title: Obsidian Bases tags: [Obsidian, Guide, Bases] date: 2026-01-08 source: raw/04_文档与参考/Markdown文档/Obsidian Bases.md

Obsidian Bases

TL

Obsidian Bases 是 Obsidian 中基于 YAML 格式定义的动态数据视图功能,支持 .base 文件和嵌入 Markdown 的写法,可以通过过滤器、公式、多种视图类型对库内笔记进行筛选、计算和展示,支持表格、卡片、列表、地图多种展示形式。

要点

  • Obsidian Bases 是基于 YAML 格式定义,用于对 Obsidian 库内笔记生成动态视图的功能,文件扩展名为 .base,也支持嵌入 Markdown 代码块。
  • 一个 Base 文件可包含:全局过滤器、全局公式、属性显示配置、自定义汇总、多个不同类型的视图。
  • 过滤器支持嵌套逻辑(与/或/非),可以对笔记属性、文件元数据进行条件筛选。
  • 属性分为三类:笔记前置元属性、文件内置属性、公式计算属性。
  • 支持公式表达式,内置大量日期、字符串、数值、列表、文件等相关函数,可实现自定义计算。
  • 支持四种视图类型:表格、卡片、列表、地图(地图需 Obsidian Maps 插件),支持分组、分页限制、列排序和属性汇总。
  • 支持嵌入到其他 Markdown 文件中,可以指定展示特定视图。

完整定义与语法

概述

Obsidian Bases 能力使 Claude Code 可以创建和编辑合法的 Obsidian Bases(.base 文件),包含视图、过滤器、公式和所有相关配置。

Obsidian Bases 是基于 YAML 的文件,用于定义 Obsidian 库中笔记的动态视图。一个 Base 文件可包含多个视图、全局过滤器、公式、属性配置和自定义汇总。

文件格式

Base 文件使用 .base 扩展名,内容为合法 YAML,也可以嵌入在 Markdown 代码块中。

完整 Schema

# Global filters apply to ALL views in the base
filters:
  # Can be a single filter string
  # OR a recursive filter object with and/or/not
  and: []
  or: []
  not: []
 
# Define formula properties that can be used across all views
formulas:
  formula_name: 'expression'
 
# Configure display names and settings for properties
properties:
  property_name:
    displayName: "Display Name"
  formula.formula_name:
    displayName: "Formula Display Name"
  file.ext:
    displayName: "Extension"
 
# Define custom summary formulas
summaries:
  custom_summary_name: 'values.mean().round(3)'
 
# Define one or more views
views:
  - type: table | cards | list | map
    name: "View Name"
    limit: 10                    # Optional: limit results
    groupBy:                     # Optional: group results
      property: property_name
      direction: ASC | DESC
    filters:                     # View-specific filters
      and: []
    order:                       # Properties to display in order
      - file.name
      - property_name
      - formula.formula_name
    summaries:                   # Map properties to summary formulas
      property_name: Average

过滤器语法

过滤器用于筛选结果,可以全局应用,也可以按视图单独应用。

过滤器结构

# Single filter
filters: 'status == "done"'
 
# AND - all conditions must be true
filters:
  and:
    - 'status == "done"'
    - 'priority > 3'
 
# OR - any condition can be true
filters:
  or:
    - 'file.hasTag("book")'
    - 'file.hasTag("article")'
 
# NOT - exclude matching items
filters:
  not:
    - 'file.hasTag("archived")'
 
# Nested filters
filters:
  or:
    - file.hasTag("tag")
    - and:
        - file.hasTag("book")
        - file.hasLink("Textbook")
    - not:
        - file.hasTag("book")
        - file.inFolder("Required Reading")

过滤器运算符

OperatorDescription
==equals
!=not equal
>greater than
<less than
>=greater than or equal
<=less than or equal
&&logical and
`
!logical not

属性

属性的三种类型

  1. 笔记属性 - 来自前置元数据:note.author 或简写 author
  2. 文件属性 - 文件元数据:file.namefile.mtime
  3. 公式属性 - 计算值:formula.my_formula

文件属性参考

PropertyTypeDescription
file.nameStringFile name
file.basenameStringFile name without extension
file.pathStringFull path to file
file.folderStringParent folder path
file.extStringFile extension
file.sizeNumberFile size in bytes
file.ctimeDateCreated time
file.mtimeDateModified time
file.tagsListAll tags in file
file.linksListInternal links in file
file.backlinksListFiles linking to this file
file.embedsListEmbeds in the note
file.propertiesObjectAll frontmatter properties

this 关键字

  • 在主内容区:指代 Base 文件本身
  • 嵌入场景:指代嵌入当前 Base 的文件
  • 在侧边栏:指代主内容区的活跃文件

公式语法

公式通过属性计算值,在 formulas 段定义:

formulas:
  # Simple arithmetic
  total: "price * quantity"
  
  # Conditional logic
  status_icon: 'if(done, "✅", "⏳")'
  
  # String formatting
  formatted_price: 'if(price, price.toFixed(2) + " dollars")'
  
  # Date formatting
  created: 'file.ctime.format("YYYY-MM-DD")'
  
  # Complex expressions
  days_old: '((now() - file.ctime) / 86400000).round(0)'

函数参考

全局函数

FunctionSignatureDescription
date()date(string): dateParse string to date. Format: YYYY-MM-DD HH:mm:ss
duration()duration(string): durationParse duration string
now()now(): dateCurrent date and time
today()today(): dateCurrent date (time = 00:00:00)
if()if(condition, trueResult, falseResult?)Conditional
min()min(n1, n2, ...): numberSmallest number
max()max(n1, n2, ...): numberLargest number
number()number(any): numberConvert to number
link()link(path, display?): LinkCreate a link
list()list(element): ListWrap in list if not already
file()file(path): fileGet file object
image()image(path): imageCreate image for rendering
icon()icon(name): iconLucide icon by name
html()html(string): htmlRender as HTML
escapeHTML()escapeHTML(string): stringEscape HTML characters

任意类型通用函数

FunctionSignatureDescription
isTruthy()any.isTruthy(): booleanCoerce to boolean
isType()any.isType(type): booleanCheck type
toString()any.toString(): stringConvert to string

日期函数与字段

可用字段: date.yeardate.monthdate.daydate.hourdate.minute