@riebeckite/plugin-bases 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 +180 -0
- package/README_ja.md +155 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +909 -0
- package/dist/src/evaluate.d.ts +6 -0
- package/dist/src/parse.d.ts +19 -0
- package/dist/src/placeholder.d.ts +21 -0
- package/dist/src/remark.d.ts +14 -0
- package/dist/src/render.d.ts +6 -0
- package/dist/src/runtime.d.ts +13 -0
- package/dist/src/types.d.ts +82 -0
- package/package.json +58 -0
- package/style.css +145 -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,180 @@
|
|
|
1
|
+
# @riebeckite/plugin-bases
|
|
2
|
+
|
|
3
|
+
Render Obsidian Bases definitions from fenced `base` code blocks. Filtering,
|
|
4
|
+
sorting, and view composition run against the content manifest at build time, so
|
|
5
|
+
no client-side JavaScript is required.
|
|
6
|
+
|
|
7
|
+
[日本語](./README_ja.md)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`bases()` recognises fenced blocks
|
|
12
|
+
|
|
13
|
+
````md
|
|
14
|
+
```base
|
|
15
|
+
filters:
|
|
16
|
+
and:
|
|
17
|
+
- file.hasTag("featured")
|
|
18
|
+
properties:
|
|
19
|
+
file.name:
|
|
20
|
+
displayName: Title
|
|
21
|
+
file.tags:
|
|
22
|
+
displayName: Tags
|
|
23
|
+
views:
|
|
24
|
+
- type: table
|
|
25
|
+
name: Featured
|
|
26
|
+
order:
|
|
27
|
+
- file.name
|
|
28
|
+
- file.tags
|
|
29
|
+
limit: 10
|
|
30
|
+
```
|
|
31
|
+
````
|
|
32
|
+
|
|
33
|
+
and renders them using the content manifest (every note's frontmatter, tags,
|
|
34
|
+
links, and permalink).
|
|
35
|
+
|
|
36
|
+
## Usage
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineConfig } from "@riebeckite/core";
|
|
40
|
+
import { bases } from "@riebeckite/plugin-bases";
|
|
41
|
+
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
// ...
|
|
44
|
+
plugins: [bases()],
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Block syntax
|
|
49
|
+
|
|
50
|
+
The block body is an Obsidian Base YAML document.
|
|
51
|
+
|
|
52
|
+
| Field | Type | Description |
|
|
53
|
+
| ----- | ---- | ----------- |
|
|
54
|
+
| `filters` | expression \| list \| object | Top-level filter applied to every view (below) |
|
|
55
|
+
| `properties` | object | Property id -> display name (or `{ displayName }`) |
|
|
56
|
+
| `views` | object[] | One or more views |
|
|
57
|
+
|
|
58
|
+
### Views
|
|
59
|
+
|
|
60
|
+
| Field | Type | Description |
|
|
61
|
+
| ----- | ---- | ----------- |
|
|
62
|
+
| `type` | `"table"` \| `"cards"` | Output kind. Defaults to `table` |
|
|
63
|
+
| `name` | string | Optional label rendered above the view |
|
|
64
|
+
| `filters` | filter | Additional filter, combined with the top-level filter using AND |
|
|
65
|
+
| `order` | string \| string[] | Columns (property ids) and their display order |
|
|
66
|
+
| `columns` | string \| string[] | Alias for `order` |
|
|
67
|
+
| `sort` | object \| object[] \| string | Sort keys (below) |
|
|
68
|
+
| `limit` | number | Row cap for this view; still bounded by the `limit` option |
|
|
69
|
+
|
|
70
|
+
`sort` accepts the Core shape `{ field, order }`, the Obsidian shape
|
|
71
|
+
`{ property, direction }`, or a shorthand string (`"-file.name"` sorts
|
|
72
|
+
descending). When a view omits `order`/`columns`, the columns are the keys of
|
|
73
|
+
`properties` (in order), or `["file.name", "file.tags"]`.
|
|
74
|
+
|
|
75
|
+
### Filter grammar
|
|
76
|
+
|
|
77
|
+
A filter is an expression string, a list of expressions (treated as AND), or an
|
|
78
|
+
object with `and` / `or` / `not` keys. `and` and `or` take a list; `not` takes an
|
|
79
|
+
expression or a list (the list is ANDed, then negated). A plain object whose keys
|
|
80
|
+
are property names is treated as equality.
|
|
81
|
+
|
|
82
|
+
| Expression | Description |
|
|
83
|
+
| ---------- | ----------- |
|
|
84
|
+
| `file.hasTag("x")` | Has the tag `x` (or a subtag `x/...`). Case-insensitive |
|
|
85
|
+
| `file.inFolder("x")` | Slug equals `x` or starts with `x/` |
|
|
86
|
+
| `file.hasLink("x")` | Links to `x` (by resolved slug, raw target, or file name) |
|
|
87
|
+
| `file.name` / `file.title` | Note title |
|
|
88
|
+
| `file.path` / `file.slug` | Slug |
|
|
89
|
+
| `file.folder` | Parent folder of the slug |
|
|
90
|
+
| `file.link` / `file.permalink` | Permalink |
|
|
91
|
+
| `file.tags` | Tags |
|
|
92
|
+
| `note.key` / `key` | A frontmatter value |
|
|
93
|
+
|
|
94
|
+
Comparisons use `==`, `!=`, `>`, `<`, `>=`, `<=`, and `contains`. String
|
|
95
|
+
comparisons are case-insensitive; `contains` tests array membership or substring
|
|
96
|
+
containment. Bare scalar lists are ANDed.
|
|
97
|
+
|
|
98
|
+
```yaml
|
|
99
|
+
filters:
|
|
100
|
+
and:
|
|
101
|
+
- file.hasTag("featured")
|
|
102
|
+
- or:
|
|
103
|
+
- note.status == "published"
|
|
104
|
+
- note.status == "review"
|
|
105
|
+
- not:
|
|
106
|
+
- file.hasTag("draft")
|
|
107
|
+
views:
|
|
108
|
+
- type: table
|
|
109
|
+
name: Featured
|
|
110
|
+
order: [file.name, note.status]
|
|
111
|
+
sort:
|
|
112
|
+
- property: file.name
|
|
113
|
+
direction: ASC
|
|
114
|
+
limit: 20
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Options
|
|
118
|
+
|
|
119
|
+
| Option | Type | Default | Description |
|
|
120
|
+
| ------ | ---- | ------- | ----------- |
|
|
121
|
+
| `className` | `string` | `"rb-bases"` | Root CSS class |
|
|
122
|
+
| `language` | `string` | `"base"` | Fence language to target |
|
|
123
|
+
| `limit` | `number` | `100` | Global row cap applied to every view |
|
|
124
|
+
| `showFallback` | `boolean` | `true` | Render the raw Base definition in a `<details>` fallback |
|
|
125
|
+
| `view` | `string` | none | Render only the view with this name when a Base defines several |
|
|
126
|
+
|
|
127
|
+
## Output HTML / CSS hooks
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<div class="rb-bases" data-bases data-bases-view="table">
|
|
131
|
+
<section class="rb-bases__view" data-bases-view="table">
|
|
132
|
+
<h3 class="rb-bases__view-name">Featured</h3>
|
|
133
|
+
<table class="rb-bases__table"> ... </table>
|
|
134
|
+
</section>
|
|
135
|
+
<details class="rb-bases__fallback"> ... </details>
|
|
136
|
+
</div>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Stable classes: `rb-bases`, `rb-bases__view`, `rb-bases__view-name`,
|
|
140
|
+
`rb-bases__table`, `rb-bases__heading`, `rb-bases__cell`, `rb-bases__row`,
|
|
141
|
+
`rb-bases__link`, `rb-bases__tags`, `rb-bases__tag`, `rb-bases__cards`,
|
|
142
|
+
`rb-bases__card`, `rb-bases__card-title`, `rb-bases__fields`, `rb-bases__field`,
|
|
143
|
+
`rb-bases__field-label`, `rb-bases__field-value`, `rb-bases__empty`,
|
|
144
|
+
`rb-bases__fallback`, `rb-bases--error`. Stable attributes: `data-bases`,
|
|
145
|
+
`data-bases-view`.
|
|
146
|
+
|
|
147
|
+
## Diagnostics
|
|
148
|
+
|
|
149
|
+
A block that is not valid YAML, or that uses an unsupported filter expression or
|
|
150
|
+
view shape, is left as a code block and reported through `file.message(...)` with
|
|
151
|
+
`source: "@riebeckite/plugin-bases"`.
|
|
152
|
+
|
|
153
|
+
## Limitations
|
|
154
|
+
|
|
155
|
+
This is an MVP subset of Obsidian Bases:
|
|
156
|
+
|
|
157
|
+
- Only the `table` and `cards` view types are rendered.
|
|
158
|
+
- Inline boolean operators (`&&`, `||`, `!`) are not supported; use the
|
|
159
|
+
`and` / `or` / `not` YAML structure.
|
|
160
|
+
- `if()` / `filter()` and other Base formula functions are not supported.
|
|
161
|
+
- Nested property paths and `file.mtime` / `file.ctime` are mapped onto `date`.
|
|
162
|
+
- Property-to-property comparisons are not supported; the right-hand side is a
|
|
163
|
+
literal.
|
|
164
|
+
- Results are fixed at build time. Rebuilding a host note when a queried note
|
|
165
|
+
changes is future work; a full build always recomputes correctly.
|
|
166
|
+
|
|
167
|
+
## Exports
|
|
168
|
+
|
|
169
|
+
- `bases(options?)` — plugin factory (alias: `basesPlugin`)
|
|
170
|
+
- `remarkBases(options?)` — remark transform usable on its own (`options.language`
|
|
171
|
+
selects the fence language)
|
|
172
|
+
- `parseBases(document)` — compiles a parsed YAML Base document to a spec
|
|
173
|
+
- `matchesCondition(condition, entry)` — condition evaluator
|
|
174
|
+
- Types: `BasesOptions`, `BasesSpec`, `BasesView`, `BasesViewType`,
|
|
175
|
+
`BasesCondition`, `BasesValueRef`, `BasesBuiltinValue`, `BasesOperator`,
|
|
176
|
+
`BasesLiteral`
|
|
177
|
+
|
|
178
|
+
## See also
|
|
179
|
+
|
|
180
|
+
- [Plugin guide](../../../docs/en/plugin-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @riebeckite/plugin-bases
|
|
2
|
+
|
|
3
|
+
フェンスコードブロック `base` に書いた Obsidian Bases 定義を HTML にレンダリングします。フィルタ・ソート・ビューの組み立てはビルド時にコンテンツマニフェストに対して行われるため、クライアントサイド JavaScript は不要です。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 概要
|
|
8
|
+
|
|
9
|
+
`bases()` は次のようなフェンスブロックを認識します。
|
|
10
|
+
|
|
11
|
+
````md
|
|
12
|
+
```base
|
|
13
|
+
filters:
|
|
14
|
+
and:
|
|
15
|
+
- file.hasTag("featured")
|
|
16
|
+
properties:
|
|
17
|
+
file.name:
|
|
18
|
+
displayName: Title
|
|
19
|
+
file.tags:
|
|
20
|
+
displayName: Tags
|
|
21
|
+
views:
|
|
22
|
+
- type: table
|
|
23
|
+
name: Featured
|
|
24
|
+
order:
|
|
25
|
+
- file.name
|
|
26
|
+
- file.tags
|
|
27
|
+
limit: 10
|
|
28
|
+
```
|
|
29
|
+
````
|
|
30
|
+
|
|
31
|
+
レンダリングにはコンテンツマニフェスト(各ノートの frontmatter・タグ・リンク・パーマリンク)を使います。
|
|
32
|
+
|
|
33
|
+
## 使い方
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { defineConfig } from "@riebeckite/core";
|
|
37
|
+
import { bases } from "@riebeckite/plugin-bases";
|
|
38
|
+
|
|
39
|
+
export default defineConfig({
|
|
40
|
+
// ...
|
|
41
|
+
plugins: [bases()],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## ブロックの構文
|
|
46
|
+
|
|
47
|
+
ブロック本体は Obsidian Base の YAML ドキュメントです。
|
|
48
|
+
|
|
49
|
+
| フィールド | 型 | 説明 |
|
|
50
|
+
| ---------- | -- | ---- |
|
|
51
|
+
| `filters` | 式 \| リスト \| オブジェクト | 全ビューに適用するトップレベルフィルタ(後述) |
|
|
52
|
+
| `properties` | オブジェクト | プロパティ ID → 表示名(または `{ displayName }`) |
|
|
53
|
+
| `views` | オブジェクト[] | 1 つ以上のビュー |
|
|
54
|
+
|
|
55
|
+
### ビュー
|
|
56
|
+
|
|
57
|
+
| フィールド | 型 | 説明 |
|
|
58
|
+
| ---------- | -- | ---- |
|
|
59
|
+
| `type` | `"table"` \| `"cards"` | 出力形式。既定は `table` |
|
|
60
|
+
| `name` | string | ビュー上部に表示する任意のラベル |
|
|
61
|
+
| `filters` | フィルタ | トップレベルフィルタに AND で合成する追加フィルタ |
|
|
62
|
+
| `order` | string \| string[] | 列(プロパティ ID)と表示順 |
|
|
63
|
+
| `columns` | string \| string[] | `order` の別名 |
|
|
64
|
+
| `sort` | オブジェクト \| オブジェクト[] \| string | ソートキー(後述) |
|
|
65
|
+
| `limit` | number | このビューの行数上限。`limit` オプション以下に制限される |
|
|
66
|
+
|
|
67
|
+
`sort` は Core 形式 `{ field, order }`、Obsidian 形式 `{ property, direction }`、短縮文字列(`"-file.name"` で降順)のいずれかを受け付けます。ビューに `order` / `columns` がない場合、列は `properties` のキー(定義順)、それもなければ `["file.name", "file.tags"]` になります。
|
|
68
|
+
|
|
69
|
+
### フィルタの文法
|
|
70
|
+
|
|
71
|
+
フィルタは式文字列、式のリスト(AND として扱う)、または `and` / `or` / `not` を持つオブジェクトです。`and` と `or` はリストを取り、`not` は式またはリスト(リストは AND でまとめてから否定)を取ります。プロパティ名をキーにした素のオブジェクトは等価比較として扱います。
|
|
72
|
+
|
|
73
|
+
| 式 | 説明 |
|
|
74
|
+
| -- | ---- |
|
|
75
|
+
| `file.hasTag("x")` | タグ `x`(またはサブタグ `x/...`)を持つ。大文字小文字は区別しない |
|
|
76
|
+
| `file.inFolder("x")` | スラグが `x` に一致するか `x/` で始まる |
|
|
77
|
+
| `file.hasLink("x")` | `x` へのリンクがある(解決済みスラグ・生のターゲット・ファイル名で照合) |
|
|
78
|
+
| `file.name` / `file.title` | ノートのタイトル |
|
|
79
|
+
| `file.path` / `file.slug` | スラグ |
|
|
80
|
+
| `file.folder` | スラグの親フォルダ |
|
|
81
|
+
| `file.link` / `file.permalink` | パーマリンク |
|
|
82
|
+
| `file.tags` | タグ |
|
|
83
|
+
| `note.key` / `key` | frontmatter の値 |
|
|
84
|
+
|
|
85
|
+
比較演算子は `==`、`!=`、`>`、`<`、`>=`、`<=`、`contains` です。文字列比較は大文字小文字を区別せず、`contains` は配列の要素または文字列の部分一致を調べます。スカラーのリストは AND として扱います。
|
|
86
|
+
|
|
87
|
+
```yaml
|
|
88
|
+
filters:
|
|
89
|
+
and:
|
|
90
|
+
- file.hasTag("featured")
|
|
91
|
+
- or:
|
|
92
|
+
- note.status == "published"
|
|
93
|
+
- note.status == "review"
|
|
94
|
+
- not:
|
|
95
|
+
- file.hasTag("draft")
|
|
96
|
+
views:
|
|
97
|
+
- type: table
|
|
98
|
+
name: Featured
|
|
99
|
+
order: [file.name, note.status]
|
|
100
|
+
sort:
|
|
101
|
+
- property: file.name
|
|
102
|
+
direction: ASC
|
|
103
|
+
limit: 20
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## オプション
|
|
107
|
+
|
|
108
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
109
|
+
| ---------- | -- | ------ | ---- |
|
|
110
|
+
| `className` | `string` | `"rb-bases"` | ルート CSS クラス |
|
|
111
|
+
| `language` | `string` | `"base"` | 対象とするフェンス言語 |
|
|
112
|
+
| `limit` | `number` | `100` | 全ビューに適用する行数上限 |
|
|
113
|
+
| `showFallback` | `boolean` | `true` | 生の Base 定義を `<details>` のフォールバックに表示する |
|
|
114
|
+
| `view` | `string` | なし | Base に複数ビューがあるとき、指定名のビューだけをレンダリングする |
|
|
115
|
+
|
|
116
|
+
## 出力 HTML / CSS フック
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
<div class="rb-bases" data-bases data-bases-view="table">
|
|
120
|
+
<section class="rb-bases__view" data-bases-view="table">
|
|
121
|
+
<h3 class="rb-bases__view-name">Featured</h3>
|
|
122
|
+
<table class="rb-bases__table"> ... </table>
|
|
123
|
+
</section>
|
|
124
|
+
<details class="rb-bases__fallback"> ... </details>
|
|
125
|
+
</div>
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
安定クラス: `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`。安定属性: `data-bases`、`data-bases-view`。
|
|
129
|
+
|
|
130
|
+
## 診断
|
|
131
|
+
|
|
132
|
+
YAML として不正なブロック、未対応のフィルタ式やビュー形状を使ったブロックはコードブロックのまま残し、`source: "@riebeckite/plugin-bases"` を付けて `file.message(...)` で報告します。
|
|
133
|
+
|
|
134
|
+
## 制限事項
|
|
135
|
+
|
|
136
|
+
これは Obsidian Bases の MVP サブセットです。
|
|
137
|
+
|
|
138
|
+
- レンダリングできるのは `table` と `cards` の 2 種類のビューだけです。
|
|
139
|
+
- インラインの論理演算子(`&&`、`||`、`!`)は未対応です。`and` / `or` / `not` の YAML 構造を使ってください。
|
|
140
|
+
- `if()` / `filter()` などの Base フォーミュラ関数は未対応です。
|
|
141
|
+
- ネストしたプロパティパスと `file.mtime` / `file.ctime` は `date` にマップされます。
|
|
142
|
+
- プロパティ同士の比較は未対応で、右辺はリテラルです。
|
|
143
|
+
- 結果はビルド時に確定します。参照先ノートの変更に応じてホストノートだけを再ビルドするのは今後の課題で、フルビルドでは常に正しく再計算されます。
|
|
144
|
+
|
|
145
|
+
## エクスポート
|
|
146
|
+
|
|
147
|
+
- `bases(options?)` — プラグインファクトリ(別名: `basesPlugin`)
|
|
148
|
+
- `remarkBases(options?)` — 単体で使える remark トランスフォーム(`options.language` でフェンス言語を選択)
|
|
149
|
+
- `parseBases(document)` — パース済み YAML Base ドキュメントをスペックにコンパイル
|
|
150
|
+
- `matchesCondition(condition, entry)` — 条件評価関数
|
|
151
|
+
- 型: `BasesOptions`、`BasesSpec`、`BasesView`、`BasesViewType`、`BasesCondition`、`BasesValueRef`、`BasesBuiltinValue`、`BasesOperator`、`BasesLiteral`
|
|
152
|
+
|
|
153
|
+
## 関連
|
|
154
|
+
|
|
155
|
+
- [プラグインガイド](../../../docs/ja/plugin-system.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { BasesOptions } from "./src/types.js";
|
|
2
|
+
export { remarkBases } from "./src/remark.js";
|
|
3
|
+
export { parseBases } from "./src/parse.js";
|
|
4
|
+
export { matchesCondition, resolveValueRef } from "./src/evaluate.js";
|
|
5
|
+
export type { BasesBuiltinValue, BasesCondition, BasesLiteral, BasesOperator, BasesOptions, BasesSpec, BasesValueRef, BasesView, BasesViewType, } from "./src/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* Renders Obsidian Bases definitions from fenced `base` code blocks.
|
|
8
|
+
*
|
|
9
|
+
* A block body is an Obsidian Base YAML document. It is compiled to a filter /
|
|
10
|
+
* sort / view spec at parse time and rendered against the content manifest at
|
|
11
|
+
* build time, so no client-side JavaScript is required.
|
|
12
|
+
*/
|
|
13
|
+
export declare function bases(options?: BasesOptions): import("@riebeckite/core").RiebeckitePlugin<BasesOptions>;
|
|
14
|
+
/** Alias kept for symmetry with other plugin factories. */
|
|
15
|
+
export declare const basesPlugin: typeof bases;
|