@riebeckite/plugin-dataset 0.0.0-stage → 0.2.0
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 +92 -2
- package/README_ja.md +72 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +165 -0
- package/dist/src/dataset.d.ts +39 -0
- package/package.json +57 -3
- package/schema/index.schema.json +30 -0
- package/schema/links.schema.json +42 -0
- package/schema/pages.schema.json +45 -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
CHANGED
|
@@ -1,3 +1,93 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @riebeckite/plugin-dataset
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<!-- Generated from docs/docs/plugins/dataset.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
|
+
|
|
5
|
+
Versioned NDJSON exports of the published content graph, written at build
|
|
6
|
+
time.
|
|
7
|
+
|
|
8
|
+
[日本語](./README_ja.md)
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
`dataset()` writes three generated files under `data/` (configurable with the
|
|
13
|
+
`directory` option):
|
|
14
|
+
|
|
15
|
+
- `pages.ndjson`: one JSON object per discoverable note —
|
|
16
|
+
`{ slug, permalink, title, tags, date, excerpt, body }` plus `language`
|
|
17
|
+
for localized notes
|
|
18
|
+
- `links.ndjson`: one JSON object per resolved note-to-note link —
|
|
19
|
+
`{ sourceSlug, sourcePermalink, targetSlug, targetPermalink, raw, embed }`
|
|
20
|
+
- `index.json`: `{ schemaVersion, generator, pages, links }` — the dataset
|
|
21
|
+
schema version and record counts
|
|
22
|
+
|
|
23
|
+
The dataset reads `manifest.discoverableEntries`, so `unlisted`, `draft`, and
|
|
24
|
+
scheduled notes never appear in the output. Links whose source or target is
|
|
25
|
+
not a discoverable note are dropped, and non-note links (images, attachments,
|
|
26
|
+
unresolved wikilinks) are excluded from `links.ndjson`. `slug` stays the
|
|
27
|
+
internal identity and `permalink` the public URL. `excerpt` prefers the
|
|
28
|
+
frontmatter `description` and falls back to the note body (180 characters);
|
|
29
|
+
`body` carries up to 4,000 characters of plain text.
|
|
30
|
+
|
|
31
|
+
Output is deterministic: records are sorted by slug and the files contain no
|
|
32
|
+
timestamps, so building the same vault twice produces identical files.
|
|
33
|
+
|
|
34
|
+
## Schemas
|
|
35
|
+
|
|
36
|
+
The package ships normative JSON Schema documents for every record type, so
|
|
37
|
+
standalone consumers can validate the downloaded files without installing any
|
|
38
|
+
Riebeckite package:
|
|
39
|
+
|
|
40
|
+
```text
|
|
41
|
+
@riebeckite/plugin-dataset/schema/pages.schema.json
|
|
42
|
+
@riebeckite/plugin-dataset/schema/links.schema.json
|
|
43
|
+
@riebeckite/plugin-dataset/schema/index.schema.json
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Each `pages.ndjson` line is one `pages` record, each `links.ndjson` line is one
|
|
47
|
+
`links` record, and `index.json` matches `index`. The plugin's tests validate
|
|
48
|
+
generated output against these schemas and check the `index.json` record
|
|
49
|
+
counts, so a schema and implementation drift fails the build.
|
|
50
|
+
|
|
51
|
+
`schemaVersion` counts breaking changes to the record shapes: appending an
|
|
52
|
+
optional field keeps the version, while removing, renaming, or redefining a
|
|
53
|
+
field bumps it. See
|
|
54
|
+
[the dataset schema versioning ADR](https://github.com/Rerurate514/riebeckite/blob/main/docs/agents/adr/20261122-101500-dataset-schema-versioning-9d3f2a.md).
|
|
55
|
+
|
|
56
|
+
## Installation
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
npm install @riebeckite/plugin-dataset
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { defineConfig } from "@riebeckite/core";
|
|
66
|
+
import { dataset } from "@riebeckite/plugin-dataset";
|
|
67
|
+
|
|
68
|
+
export default defineConfig({
|
|
69
|
+
plugins: [dataset()],
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Options
|
|
74
|
+
|
|
75
|
+
| Option | Type | Default | Description |
|
|
76
|
+
| ------ | ---- | ------- | ----------- |
|
|
77
|
+
| `directory` | `string` | `data` | Output directory relative to the site root, without empty, `.`, or `..` segments |
|
|
78
|
+
| `exclude` | `string[]` | `[]` | Slug paths (and their descendants) dropped from every output, matching the discovery exclude semantics of other plugins |
|
|
79
|
+
|
|
80
|
+
## Exports
|
|
81
|
+
|
|
82
|
+
- `dataset()` — plugin factory
|
|
83
|
+
- `buildDatasetPages(entries, excludedSlugs?)` — page records from discoverable entries
|
|
84
|
+
- `buildDatasetLinks(entries, excludedSlugs?)` — link records between discoverable notes
|
|
85
|
+
- `buildDatasetOutputs(entries, directory, excludedSlugs?)` — planned generated outputs
|
|
86
|
+
- `buildDatasetIndex(pages, links)` — `DatasetIndex` record
|
|
87
|
+
- `toNdjson(records)` — NDJSON serialization
|
|
88
|
+
- Constants: `DATASET_SCHEMA_VERSION`, `DEFAULT_DATASET_DIRECTORY`, `DATASET_GENERATOR`
|
|
89
|
+
- Types: `DatasetPage`, `DatasetLink`, `DatasetIndex`, `DatasetPluginOptions`
|
|
90
|
+
|
|
91
|
+
## See also
|
|
92
|
+
|
|
93
|
+
- [Plugin guide](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/plugin-api.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @riebeckite/plugin-dataset
|
|
2
|
+
|
|
3
|
+
<!-- Generated from docs/docs/plugins/dataset.ja.md. Edit the canonical documentation in docs/docs/plugins and run `pnpm docs:sync`. -->
|
|
4
|
+
|
|
5
|
+
公開済みコンテンツグラフを、スキーマバージョン付きの NDJSON としてビルド時に書き出すプラグインです。
|
|
6
|
+
|
|
7
|
+
[English](./README.md)
|
|
8
|
+
|
|
9
|
+
## できること
|
|
10
|
+
|
|
11
|
+
`dataset()` は `data/` ディレクトリ(`directory` オプションで変更できます)に3つの生成ファイルを書き出します。
|
|
12
|
+
|
|
13
|
+
- `pages.ndjson`:公開ノート1件につき1行の JSON オブジェクト — `{ slug, permalink, title, tags, date, excerpt, body }`(ローカライズ済みノートは `language` を追加)
|
|
14
|
+
- `links.ndjson`:解決済みノート間リンク1件につき1行 — `{ sourceSlug, sourcePermalink, targetSlug, targetPermalink, raw, embed }`
|
|
15
|
+
- `index.json`:`{ schemaVersion, generator, pages, links }` — データセットのスキーマバージョンと件数
|
|
16
|
+
|
|
17
|
+
データセットは `manifest.discoverableEntries` を読むため、unlisted・draft・予約公開のノートは出力に現れません。送り元・送り先のどちらかでも公開ノートでないリンクは除外され、画像・添付ファイル・未解決のウィキリンクも `links.ndjson` には含まれません。`slug` は内部の識別子、`permalink` は公開URLという区別を維持します。`excerpt` は frontmatter の `description` を優先し、なければ本文から最大180文字、`body` は本文の平文を最大4,000文字まで収録します。
|
|
18
|
+
|
|
19
|
+
出力は決定的です。レコードは slug 順に並び、ファイルにタイムスタンプは含まれないため、同じ vault を2回ビルドすると同一のファイルが得られます。
|
|
20
|
+
|
|
21
|
+
## スキーマ
|
|
22
|
+
|
|
23
|
+
パッケージにはすべてのレコード型の正本(JSON Schema)が同梱されており、Riebeckite のパッケージを一切インストールせずに、ダウンロードしたファイルを検証できます。
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
@riebeckite/plugin-dataset/schema/pages.schema.json
|
|
27
|
+
@riebeckite/plugin-dataset/schema/links.schema.json
|
|
28
|
+
@riebeckite/plugin-dataset/schema/index.schema.json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`pages.ndjson` の各行が `pages` レコード、`links.ndjson` の各行が `links` レコード、`index.json` は `index` に対応します。プラグイン自身のテストが生成結果をこれらのスキーマと `index.json` の件数で検証するため、スキーマと実装がずれるとビルドが失敗します。
|
|
32
|
+
|
|
33
|
+
`schemaVersion` はレコード構造への破壊的変更のみをカウントします。オプションフィールドの追加はバージョンを維持し、フィールドの削除・リネーム・意味変更でバージョンを上げます。詳細は
|
|
34
|
+
[データセットスキーマのバージョニングに関する ADR](https://github.com/Rerurate514/riebeckite/blob/main/docs/agents/adr/20261122-101500-dataset-schema-versioning-9d3f2a.md)
|
|
35
|
+
を参照してください。
|
|
36
|
+
|
|
37
|
+
## インストール
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm install @riebeckite/plugin-dataset
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 設定と配置
|
|
44
|
+
|
|
45
|
+
```ts
|
|
46
|
+
import { defineConfig } from "@riebeckite/core";
|
|
47
|
+
import { dataset } from "@riebeckite/plugin-dataset";
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
plugins: [dataset()],
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| オプション | 型 | 既定値 | 内容 |
|
|
55
|
+
| --- | --- | --- | --- |
|
|
56
|
+
| `directory` | `string` | `data` | サイトルートからの出力ディレクトリ。空・`.`・`..` のセグメントは使えません |
|
|
57
|
+
| `exclude` | `string[]` | `[]` | すべての出力から除外する slug パス(子孫も含む)。他プラグインの discovery exclude と同じ意味論です |
|
|
58
|
+
|
|
59
|
+
## 公開 API
|
|
60
|
+
|
|
61
|
+
- `dataset()`:プラグインファクトリ
|
|
62
|
+
- `buildDatasetPages(entries, excludedSlugs?)`:公開エントリからページレコードを構築
|
|
63
|
+
- `buildDatasetLinks(entries, excludedSlugs?)`:公開ノート間のリンクレコードを構築
|
|
64
|
+
- `buildDatasetOutputs(entries, directory, excludedSlugs?)`:生成出力のプレビルド
|
|
65
|
+
- `buildDatasetIndex(pages, links)`:`DatasetIndex` レコード
|
|
66
|
+
- `toNdjson(records)`:NDJSON へのシリアライズ
|
|
67
|
+
- 定数:`DATASET_SCHEMA_VERSION`、`DEFAULT_DATASET_DIRECTORY`、`DATASET_GENERATOR`
|
|
68
|
+
- 型:`DatasetPage`、`DatasetLink`、`DatasetIndex`、`DatasetPluginOptions`
|
|
69
|
+
|
|
70
|
+
## 関連資料
|
|
71
|
+
|
|
72
|
+
- [プラグインシステム](https://github.com/Rerurate514/riebeckite/blob/main/docs/docs/reference/plugin-api.ja.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type DatasetPluginOptions } from "./src/dataset.js";
|
|
2
|
+
export type { DatasetIndex, DatasetLink, DatasetPage, DatasetPluginOptions, } from "./src/dataset.js";
|
|
3
|
+
export { buildDatasetIndex, buildDatasetLinks, buildDatasetOutputs, buildDatasetPages, DATASET_GENERATOR, DATASET_SCHEMA_VERSION, DEFAULT_DATASET_DIRECTORY, resolveDatasetDirectory, toNdjson, validateDatasetOptions, } from "./src/dataset.js";
|
|
4
|
+
export declare function dataset(options?: DatasetPluginOptions): import("@riebeckite/core").RiebeckitePlugin<DatasetPluginOptions>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { definePlugin } from "@riebeckite/core";
|
|
3
|
+
|
|
4
|
+
// src/dataset.ts
|
|
5
|
+
import {
|
|
6
|
+
createEntryExcerpt,
|
|
7
|
+
getEntryLanguage,
|
|
8
|
+
getEntryPlainText,
|
|
9
|
+
isExcludedSlugPath,
|
|
10
|
+
resolveEntryDate
|
|
11
|
+
} from "@riebeckite/core";
|
|
12
|
+
var DATASET_SCHEMA_VERSION = 1;
|
|
13
|
+
var DEFAULT_DATASET_DIRECTORY = "data";
|
|
14
|
+
var DATASET_GENERATOR = "@riebeckite/plugin-dataset";
|
|
15
|
+
var MAX_BODY_LENGTH = 4e3;
|
|
16
|
+
function validateDatasetOptions(options) {
|
|
17
|
+
const issues = [];
|
|
18
|
+
if (!options) return issues;
|
|
19
|
+
if (options.directory !== void 0) {
|
|
20
|
+
if (typeof options.directory !== "string" || options.directory.trim() === "") {
|
|
21
|
+
issues.push({
|
|
22
|
+
path: "directory",
|
|
23
|
+
message: "Expected a non-empty string."
|
|
24
|
+
});
|
|
25
|
+
} else if (options.directory.split("/").some(isInvalidSegment)) {
|
|
26
|
+
issues.push({
|
|
27
|
+
path: "directory",
|
|
28
|
+
message: "Expected a relative directory path without empty, '.', or '..' segments."
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (options.exclude !== void 0) {
|
|
33
|
+
if (!Array.isArray(options.exclude)) {
|
|
34
|
+
issues.push({ path: "exclude", message: "Expected an array." });
|
|
35
|
+
} else {
|
|
36
|
+
options.exclude.forEach((slug, index) => {
|
|
37
|
+
if (typeof slug !== "string" || slug.trim() === "") {
|
|
38
|
+
issues.push({
|
|
39
|
+
path: `exclude[${index}]`,
|
|
40
|
+
message: "Expected a non-empty string."
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return issues;
|
|
47
|
+
}
|
|
48
|
+
function resolveDatasetDirectory(directory) {
|
|
49
|
+
return directory?.trim() || DEFAULT_DATASET_DIRECTORY;
|
|
50
|
+
}
|
|
51
|
+
function buildDatasetPages(entries, excludedSlugs = []) {
|
|
52
|
+
return entries.filter((entry) => !isExcludedSlugPath(entry.slug, excludedSlugs)).map((entry) => {
|
|
53
|
+
const language = getEntryLanguage(entry);
|
|
54
|
+
return {
|
|
55
|
+
slug: entry.slug,
|
|
56
|
+
permalink: entry.permalink,
|
|
57
|
+
title: entry.title,
|
|
58
|
+
tags: entry.tags,
|
|
59
|
+
date: resolveEntryDate(entry.frontmatter),
|
|
60
|
+
excerpt: createEntryExcerpt(entry),
|
|
61
|
+
body: getEntryPlainText(entry).slice(0, MAX_BODY_LENGTH),
|
|
62
|
+
...language === void 0 ? {} : { language }
|
|
63
|
+
};
|
|
64
|
+
}).sort(compareBySlug);
|
|
65
|
+
}
|
|
66
|
+
function buildDatasetLinks(entries, excludedSlugs = []) {
|
|
67
|
+
const published = entries.filter(
|
|
68
|
+
(entry) => !isExcludedSlugPath(entry.slug, excludedSlugs)
|
|
69
|
+
);
|
|
70
|
+
const permalinks = new Map(
|
|
71
|
+
published.map((entry) => [entry.slug, entry.permalink])
|
|
72
|
+
);
|
|
73
|
+
const links = [];
|
|
74
|
+
for (const entry of published) {
|
|
75
|
+
for (const link of entry.links) {
|
|
76
|
+
if (link.kind !== "note" || link.slug === null) continue;
|
|
77
|
+
const targetPermalink = permalinks.get(link.slug);
|
|
78
|
+
if (targetPermalink === void 0) continue;
|
|
79
|
+
links.push({
|
|
80
|
+
sourceSlug: entry.slug,
|
|
81
|
+
sourcePermalink: entry.permalink,
|
|
82
|
+
targetSlug: link.slug,
|
|
83
|
+
targetPermalink,
|
|
84
|
+
raw: link.raw,
|
|
85
|
+
embed: link.embed
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return links.sort(
|
|
90
|
+
(a, b) => compareStrings(a.sourceSlug, b.sourceSlug) || compareStrings(a.targetSlug, b.targetSlug) || compareStrings(a.raw, b.raw)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
function buildDatasetIndex(pages, links) {
|
|
94
|
+
return {
|
|
95
|
+
schemaVersion: DATASET_SCHEMA_VERSION,
|
|
96
|
+
generator: DATASET_GENERATOR,
|
|
97
|
+
pages: pages.length,
|
|
98
|
+
links: links.length
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function toNdjson(records) {
|
|
102
|
+
if (records.length === 0) return "";
|
|
103
|
+
return `${records.map((record) => JSON.stringify(record)).join("\n")}
|
|
104
|
+
`;
|
|
105
|
+
}
|
|
106
|
+
function buildDatasetOutputs(entries, directory, excludedSlugs = []) {
|
|
107
|
+
const pages = buildDatasetPages(entries, excludedSlugs);
|
|
108
|
+
const links = buildDatasetLinks(entries, excludedSlugs);
|
|
109
|
+
const dependencies = [{ type: "global" }];
|
|
110
|
+
return [
|
|
111
|
+
{
|
|
112
|
+
path: `${directory}/pages.ndjson`,
|
|
113
|
+
content: toNdjson(pages),
|
|
114
|
+
dependencies
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
path: `${directory}/links.ndjson`,
|
|
118
|
+
content: toNdjson(links),
|
|
119
|
+
dependencies
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
path: `${directory}/index.json`,
|
|
123
|
+
content: `${JSON.stringify(buildDatasetIndex(pages, links), null, 2)}
|
|
124
|
+
`,
|
|
125
|
+
dependencies
|
|
126
|
+
}
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
function compareBySlug(a, b) {
|
|
130
|
+
return compareStrings(a.slug, b.slug);
|
|
131
|
+
}
|
|
132
|
+
function compareStrings(a, b) {
|
|
133
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
134
|
+
}
|
|
135
|
+
function isInvalidSegment(segment) {
|
|
136
|
+
return segment === "" || segment === "." || segment === "..";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// index.ts
|
|
140
|
+
function dataset(options = {}) {
|
|
141
|
+
const directory = resolveDatasetDirectory(options.directory);
|
|
142
|
+
return definePlugin({
|
|
143
|
+
name: "dataset",
|
|
144
|
+
options,
|
|
145
|
+
validateOptions: validateDatasetOptions,
|
|
146
|
+
planGeneratedOutputs: ({ manifest }) => buildDatasetOutputs(
|
|
147
|
+
manifest.discoverableEntries,
|
|
148
|
+
directory,
|
|
149
|
+
options.exclude ?? []
|
|
150
|
+
)
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export {
|
|
154
|
+
DATASET_GENERATOR,
|
|
155
|
+
DATASET_SCHEMA_VERSION,
|
|
156
|
+
DEFAULT_DATASET_DIRECTORY,
|
|
157
|
+
buildDatasetIndex,
|
|
158
|
+
buildDatasetLinks,
|
|
159
|
+
buildDatasetOutputs,
|
|
160
|
+
buildDatasetPages,
|
|
161
|
+
dataset,
|
|
162
|
+
resolveDatasetDirectory,
|
|
163
|
+
toNdjson,
|
|
164
|
+
validateDatasetOptions
|
|
165
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type ConfigValidationIssue, type ContentManifestEntry, type PlannedGeneratedOutput } from "@riebeckite/core";
|
|
2
|
+
export declare const DATASET_SCHEMA_VERSION = 1;
|
|
3
|
+
export declare const DEFAULT_DATASET_DIRECTORY = "data";
|
|
4
|
+
export declare const DATASET_GENERATOR = "@riebeckite/plugin-dataset";
|
|
5
|
+
export type DatasetPluginOptions = {
|
|
6
|
+
readonly directory?: string;
|
|
7
|
+
readonly exclude?: readonly string[];
|
|
8
|
+
};
|
|
9
|
+
export type DatasetPage = {
|
|
10
|
+
readonly slug: string;
|
|
11
|
+
readonly permalink: string;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly tags: readonly string[];
|
|
14
|
+
readonly date: string | null;
|
|
15
|
+
readonly excerpt: string;
|
|
16
|
+
readonly body: string;
|
|
17
|
+
readonly language?: string;
|
|
18
|
+
};
|
|
19
|
+
export type DatasetLink = {
|
|
20
|
+
readonly sourceSlug: string;
|
|
21
|
+
readonly sourcePermalink: string;
|
|
22
|
+
readonly targetSlug: string;
|
|
23
|
+
readonly targetPermalink: string;
|
|
24
|
+
readonly raw: string;
|
|
25
|
+
readonly embed: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type DatasetIndex = {
|
|
28
|
+
readonly schemaVersion: number;
|
|
29
|
+
readonly generator: string;
|
|
30
|
+
readonly pages: number;
|
|
31
|
+
readonly links: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function validateDatasetOptions(options: DatasetPluginOptions | undefined): readonly ConfigValidationIssue[];
|
|
34
|
+
export declare function resolveDatasetDirectory(directory: string | undefined): string;
|
|
35
|
+
export declare function buildDatasetPages(entries: readonly ContentManifestEntry[], excludedSlugs?: readonly string[]): readonly DatasetPage[];
|
|
36
|
+
export declare function buildDatasetLinks(entries: readonly ContentManifestEntry[], excludedSlugs?: readonly string[]): readonly DatasetLink[];
|
|
37
|
+
export declare function buildDatasetIndex(pages: readonly DatasetPage[], links: readonly DatasetLink[]): DatasetIndex;
|
|
38
|
+
export declare function toNdjson(records: readonly unknown[]): string;
|
|
39
|
+
export declare function buildDatasetOutputs(entries: readonly ContentManifestEntry[], directory: string, excludedSlugs?: readonly string[]): readonly PlannedGeneratedOutput[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-dataset",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"source": "./index.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./schema/pages.schema.json": "./schema/pages.schema.json",
|
|
16
|
+
"./schema/links.schema.json": "./schema/links.schema.json",
|
|
17
|
+
"./schema/index.schema.json": "./schema/index.schema.json"
|
|
18
|
+
},
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@riebeckite/core": "^0.2.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsx": "^4.22.4",
|
|
24
|
+
"@riebeckite/core": "0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"README.md",
|
|
32
|
+
"README_ja.md",
|
|
33
|
+
"schema",
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
39
|
+
"directory": "packages/plugins/dataset"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
44
|
+
},
|
|
45
|
+
"description": "Versioned NDJSON dataset exports of the published Riebeckite content graph.",
|
|
46
|
+
"keywords": [
|
|
47
|
+
"riebeckite",
|
|
48
|
+
"plugin",
|
|
49
|
+
"dataset",
|
|
50
|
+
"ndjson"
|
|
51
|
+
],
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
54
|
+
},
|
|
55
|
+
"sideEffects": false,
|
|
56
|
+
"scripts": {
|
|
57
|
+
"build": "node ../../../scripts/build_package.mjs",
|
|
58
|
+
"test": "node --import tsx --test \"test/*.test.ts\""
|
|
59
|
+
}
|
|
6
60
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "urn:riebeckite:dataset:index:v1",
|
|
4
|
+
"title": "Riebeckite dataset index",
|
|
5
|
+
"description": "index.json emitted by @riebeckite/plugin-dataset.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["schemaVersion", "generator", "pages", "links"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"schemaVersion": {
|
|
11
|
+
"type": "integer",
|
|
12
|
+
"minimum": 1,
|
|
13
|
+
"description": "Version of the pages and links record schemas; increments on breaking changes, additive optional fields keep the version."
|
|
14
|
+
},
|
|
15
|
+
"generator": {
|
|
16
|
+
"type": "string",
|
|
17
|
+
"const": "@riebeckite/plugin-dataset"
|
|
18
|
+
},
|
|
19
|
+
"pages": {
|
|
20
|
+
"type": "integer",
|
|
21
|
+
"minimum": 0,
|
|
22
|
+
"description": "Number of records in pages.ndjson."
|
|
23
|
+
},
|
|
24
|
+
"links": {
|
|
25
|
+
"type": "integer",
|
|
26
|
+
"minimum": 0,
|
|
27
|
+
"description": "Number of records in links.ndjson."
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "urn:riebeckite:dataset:links:v1",
|
|
4
|
+
"title": "Riebeckite dataset link record",
|
|
5
|
+
"description": "One record per line of links.ndjson, emitted by @riebeckite/plugin-dataset. Both ends are pages that appear in pages.ndjson.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": [
|
|
9
|
+
"sourceSlug",
|
|
10
|
+
"sourcePermalink",
|
|
11
|
+
"targetSlug",
|
|
12
|
+
"targetPermalink",
|
|
13
|
+
"raw",
|
|
14
|
+
"embed"
|
|
15
|
+
],
|
|
16
|
+
"properties": {
|
|
17
|
+
"sourceSlug": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "Internal slug of the linking page."
|
|
20
|
+
},
|
|
21
|
+
"sourcePermalink": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Published URL path of the linking page."
|
|
24
|
+
},
|
|
25
|
+
"targetSlug": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"description": "Internal slug of the linked page."
|
|
28
|
+
},
|
|
29
|
+
"targetPermalink": {
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "Published URL path of the linked page."
|
|
32
|
+
},
|
|
33
|
+
"raw": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"description": "Original wiki link text, for example [[note]] or ![[note]]."
|
|
36
|
+
},
|
|
37
|
+
"embed": {
|
|
38
|
+
"type": "boolean",
|
|
39
|
+
"description": "True when the link is an embed (![[...]])."
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "urn:riebeckite:dataset:pages:v1",
|
|
4
|
+
"title": "Riebeckite dataset page record",
|
|
5
|
+
"description": "One record per line of pages.ndjson, emitted by @riebeckite/plugin-dataset.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["slug", "permalink", "title", "tags", "date", "excerpt", "body"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"slug": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "Stable internal note identifier; unchanged when the public URL changes."
|
|
13
|
+
},
|
|
14
|
+
"permalink": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "Published URL path of the page."
|
|
17
|
+
},
|
|
18
|
+
"title": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "Resolved page title."
|
|
21
|
+
},
|
|
22
|
+
"tags": {
|
|
23
|
+
"type": "array",
|
|
24
|
+
"items": { "type": "string" },
|
|
25
|
+
"description": "Resolved entry tags."
|
|
26
|
+
},
|
|
27
|
+
"date": {
|
|
28
|
+
"type": ["string", "null"],
|
|
29
|
+
"format": "date-time",
|
|
30
|
+
"description": "Resolved publication date as an ISO 8601 datetime, or null when the note has no date."
|
|
31
|
+
},
|
|
32
|
+
"excerpt": {
|
|
33
|
+
"type": "string",
|
|
34
|
+
"description": "Frontmatter description when set, otherwise the leading plain text of the note, capped at 180 characters."
|
|
35
|
+
},
|
|
36
|
+
"body": {
|
|
37
|
+
"type": "string",
|
|
38
|
+
"description": "Plain-text body capped at 4,000 characters."
|
|
39
|
+
},
|
|
40
|
+
"language": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "Language of the entry's public location, omitted when unset."
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|