@riebeckite/plugin-dataview 0.0.11 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +227 -227
  2. package/README_ja.md +191 -191
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,227 +1,227 @@
1
- # @riebeckite/plugin-dataview
2
-
3
- Evaluate declarative `dataview` code blocks against the content manifest at
4
- build time and render them as lists, tables, task lists, or calendars. No
5
- client-side JavaScript is required.
6
-
7
- [日本語](./README_ja.md)
8
-
9
- ## Overview
10
-
11
- `dataviewPlugin()` recognises fenced blocks whose language is `dataview`:
12
-
13
- ````md
14
- ```dataview
15
- TABLE file.name AS "Name", status
16
- FROM #project
17
- WHERE status = "active"
18
- SORT file.name asc
19
- LIMIT 10
20
- ```
21
- ````
22
-
23
- and renders them from the manifest (every note's frontmatter, tags, links, and
24
- permalink). DataviewJS (`dataviewjs`) is **not** supported: those blocks stay
25
- code blocks and produce a diagnostic.
26
-
27
- ## Usage
28
-
29
- ```ts
30
- import { defineConfig } from "@riebeckite/core";
31
- import { dataviewPlugin } from "@riebeckite/plugin-dataview";
32
-
33
- export default defineConfig({
34
- // ...
35
- plugins: [dataviewPlugin()],
36
- });
37
- ```
38
-
39
- ## Query syntax
40
-
41
- A block starts with a query type (`LIST`, `TABLE`, `TASK`, or `CALENDAR`)
42
- followed by optional clauses:
43
-
44
- ```
45
- LIST|TABLE|TASK|CALENDAR [expression or columns]
46
- FROM <source expression>
47
- WHERE <boolean expression>
48
- SORT <field> [asc|desc][, ...]
49
- GROUP BY <field>
50
- LIMIT <n>
51
- ```
52
-
53
- Clauses are case-insensitive. Each clause starts on its own line, but a clause
54
- body may span multiple lines.
55
-
56
- ### `LIST`
57
-
58
- `LIST` renders an unordered list of matching notes. An optional trailing
59
- expression is shown as metadata next to the link:
60
-
61
- ```dataview
62
- LIST file.date
63
- FROM #diary
64
- SORT file.date desc
65
- ```
66
-
67
- ### `TABLE`
68
-
69
- `TABLE` renders a table. When no columns are given, a single `file.link` column
70
- is used. Columns are field paths, optionally renamed with `AS`:
71
-
72
- ```dataview
73
- TABLE file.name AS "Name", status, priority
74
- FROM #project
75
- ```
76
-
77
- ### `TASK`
78
-
79
- `TASK` extracts the task list items (`- [ ]` / `- [x]`) from every matching
80
- note and renders them as `<ul class="rb-dataview__tasks">`. `FROM` and `WHERE`
81
- select the **pages**, not individual tasks:
82
-
83
- ```dataview
84
- TASK
85
- FROM #project
86
- ```
87
-
88
- ### `CALENDAR`
89
-
90
- `CALENDAR` renders a month grid. The optional trailing expression selects the
91
- date field (default `date`). The month of the most recent matched date is shown:
92
-
93
- ```dataview
94
- CALENDAR date
95
- FROM #project
96
- ```
97
-
98
- ## Clauses
99
-
100
- ### `FROM`
101
-
102
- `FROM` selects candidate notes. Sources are:
103
-
104
- | Source | Meaning |
105
- | ------ | ------- |
106
- | `#tag` | Has the tag |
107
- | `"folder"` | Slug is the folder or lives under it |
108
- | `[[note]]` | Links to `note` (incoming links) |
109
-
110
- Combine sources with `and` / `or`, negate with `!` or `-`, and group with
111
- parentheses. Adjacent sources are treated as `and`.
112
-
113
- ```dataview
114
- FROM (#project or #area) and "notes" and !#archive
115
- ```
116
-
117
- ### `WHERE`
118
-
119
- `WHERE` filters notes with a boolean expression over `file.*` and frontmatter
120
- fields.
121
-
122
- | Feature | Examples |
123
- | ------- | -------- |
124
- | Comparison | `status = "active"`, `priority > 2`, `date <= "2026-12-31"` |
125
- | Boolean | `status = "active" and !draft`, `a or b` |
126
- | `contains()` | `contains(file.tags, "#project")`, `contains(tags, "project")` |
127
- | `date()` | `date(due) >= date("2026-01-01")` |
128
- | `number()` / `string()` | `number(weight) > 3` |
129
-
130
- String `=`/`!=` comparisons and `contains()` are case-insensitive. `date()`
131
- returns a millisecond timestamp (or `null`), so `date(a) < date(b)` compares
132
- chronologically. `null`/missing values never satisfy `<`/`>` comparisons.
133
-
134
- `file.*` fields: `file.name`, `file.title`, `file.slug`, `file.path`,
135
- `file.folder`, `file.link`, `file.permalink`, `file.url`, `file.tags`,
136
- `file.date`, `file.created`, `file.updated`, `file.published`. Other frontmatter
137
- keys are read directly by name (`status`, `priority`, `due`, ...).
138
-
139
- ### `SORT`
140
-
141
- `SORT` accepts a comma-separated list of fields with an optional direction
142
- (`asc`, the default, or `desc`). Notes with a missing field sort last.
143
-
144
- ```dataview
145
- SORT priority desc, file.name asc
146
- ```
147
-
148
- ### `GROUP BY`
149
-
150
- `GROUP BY <field>` groups the matched notes. Each group is headed by the group
151
- value; `LIST` and `TASK` render one list per group, and `TABLE` inserts a group
152
- row. Groups keep the order established by `SORT`.
153
-
154
- ### `LIMIT`
155
-
156
- `LIMIT <n>` caps the number of rendered notes (before grouping). It can also be
157
- set for every block with the `limit` option.
158
-
159
- ## Options
160
-
161
- | Option | Type | Default | Description |
162
- | ------ | ---- | ------- | ----------- |
163
- | `className` | `string` | `"rb-dataview"` | Root CSS class |
164
- | `language` | `string` | `"dataview"` | Fence language to target |
165
- | `hideFallback` | `boolean` | `false` | Hide the raw-query `<details>` fallback |
166
- | `limit` | `number` | none | Default `LIMIT` when a block omits one |
167
-
168
- ## Rendering
169
-
170
- Each block becomes:
171
-
172
- ```html
173
- <div class="rb-dataview" data-dataview data-dataview-type="list">
174
- <!-- list, table, task, or calendar output -->
175
- <details class="rb-dataview__fallback">
176
- <summary>Dataview query</summary>
177
- <pre><code>LIST FROM #project</code></pre>
178
- </details>
179
- </div>
180
- ```
181
-
182
- The readable `<details>` fallback contains the raw query and can be disabled
183
- with `hideFallback`.
184
-
185
- ## Diagnostics
186
-
187
- - `dataviewjs` blocks are left untouched and emit a
188
- `dataview-unsupported-language` **warning**. The markdown-time remark
189
- transform also records a `file.message` with
190
- `source: "@riebeckite/plugin-dataview"`.
191
- - Blocks the parser or evaluator cannot handle render an inline error box and
192
- emit a `dataview-invalid` **error** diagnostic. Unsupported syntax is also
193
- reported through `file.message` while the markdown is parsed.
194
-
195
- ## Limitations
196
-
197
- - **No DataviewJS.** `dataviewjs` is intentionally unsupported.
198
- - **No inline fields** (`field:: value`). Only frontmatter is read.
199
- - **`TABLE` columns are field paths**, not arbitrary expressions. Rename with
200
- `AS "Label"`; computed columns (for example `file.size / 1024`) are not
201
- supported.
202
- - **`TASK` filters pages, not tasks.** `WHERE`/`FROM` apply to the notes that
203
- contain tasks.
204
- - **`CALENDAR` shows one month** — the month of the most recent matched date.
205
- - `file.size`, `file.mtime`, and `file.ctime` are not available from the
206
- manifest and evaluate to `undefined`.
207
- - Results are fixed at build time and links produced by a dataview block are not
208
- added to the content graph (backlinks). A full build always recomputes
209
- correctly.
210
-
211
- ## Exports
212
-
213
- - `dataviewPlugin(options?)` / `dataview(options?)` — plugin factory
214
- - `remarkDataview(options?)` — remark transform usable on its own
215
- - `parseDataview(source)` — parse a block body into a `DataviewSpec`
216
- - `selectDataviewEntries(spec, manifest, defaultLimit)` — matching engine
217
- - `evaluateDataviewExpression(expression, scope)` and
218
- `matchesDataviewFrom(from, entry, manifest)` — expression helpers
219
- - `renderDataview(selection, spec, options, source)` — HTML renderer
220
- - `resolveDataviewOptions(options?)` — normalise plugin options
221
- - `DATAVIEW_ATTRIBUTE` — placeholder attribute name
222
- - Types: `DataviewOptions`, `DataviewSpec`, `DataviewQueryType`,
223
- `DataviewExpression`, `DataviewFrom`, and friends
224
-
225
- ## See also
226
-
227
- - [Plugin guide](../../../docs/en/plugin-system.md)
1
+ # @riebeckite/plugin-dataview
2
+
3
+ Evaluate declarative `dataview` code blocks against the content manifest at
4
+ build time and render them as lists, tables, task lists, or calendars. No
5
+ client-side JavaScript is required.
6
+
7
+ [日本語](./README_ja.md)
8
+
9
+ ## Overview
10
+
11
+ `dataviewPlugin()` recognises fenced blocks whose language is `dataview`:
12
+
13
+ ````md
14
+ ```dataview
15
+ TABLE file.name AS "Name", status
16
+ FROM #project
17
+ WHERE status = "active"
18
+ SORT file.name asc
19
+ LIMIT 10
20
+ ```
21
+ ````
22
+
23
+ and renders them from the manifest (every note's frontmatter, tags, links, and
24
+ permalink). DataviewJS (`dataviewjs`) is **not** supported: those blocks stay
25
+ code blocks and produce a diagnostic.
26
+
27
+ ## Usage
28
+
29
+ ```ts
30
+ import { defineConfig } from "@riebeckite/core";
31
+ import { dataviewPlugin } from "@riebeckite/plugin-dataview";
32
+
33
+ export default defineConfig({
34
+ // ...
35
+ plugins: [dataviewPlugin()],
36
+ });
37
+ ```
38
+
39
+ ## Query syntax
40
+
41
+ A block starts with a query type (`LIST`, `TABLE`, `TASK`, or `CALENDAR`)
42
+ followed by optional clauses:
43
+
44
+ ```
45
+ LIST|TABLE|TASK|CALENDAR [expression or columns]
46
+ FROM <source expression>
47
+ WHERE <boolean expression>
48
+ SORT <field> [asc|desc][, ...]
49
+ GROUP BY <field>
50
+ LIMIT <n>
51
+ ```
52
+
53
+ Clauses are case-insensitive. Each clause starts on its own line, but a clause
54
+ body may span multiple lines.
55
+
56
+ ### `LIST`
57
+
58
+ `LIST` renders an unordered list of matching notes. An optional trailing
59
+ expression is shown as metadata next to the link:
60
+
61
+ ```dataview
62
+ LIST file.date
63
+ FROM #diary
64
+ SORT file.date desc
65
+ ```
66
+
67
+ ### `TABLE`
68
+
69
+ `TABLE` renders a table. When no columns are given, a single `file.link` column
70
+ is used. Columns are field paths, optionally renamed with `AS`:
71
+
72
+ ```dataview
73
+ TABLE file.name AS "Name", status, priority
74
+ FROM #project
75
+ ```
76
+
77
+ ### `TASK`
78
+
79
+ `TASK` extracts the task list items (`- [ ]` / `- [x]`) from every matching
80
+ note and renders them as `<ul class="rb-dataview__tasks">`. `FROM` and `WHERE`
81
+ select the **pages**, not individual tasks:
82
+
83
+ ```dataview
84
+ TASK
85
+ FROM #project
86
+ ```
87
+
88
+ ### `CALENDAR`
89
+
90
+ `CALENDAR` renders a month grid. The optional trailing expression selects the
91
+ date field (default `date`). The month of the most recent matched date is shown:
92
+
93
+ ```dataview
94
+ CALENDAR date
95
+ FROM #project
96
+ ```
97
+
98
+ ## Clauses
99
+
100
+ ### `FROM`
101
+
102
+ `FROM` selects candidate notes. Sources are:
103
+
104
+ | Source | Meaning |
105
+ | ------ | ------- |
106
+ | `#tag` | Has the tag |
107
+ | `"folder"` | Slug is the folder or lives under it |
108
+ | `[[note]]` | Links to `note` (incoming links) |
109
+
110
+ Combine sources with `and` / `or`, negate with `!` or `-`, and group with
111
+ parentheses. Adjacent sources are treated as `and`.
112
+
113
+ ```dataview
114
+ FROM (#project or #area) and "notes" and !#archive
115
+ ```
116
+
117
+ ### `WHERE`
118
+
119
+ `WHERE` filters notes with a boolean expression over `file.*` and frontmatter
120
+ fields.
121
+
122
+ | Feature | Examples |
123
+ | ------- | -------- |
124
+ | Comparison | `status = "active"`, `priority > 2`, `date <= "2026-12-31"` |
125
+ | Boolean | `status = "active" and !draft`, `a or b` |
126
+ | `contains()` | `contains(file.tags, "#project")`, `contains(tags, "project")` |
127
+ | `date()` | `date(due) >= date("2026-01-01")` |
128
+ | `number()` / `string()` | `number(weight) > 3` |
129
+
130
+ String `=`/`!=` comparisons and `contains()` are case-insensitive. `date()`
131
+ returns a millisecond timestamp (or `null`), so `date(a) < date(b)` compares
132
+ chronologically. `null`/missing values never satisfy `<`/`>` comparisons.
133
+
134
+ `file.*` fields: `file.name`, `file.title`, `file.slug`, `file.path`,
135
+ `file.folder`, `file.link`, `file.permalink`, `file.url`, `file.tags`,
136
+ `file.date`, `file.created`, `file.updated`, `file.published`. Other frontmatter
137
+ keys are read directly by name (`status`, `priority`, `due`, ...).
138
+
139
+ ### `SORT`
140
+
141
+ `SORT` accepts a comma-separated list of fields with an optional direction
142
+ (`asc`, the default, or `desc`). Notes with a missing field sort last.
143
+
144
+ ```dataview
145
+ SORT priority desc, file.name asc
146
+ ```
147
+
148
+ ### `GROUP BY`
149
+
150
+ `GROUP BY <field>` groups the matched notes. Each group is headed by the group
151
+ value; `LIST` and `TASK` render one list per group, and `TABLE` inserts a group
152
+ row. Groups keep the order established by `SORT`.
153
+
154
+ ### `LIMIT`
155
+
156
+ `LIMIT <n>` caps the number of rendered notes (before grouping). It can also be
157
+ set for every block with the `limit` option.
158
+
159
+ ## Options
160
+
161
+ | Option | Type | Default | Description |
162
+ | ------ | ---- | ------- | ----------- |
163
+ | `className` | `string` | `"rb-dataview"` | Root CSS class |
164
+ | `language` | `string` | `"dataview"` | Fence language to target |
165
+ | `hideFallback` | `boolean` | `false` | Hide the raw-query `<details>` fallback |
166
+ | `limit` | `number` | none | Default `LIMIT` when a block omits one |
167
+
168
+ ## Rendering
169
+
170
+ Each block becomes:
171
+
172
+ ```html
173
+ <div class="rb-dataview" data-dataview data-dataview-type="list">
174
+ <!-- list, table, task, or calendar output -->
175
+ <details class="rb-dataview__fallback">
176
+ <summary>Dataview query</summary>
177
+ <pre><code>LIST FROM #project</code></pre>
178
+ </details>
179
+ </div>
180
+ ```
181
+
182
+ The readable `<details>` fallback contains the raw query and can be disabled
183
+ with `hideFallback`.
184
+
185
+ ## Diagnostics
186
+
187
+ - `dataviewjs` blocks are left untouched and emit a
188
+ `dataview-unsupported-language` **warning**. The markdown-time remark
189
+ transform also records a `file.message` with
190
+ `source: "@riebeckite/plugin-dataview"`.
191
+ - Blocks the parser or evaluator cannot handle render an inline error box and
192
+ emit a `dataview-invalid` **error** diagnostic. Unsupported syntax is also
193
+ reported through `file.message` while the markdown is parsed.
194
+
195
+ ## Limitations
196
+
197
+ - **No DataviewJS.** `dataviewjs` is intentionally unsupported.
198
+ - **No inline fields** (`field:: value`). Only frontmatter is read.
199
+ - **`TABLE` columns are field paths**, not arbitrary expressions. Rename with
200
+ `AS "Label"`; computed columns (for example `file.size / 1024`) are not
201
+ supported.
202
+ - **`TASK` filters pages, not tasks.** `WHERE`/`FROM` apply to the notes that
203
+ contain tasks.
204
+ - **`CALENDAR` shows one month** — the month of the most recent matched date.
205
+ - `file.size`, `file.mtime`, and `file.ctime` are not available from the
206
+ manifest and evaluate to `undefined`.
207
+ - Results are fixed at build time and links produced by a dataview block are not
208
+ added to the content graph (backlinks). A full build always recomputes
209
+ correctly.
210
+
211
+ ## Exports
212
+
213
+ - `dataviewPlugin(options?)` / `dataview(options?)` — plugin factory
214
+ - `remarkDataview(options?)` — remark transform usable on its own
215
+ - `parseDataview(source)` — parse a block body into a `DataviewSpec`
216
+ - `selectDataviewEntries(spec, manifest, defaultLimit)` — matching engine
217
+ - `evaluateDataviewExpression(expression, scope)` and
218
+ `matchesDataviewFrom(from, entry, manifest)` — expression helpers
219
+ - `renderDataview(selection, spec, options, source)` — HTML renderer
220
+ - `resolveDataviewOptions(options?)` — normalise plugin options
221
+ - `DATAVIEW_ATTRIBUTE` — placeholder attribute name
222
+ - Types: `DataviewOptions`, `DataviewSpec`, `DataviewQueryType`,
223
+ `DataviewExpression`, `DataviewFrom`, and friends
224
+
225
+ ## See also
226
+
227
+ - [Plugin guide](../../../docs/en/reference/plugin-api.md)
package/README_ja.md CHANGED
@@ -1,191 +1,191 @@
1
- # @riebeckite/plugin-dataview
2
-
3
- 宣言的な `dataview` コードブロックをビルド時にコンテンツマニフェストへ照合し、リスト・表・タスク一覧・カレンダーとして描画するプラグインです。クライアント側の JavaScript は不要です。
4
-
5
- [English](./README.md)
6
-
7
- ## できること
8
-
9
- `dataviewPlugin()` は、フェンス言語が `dataview` のコードブロックを検出します。
10
-
11
- ````md
12
- ```dataview
13
- TABLE file.name AS "Name", status
14
- FROM #project
15
- WHERE status = "active"
16
- SORT file.name asc
17
- LIMIT 10
18
- ```
19
- ````
20
-
21
- ブロックはマニフェスト(全ノートのフロントマター・タグ・リンク・パーマリンク)を使って描画されます。DataviewJS(`dataviewjs`)には対応しません。そのブロックはコードブロックのまま残り、診断を1件出します。
22
-
23
- ## 設定
24
-
25
- ```ts
26
- import { defineConfig } from "@riebeckite/core";
27
- import { dataviewPlugin } from "@riebeckite/plugin-dataview";
28
-
29
- export default defineConfig({
30
- // ...
31
- plugins: [dataviewPlugin()],
32
- });
33
- ```
34
-
35
- ## クエリの書き方
36
-
37
- ブロックはクエリ種別(`LIST`、`TABLE`、`TASK`、`CALENDAR`)で始まり、そのあとに任意の節が続きます。
38
-
39
- ```
40
- LIST|TABLE|TASK|CALENDAR [式または列]
41
- FROM <ソース式>
42
- WHERE <真偽式>
43
- SORT <フィールド> [asc|desc][, ...]
44
- GROUP BY <フィールド>
45
- LIMIT <n>
46
- ```
47
-
48
- 節のキーワードは大文字小文字を区別しません。節はそれぞれ行頭から始めますが、節の内容は複数行にまたがってもかまいません。
49
-
50
- ### `LIST`
51
-
52
- `LIST` は一致したノートを箇条書きにします。末尾に式を書くと、リンクの横にメタ情報として表示します。
53
-
54
- ```dataview
55
- LIST file.date
56
- FROM #diary
57
- SORT file.date desc
58
- ```
59
-
60
- ### `TABLE`
61
-
62
- `TABLE` は表を描画します。列を省略すると `file.link` の1列だけになります。列はフィールドパスで、`AS` で見出しを付けられます。
63
-
64
- ```dataview
65
- TABLE file.name AS "Name", status, priority
66
- FROM #project
67
- ```
68
-
69
- ### `TASK`
70
-
71
- `TASK` は一致した各ノートからタスク項目(`- [ ]` / `- [x]`)を取り出し、`<ul class="rb-dataview__tasks">` として描画します。`FROM` と `WHERE` が選ぶのは**ノート**であり、個々のタスクではありません。
72
-
73
- ```dataview
74
- TASK
75
- FROM #project
76
- ```
77
-
78
- ### `CALENDAR`
79
-
80
- `CALENDAR` は月のグリッドを描画します。末尾の式で日付フィールドを指定できます(既定は `date`)。一致した日付のうち最も新しい月を表示します。
81
-
82
- ```dataview
83
- CALENDAR date
84
- FROM #project
85
- ```
86
-
87
- ## 節
88
-
89
- ### `FROM`
90
-
91
- `FROM` は候補となるノートを絞り込みます。使えるソースは次の3つです。
92
-
93
- | ソース | 意味 |
94
- | --- | --- |
95
- | `#tag` | そのタグを持つ |
96
- | `"folder"` | スラッグがそのフォルダ、またはその配下 |
97
- | `[[note]]` | `note` へリンクしている(被リンク) |
98
-
99
- ソースは `and` / `or` でつなぎ、`!` または `-` で否定し、`(` `)` でまとめられます。ソースを続けて書いた場合は `and` とみなします。
100
-
101
- ```dataview
102
- FROM (#project or #area) and "notes" and !#archive
103
- ```
104
-
105
- ### `WHERE`
106
-
107
- `WHERE` は `file.*` とフロントマターのフィールドに対する真偽式でノートを絞り込みます。
108
-
109
- | 機能 | 例 |
110
- | --- | --- |
111
- | 比較 | `status = "active"`、`priority > 2`、`date <= "2026-12-31"` |
112
- | 論理 | `status = "active" and !draft`、`a or b` |
113
- | `contains()` | `contains(file.tags, "#project")`、`contains(tags, "project")` |
114
- | `date()` | `date(due) >= date("2026-01-01")` |
115
- | `number()` / `string()` | `number(weight) > 3` |
116
-
117
- 文字列の `=` / `!=` と `contains()` は大文字小文字を区別しません。`date()` はミリ秒のタイムスタンプ(または `null`)を返すので、`date(a) < date(b)` は時系列で比較できます。`null` や未定義の値は `<` / `>` を満たしません。
118
-
119
- `file.*` で使えるフィールドは `file.name`、`file.title`、`file.slug`、`file.path`、`file.folder`、`file.link`、`file.permalink`、`file.url`、`file.tags`、`file.date`、`file.created`、`file.updated`、`file.published` です。それ以外はフロントマターのキーをそのまま名前で参照します(`status`、`priority`、`due` など)。
120
-
121
- ### `SORT`
122
-
123
- `SORT` はフィールドをカンマ区切りで並べ、各フィールドに `asc`(既定)または `desc` を付けられます。値が無いノートは末尾に並びます。
124
-
125
- ```dataview
126
- SORT priority desc, file.name asc
127
- ```
128
-
129
- ### `GROUP BY`
130
-
131
- `GROUP BY <フィールド>` は一致したノートをグループ化します。グループ値が見出しになり、`LIST` と `TASK` はグループごとにリストを、`TABLE` はグループ行を描画します。グループの順序は `SORT` の結果を保ちます。
132
-
133
- ### `LIMIT`
134
-
135
- `LIMIT <n>` は描画するノート数を上限で打ち切ります(グループ化の前)。オプション `limit` を使えば全ブロックに既定の上限を設定できます。
136
-
137
- ## オプション
138
-
139
- | オプション | 型 | 既定値 | 内容 |
140
- | --- | --- | --- | --- |
141
- | `className` | `string` | `"rb-dataview"` | ルート要素の CSS クラス |
142
- | `language` | `string` | `"dataview"` | 対象のフェンス言語 |
143
- | `hideFallback` | `boolean` | `false` | 生クエリの `<details>` フォールバックを隠す |
144
- | `limit` | `number` | なし | ブロックが `LIMIT` を省略したときの上限 |
145
-
146
- ## 描画結果
147
-
148
- 各ブロックは次のような HTML になります。
149
-
150
- ```html
151
- <div class="rb-dataview" data-dataview data-dataview-type="list">
152
- <!-- リスト・表・タスク・カレンダーのいずれか -->
153
- <details class="rb-dataview__fallback">
154
- <summary>Dataview query</summary>
155
- <pre><code>LIST FROM #project</code></pre>
156
- </details>
157
- </div>
158
- ```
159
-
160
- `<details>` のフォールバックには元のクエリが入ります。`hideFallback` で非表示にできます。
161
-
162
- ## 診断
163
-
164
- - `dataviewjs` のブロックはそのまま残し、`dataview-unsupported-language` の**警告**を出します。Markdown 解析時の remark 変換でも `source: "@riebeckite/plugin-dataview"` を付けた `file.message` を記録します。
165
- - パーサーや評価器が扱えないブロックは、その場にエラー表示を出しつつ `dataview-invalid` の**エラー**診断を生成します。対応していない構文は、Markdown 解析時にも `file.message` で報告されます。
166
-
167
- ## 制限事項
168
-
169
- - **DataviewJS には対応しません。** `dataviewjs` は意図的に対象外です。
170
- - **インラインフィールド(`field:: value`)には対応しません。** 参照するのはフロントマターだけです。
171
- - **`TABLE` の列はフィールドパスです。** 任意の式は書けません。見出しの変更は `AS "Label"` だけです(`file.size / 1024` のような計算列は不可)。
172
- - **`TASK` が絞り込むのはノートです。** `FROM` / `WHERE` はタスクを含むノートに働きます。
173
- - **`CALENDAR` が表示するのは1か月分**です。一致した日付のうち最も新しい月を描画します。
174
- - `file.size`、`file.mtime`、`file.ctime` はマニフェストから取得できず `undefined` になります。
175
- - 結果はビルド時に確定します。dataview ブロックが生成したリンクはコンテンツグラフ(バックリンク)には含まれません。フルビルドでは常に正しく再計算されます。
176
-
177
- ## エクスポート
178
-
179
- - `dataviewPlugin(options?)` / `dataview(options?)` — プラグインファクトリ
180
- - `remarkDataview(options?)` — Remark 変換だけを利用する場合の API
181
- - `parseDataview(source)` — ブロック本文を `DataviewSpec` に変換
182
- - `selectDataviewEntries(spec, manifest, defaultLimit)` — 照合エンジン
183
- - `evaluateDataviewExpression(expression, scope)` と `matchesDataviewFrom(from, entry, manifest)` — 式のヘルパー
184
- - `renderDataview(selection, spec, options, source)` — HTML レンダラー
185
- - `resolveDataviewOptions(options?)` — オプションの正規化
186
- - `DATAVIEW_ATTRIBUTE` — プレースホルダーの属性名
187
- - 型: `DataviewOptions`、`DataviewSpec`、`DataviewQueryType`、`DataviewExpression`、`DataviewFrom` ほか
188
-
189
- ## 関連資料
190
-
191
- - [プラグインシステム](../../../docs/ja/plugin-system.md)
1
+ # @riebeckite/plugin-dataview
2
+
3
+ 宣言的な `dataview` コードブロックをビルド時にコンテンツマニフェストへ照合し、リスト・表・タスク一覧・カレンダーとして描画するプラグインです。クライアント側の JavaScript は不要です。
4
+
5
+ [English](./README.md)
6
+
7
+ ## できること
8
+
9
+ `dataviewPlugin()` は、フェンス言語が `dataview` のコードブロックを検出します。
10
+
11
+ ````md
12
+ ```dataview
13
+ TABLE file.name AS "Name", status
14
+ FROM #project
15
+ WHERE status = "active"
16
+ SORT file.name asc
17
+ LIMIT 10
18
+ ```
19
+ ````
20
+
21
+ ブロックはマニフェスト(全ノートのフロントマター・タグ・リンク・パーマリンク)を使って描画されます。DataviewJS(`dataviewjs`)には対応しません。そのブロックはコードブロックのまま残り、診断を1件出します。
22
+
23
+ ## 設定
24
+
25
+ ```ts
26
+ import { defineConfig } from "@riebeckite/core";
27
+ import { dataviewPlugin } from "@riebeckite/plugin-dataview";
28
+
29
+ export default defineConfig({
30
+ // ...
31
+ plugins: [dataviewPlugin()],
32
+ });
33
+ ```
34
+
35
+ ## クエリの書き方
36
+
37
+ ブロックはクエリ種別(`LIST`、`TABLE`、`TASK`、`CALENDAR`)で始まり、そのあとに任意の節が続きます。
38
+
39
+ ```
40
+ LIST|TABLE|TASK|CALENDAR [式または列]
41
+ FROM <ソース式>
42
+ WHERE <真偽式>
43
+ SORT <フィールド> [asc|desc][, ...]
44
+ GROUP BY <フィールド>
45
+ LIMIT <n>
46
+ ```
47
+
48
+ 節のキーワードは大文字小文字を区別しません。節はそれぞれ行頭から始めますが、節の内容は複数行にまたがってもかまいません。
49
+
50
+ ### `LIST`
51
+
52
+ `LIST` は一致したノートを箇条書きにします。末尾に式を書くと、リンクの横にメタ情報として表示します。
53
+
54
+ ```dataview
55
+ LIST file.date
56
+ FROM #diary
57
+ SORT file.date desc
58
+ ```
59
+
60
+ ### `TABLE`
61
+
62
+ `TABLE` は表を描画します。列を省略すると `file.link` の1列だけになります。列はフィールドパスで、`AS` で見出しを付けられます。
63
+
64
+ ```dataview
65
+ TABLE file.name AS "Name", status, priority
66
+ FROM #project
67
+ ```
68
+
69
+ ### `TASK`
70
+
71
+ `TASK` は一致した各ノートからタスク項目(`- [ ]` / `- [x]`)を取り出し、`<ul class="rb-dataview__tasks">` として描画します。`FROM` と `WHERE` が選ぶのは**ノート**であり、個々のタスクではありません。
72
+
73
+ ```dataview
74
+ TASK
75
+ FROM #project
76
+ ```
77
+
78
+ ### `CALENDAR`
79
+
80
+ `CALENDAR` は月のグリッドを描画します。末尾の式で日付フィールドを指定できます(既定は `date`)。一致した日付のうち最も新しい月を表示します。
81
+
82
+ ```dataview
83
+ CALENDAR date
84
+ FROM #project
85
+ ```
86
+
87
+ ## 節
88
+
89
+ ### `FROM`
90
+
91
+ `FROM` は候補となるノートを絞り込みます。使えるソースは次の3つです。
92
+
93
+ | ソース | 意味 |
94
+ | --- | --- |
95
+ | `#tag` | そのタグを持つ |
96
+ | `"folder"` | スラッグがそのフォルダ、またはその配下 |
97
+ | `[[note]]` | `note` へリンクしている(被リンク) |
98
+
99
+ ソースは `and` / `or` でつなぎ、`!` または `-` で否定し、`(` `)` でまとめられます。ソースを続けて書いた場合は `and` とみなします。
100
+
101
+ ```dataview
102
+ FROM (#project or #area) and "notes" and !#archive
103
+ ```
104
+
105
+ ### `WHERE`
106
+
107
+ `WHERE` は `file.*` とフロントマターのフィールドに対する真偽式でノートを絞り込みます。
108
+
109
+ | 機能 | 例 |
110
+ | --- | --- |
111
+ | 比較 | `status = "active"`、`priority > 2`、`date <= "2026-12-31"` |
112
+ | 論理 | `status = "active" and !draft`、`a or b` |
113
+ | `contains()` | `contains(file.tags, "#project")`、`contains(tags, "project")` |
114
+ | `date()` | `date(due) >= date("2026-01-01")` |
115
+ | `number()` / `string()` | `number(weight) > 3` |
116
+
117
+ 文字列の `=` / `!=` と `contains()` は大文字小文字を区別しません。`date()` はミリ秒のタイムスタンプ(または `null`)を返すので、`date(a) < date(b)` は時系列で比較できます。`null` や未定義の値は `<` / `>` を満たしません。
118
+
119
+ `file.*` で使えるフィールドは `file.name`、`file.title`、`file.slug`、`file.path`、`file.folder`、`file.link`、`file.permalink`、`file.url`、`file.tags`、`file.date`、`file.created`、`file.updated`、`file.published` です。それ以外はフロントマターのキーをそのまま名前で参照します(`status`、`priority`、`due` など)。
120
+
121
+ ### `SORT`
122
+
123
+ `SORT` はフィールドをカンマ区切りで並べ、各フィールドに `asc`(既定)または `desc` を付けられます。値が無いノートは末尾に並びます。
124
+
125
+ ```dataview
126
+ SORT priority desc, file.name asc
127
+ ```
128
+
129
+ ### `GROUP BY`
130
+
131
+ `GROUP BY <フィールド>` は一致したノートをグループ化します。グループ値が見出しになり、`LIST` と `TASK` はグループごとにリストを、`TABLE` はグループ行を描画します。グループの順序は `SORT` の結果を保ちます。
132
+
133
+ ### `LIMIT`
134
+
135
+ `LIMIT <n>` は描画するノート数を上限で打ち切ります(グループ化の前)。オプション `limit` を使えば全ブロックに既定の上限を設定できます。
136
+
137
+ ## オプション
138
+
139
+ | オプション | 型 | 既定値 | 内容 |
140
+ | --- | --- | --- | --- |
141
+ | `className` | `string` | `"rb-dataview"` | ルート要素の CSS クラス |
142
+ | `language` | `string` | `"dataview"` | 対象のフェンス言語 |
143
+ | `hideFallback` | `boolean` | `false` | 生クエリの `<details>` フォールバックを隠す |
144
+ | `limit` | `number` | なし | ブロックが `LIMIT` を省略したときの上限 |
145
+
146
+ ## 描画結果
147
+
148
+ 各ブロックは次のような HTML になります。
149
+
150
+ ```html
151
+ <div class="rb-dataview" data-dataview data-dataview-type="list">
152
+ <!-- リスト・表・タスク・カレンダーのいずれか -->
153
+ <details class="rb-dataview__fallback">
154
+ <summary>Dataview query</summary>
155
+ <pre><code>LIST FROM #project</code></pre>
156
+ </details>
157
+ </div>
158
+ ```
159
+
160
+ `<details>` のフォールバックには元のクエリが入ります。`hideFallback` で非表示にできます。
161
+
162
+ ## 診断
163
+
164
+ - `dataviewjs` のブロックはそのまま残し、`dataview-unsupported-language` の**警告**を出します。Markdown 解析時の remark 変換でも `source: "@riebeckite/plugin-dataview"` を付けた `file.message` を記録します。
165
+ - パーサーや評価器が扱えないブロックは、その場にエラー表示を出しつつ `dataview-invalid` の**エラー**診断を生成します。対応していない構文は、Markdown 解析時にも `file.message` で報告されます。
166
+
167
+ ## 制限事項
168
+
169
+ - **DataviewJS には対応しません。** `dataviewjs` は意図的に対象外です。
170
+ - **インラインフィールド(`field:: value`)には対応しません。** 参照するのはフロントマターだけです。
171
+ - **`TABLE` の列はフィールドパスです。** 任意の式は書けません。見出しの変更は `AS "Label"` だけです(`file.size / 1024` のような計算列は不可)。
172
+ - **`TASK` が絞り込むのはノートです。** `FROM` / `WHERE` はタスクを含むノートに働きます。
173
+ - **`CALENDAR` が表示するのは1か月分**です。一致した日付のうち最も新しい月を描画します。
174
+ - `file.size`、`file.mtime`、`file.ctime` はマニフェストから取得できず `undefined` になります。
175
+ - 結果はビルド時に確定します。dataview ブロックが生成したリンクはコンテンツグラフ(バックリンク)には含まれません。フルビルドでは常に正しく再計算されます。
176
+
177
+ ## エクスポート
178
+
179
+ - `dataviewPlugin(options?)` / `dataview(options?)` — プラグインファクトリ
180
+ - `remarkDataview(options?)` — Remark 変換だけを利用する場合の API
181
+ - `parseDataview(source)` — ブロック本文を `DataviewSpec` に変換
182
+ - `selectDataviewEntries(spec, manifest, defaultLimit)` — 照合エンジン
183
+ - `evaluateDataviewExpression(expression, scope)` と `matchesDataviewFrom(from, entry, manifest)` — 式のヘルパー
184
+ - `renderDataview(selection, spec, options, source)` — HTML レンダラー
185
+ - `resolveDataviewOptions(options?)` — オプションの正規化
186
+ - `DATAVIEW_ATTRIBUTE` — プレースホルダーの属性名
187
+ - 型: `DataviewOptions`、`DataviewSpec`、`DataviewQueryType`、`DataviewExpression`、`DataviewFrom` ほか
188
+
189
+ ## 関連資料
190
+
191
+ - [プラグインシステム](../../../docs/ja/reference/plugin-api.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-dataview",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "@types/mdast": "^4.0.4",
19
19
  "unist-util-visit": "^5.1.0",
20
- "@riebeckite/core": "0.0.11"
20
+ "@riebeckite/core": "0.0.13"
21
21
  },
22
22
  "publishConfig": {
23
23
  "access": "public"