Color mode

Bases

Render Obsidian Bases definitions from fenced base code blocks. Filtering, sorting, and view composition run against the content manifest at build time, so no client-side JavaScript is required.

日本語

Overview

bases() recognises fenced blocks

md
```base
filters:
  and:
    - file.hasTag("featured")
properties:
  file.name:
    displayName: Title
  file.tags:
    displayName: Tags
views:
  - type: table
    name: Featured
    order:
      - file.name
      - file.tags
    limit: 10
```

and renders them using the content manifest (every note's frontmatter, tags, links, and permalink).

Usage

ts
import { defineConfig } from "@riebeckite/core";
import { bases } from "@riebeckite/plugin-bases";
 
export default defineConfig({
  // ...
  plugins: [bases()],
});

Block syntax

The block body is an Obsidian Base YAML document.

Field Type Description
filters expression | list | object Top-level filter applied to every view (below)
properties object Property id -> display name (or { displayName })
views object[] One or more views

Views

Field Type Description
type "table" | "cards" Output kind. Defaults to table
name string Optional label rendered above the view
filters filter Additional filter, combined with the top-level filter using AND
order string | string[] Columns (property ids) and their display order
columns string | string[] Alias for order
sort object | object[] | string Sort keys (below)
limit number Row cap for this view; still bounded by the limit option

sort accepts the Core shape { field, order }, the Obsidian shape { property, direction }, or a shorthand string ("-file.name" sorts descending). When a view omits order/columns, the columns are the keys of properties (in order), or ["file.name", "file.tags"].

Filter grammar

A filter is an expression string, a list of expressions (treated as AND), or an object with and / or / not keys. and and or take a list; not takes an expression or a list (the list is ANDed, then negated). A plain object whose keys are property names is treated as equality.

Expression Description
file.hasTag("x") Has the tag x (or a subtag x/...). Case-insensitive
file.inFolder("x") Slug equals x or starts with x/
file.hasLink("x") Links to x (by resolved slug, raw target, or file name)
file.name / file.title Note title
file.path / file.slug Slug
file.folder Parent folder of the slug
file.link / file.permalink Permalink
file.tags Tags
note.key / key A frontmatter value

Comparisons use ==, !=, >, <, >=, <=, and contains. String comparisons are case-insensitive; contains tests array membership or substring containment. Bare scalar lists are ANDed.

yaml
filters:
  and:
    - file.hasTag("featured")
    - or:
        - note.status == "published"
        - note.status == "review"
    - not:
        - file.hasTag("draft")
views:
  - type: table
    name: Featured
    order: [file.name, note.status]
    sort:
      - property: file.name
        direction: ASC
    limit: 20

Options

Option Type Default Description
className string "rb-bases" Root CSS class
language string "base" Fence language to target
limit number 100 Global row cap applied to every view
showFallback boolean true Render the raw Base definition in a <details> fallback
view string none Render only the view with this name when a Base defines several

Output HTML / CSS hooks

html
<div class="rb-bases" data-bases data-bases-view="table">
  <section class="rb-bases__view" data-bases-view="table">
    <h3 class="rb-bases__view-name">Featured</h3>
    <table class="rb-bases__table"> ... </table>
  </section>
  <details class="rb-bases__fallback"> ... </details>
</div>

Stable classes: rb-bases, rb-bases__view, rb-bases__view-name, rb-bases__table, rb-bases__heading, rb-bases__cell, rb-bases__row, rb-bases__link, rb-bases__tags, rb-bases__tag, rb-bases__cards, rb-bases__card, rb-bases__card-title, rb-bases__fields, rb-bases__field, rb-bases__field-label, rb-bases__field-value, rb-bases__empty, rb-bases__fallback, rb-bases--error. Stable attributes: data-bases, data-bases-view.

Diagnostics

A block that is not valid YAML, or that uses an unsupported filter expression or view shape, is left as a code block and reported through file.message(...) with source: "@riebeckite/plugin-bases".

Limitations

This is an MVP subset of Obsidian Bases:

  • Only the table and cards view types are rendered.
  • Inline boolean operators (&&, ||, !) are not supported; use the and / or / not YAML structure.
  • if() / filter() and other Base formula functions are not supported.
  • Nested property paths and file.mtime / file.ctime are mapped onto date.
  • Property-to-property comparisons are not supported; the right-hand side is a literal.
  • Results are fixed at build time. Rebuilding a host note when a queried note changes is future work; a full build always recomputes correctly.

Exports

  • bases(options?) — plugin factory (alias: basesPlugin)
  • remarkBases(options?) — remark transform usable on its own (options.language selects the fence language)
  • parseBases(document) — compiles a parsed YAML Base document to a spec
  • matchesCondition(condition, entry) — condition evaluator
  • Types: BasesOptions, BasesSpec, BasesView, BasesViewType, BasesCondition, BasesValueRef, BasesBuiltinValue, BasesOperator, BasesLiteral

See also

History

1 changesCollapseExpand
1 + <!-- Generated from packages/plugins/bases/README.md. Do not edit this page directly; edit the package README and run `pnpm docs:sync`. -->
2 +
3 + # Bases
4 +
5 + Render Obsidian Bases definitions from fenced `base` code blocks. Filtering,
6 + sorting, and view composition run against the content manifest at build time, so
7 + no client-side JavaScript is required.
8 +
9 + [日本語](./bases.md)
10 +
11 + ## Overview
12 +
13 + `bases()` recognises fenced blocks
14 +
15 + ````md
16 + ```base
17 + filters:
18 + and:
19 + - file.hasTag("featured")
20 + properties:
21 + file.name:
22 + displayName: Title
23 + file.tags:
24 + displayName: Tags
25 + views:
26 + - type: table
27 + name: Featured
28 + order:
29 + - file.name
30 + - file.tags
31 + limit: 10
32 + ```
33 + ````
34 +
35 + and renders them using the content manifest (every note's frontmatter, tags,
36 + links, and permalink).
37 +
38 + ## Usage
39 +
40 + ```ts
41 + import { defineConfig } from "@riebeckite/core";
42 + import { bases } from "@riebeckite/plugin-bases";
43 +
44 + export default defineConfig({
45 + // ...
46 + plugins: [bases()],
47 + });
48 + ```
49 +
50 + ## Block syntax
51 +
52 + The block body is an Obsidian Base YAML document.
53 +
54 + | Field | Type | Description |
55 + | ----- | ---- | ----------- |
56 + | `filters` | expression \| list \| object | Top-level filter applied to every view (below) |
57 + | `properties` | object | Property id -> display name (or `{ displayName }`) |
58 + | `views` | object[] | One or more views |
59 +
60 + ### Views
61 +
62 + | Field | Type | Description |
63 + | ----- | ---- | ----------- |
64 + | `type` | `"table"` \| `"cards"` | Output kind. Defaults to `table` |
65 + | `name` | string | Optional label rendered above the view |
66 + | `filters` | filter | Additional filter, combined with the top-level filter using AND |
67 + | `order` | string \| string[] | Columns (property ids) and their display order |
68 + | `columns` | string \| string[] | Alias for `order` |
69 + | `sort` | object \| object[] \| string | Sort keys (below) |
70 + | `limit` | number | Row cap for this view; still bounded by the `limit` option |
71 +
72 + `sort` accepts the Core shape `{ field, order }`, the Obsidian shape
73 + `{ property, direction }`, or a shorthand string (`"-file.name"` sorts
74 + descending). When a view omits `order`/`columns`, the columns are the keys of
75 + `properties` (in order), or `["file.name", "file.tags"]`.
76 +
77 + ### Filter grammar
78 +
79 + A filter is an expression string, a list of expressions (treated as AND), or an
80 + object with `and` / `or` / `not` keys. `and` and `or` take a list; `not` takes an
81 + expression or a list (the list is ANDed, then negated). A plain object whose keys
82 + are property names is treated as equality.
83 +
84 + | Expression | Description |
85 + | ---------- | ----------- |
86 + | `file.hasTag("x")` | Has the tag `x` (or a subtag `x/...`). Case-insensitive |
87 + | `file.inFolder("x")` | Slug equals `x` or starts with `x/` |
88 + | `file.hasLink("x")` | Links to `x` (by resolved slug, raw target, or file name) |
89 + | `file.name` / `file.title` | Note title |
90 + | `file.path` / `file.slug` | Slug |
91 + | `file.folder` | Parent folder of the slug |
92 + | `file.link` / `file.permalink` | Permalink |
93 + | `file.tags` | Tags |
94 + | `note.key` / `key` | A frontmatter value |
95 +
96 + Comparisons use `==`, `!=`, `>`, `<`, `>=`, `<=`, and `contains`. String
97 + comparisons are case-insensitive; `contains` tests array membership or substring
98 + containment. Bare scalar lists are ANDed.
99 +
100 + ```yaml
101 + filters:
102 + and:
103 + - file.hasTag("featured")
104 + - or:
105 + - note.status == "published"
106 + - note.status == "review"
107 + - not:
108 + - file.hasTag("draft")
109 + views:
110 + - type: table
111 + name: Featured
112 + order: [file.name, note.status]
113 + sort:
114 + - property: file.name
115 + direction: ASC
116 + limit: 20
117 + ```
118 +
119 + ## Options
120 +
121 + | Option | Type | Default | Description |
122 + | ------ | ---- | ------- | ----------- |
123 + | `className` | `string` | `"rb-bases"` | Root CSS class |
124 + | `language` | `string` | `"base"` | Fence language to target |
125 + | `limit` | `number` | `100` | Global row cap applied to every view |
126 + | `showFallback` | `boolean` | `true` | Render the raw Base definition in a `<details>` fallback |
127 + | `view` | `string` | none | Render only the view with this name when a Base defines several |
128 +
129 + ## Output HTML / CSS hooks
130 +
131 + ```html
132 + <div class="rb-bases" data-bases data-bases-view="table">
133 + <section class="rb-bases__view" data-bases-view="table">
134 + <h3 class="rb-bases__view-name">Featured</h3>
135 + <table class="rb-bases__table"> ... </table>
136 + </section>
137 + <details class="rb-bases__fallback"> ... </details>
138 + </div>
139 + ```
140 +
141 + Stable classes: `rb-bases`, `rb-bases__view`, `rb-bases__view-name`,
142 + `rb-bases__table`, `rb-bases__heading`, `rb-bases__cell`, `rb-bases__row`,
143 + `rb-bases__link`, `rb-bases__tags`, `rb-bases__tag`, `rb-bases__cards`,
144 + `rb-bases__card`, `rb-bases__card-title`, `rb-bases__fields`, `rb-bases__field`,
145 + `rb-bases__field-label`, `rb-bases__field-value`, `rb-bases__empty`,
146 + `rb-bases__fallback`, `rb-bases--error`. Stable attributes: `data-bases`,
147 + `data-bases-view`.
148 +
149 + ## Diagnostics
150 +
151 + A block that is not valid YAML, or that uses an unsupported filter expression or
152 + view shape, is left as a code block and reported through `file.message(...)` with
153 + `source: "@riebeckite/plugin-bases"`.
154 +
155 + ## Limitations
156 +
157 + This is an MVP subset of Obsidian Bases:
158 +
159 + - Only the `table` and `cards` view types are rendered.
160 + - Inline boolean operators (`&&`, `||`, `!`) are not supported; use the
161 + `and` / `or` / `not` YAML structure.
162 + - `if()` / `filter()` and other Base formula functions are not supported.
163 + - Nested property paths and `file.mtime` / `file.ctime` are mapped onto `date`.
164 + - Property-to-property comparisons are not supported; the right-hand side is a
165 + literal.
166 + - Results are fixed at build time. Rebuilding a host note when a queried note
167 + changes is future work; a full build always recomputes correctly.
168 +
169 + ## Exports
170 +
171 + - `bases(options?)` — plugin factory (alias: `basesPlugin`)
172 + - `remarkBases(options?)` — remark transform usable on its own (`options.language`
173 + selects the fence language)
174 + - `parseBases(document)` — compiles a parsed YAML Base document to a spec
175 + - `matchesCondition(condition, entry)` — condition evaluator
176 + - Types: `BasesOptions`, `BasesSpec`, `BasesView`, `BasesViewType`,
177 + `BasesCondition`, `BasesValueRef`, `BasesBuiltinValue`, `BasesOperator`,
178 + `BasesLiteral`
179 +
180 + ## See also
181 +
182 + - [Plugin guide](../reference/plugin-api.en.md)
183 +