@riebeckite/plugin-dataview 0.0.1
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.
- package/LICENSE +201 -0
- package/README.md +227 -0
- package/README_ja.md +191 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1258 -0
- package/dist/src/evaluate.d.ts +28 -0
- package/dist/src/parse.d.ts +11 -0
- package/dist/src/placeholder.d.ts +5 -0
- package/dist/src/remark.d.ts +5 -0
- package/dist/src/render.d.ts +4 -0
- package/dist/src/runtime.d.ts +7 -0
- package/dist/src/types.d.ts +95 -0
- package/package.json +57 -0
- package/style.css +192 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright Rerurate_514
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +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)
|
package/README_ja.md
ADDED
|
@@ -0,0 +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)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DataviewOptions } from "./src/types.js";
|
|
2
|
+
export { parseDataview, DataviewParseError } from "./src/parse.js";
|
|
3
|
+
export { selectDataviewEntries, evaluateDataviewExpression, matchesDataviewFrom, readDataviewField, toDataviewTime, isTruthy, DataviewEvaluationError, type DataviewGroup, type DataviewScope, type DataviewSelection, } from "./src/evaluate.js";
|
|
4
|
+
export { renderDataview, renderDataviewError } from "./src/render.js";
|
|
5
|
+
export { remarkDataview, type RemarkDataviewOptions } from "./src/remark.js";
|
|
6
|
+
export { DATAVIEW_ATTRIBUTE, createDataviewPlaceholder, createDataviewPlaceholderPattern, } from "./src/placeholder.js";
|
|
7
|
+
export { DEFAULT_DATAVIEW_CLASS_NAME, DEFAULT_DATAVIEW_LANGUAGE, resolveDataviewOptions, type DataviewColumn, type DataviewComparisonOperator, type DataviewExpression, type DataviewFrom, type DataviewOptions, type DataviewParseResult, type DataviewQueryType, type DataviewSort, type DataviewSortOrder, type DataviewSource, type DataviewSpec, type ResolvedDataviewOptions, } from "./src/types.js";
|
|
8
|
+
export declare function dataviewPlugin(options?: DataviewOptions): import("@riebeckite/core").RiebeckitePlugin<DataviewOptions>;
|
|
9
|
+
export declare const dataview: typeof dataviewPlugin;
|