@riebeckite/plugin-series 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 +144 -0
- package/README_ja.md +125 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +309 -0
- package/dist/src/series.d.ts +31 -0
- package/dist/src/types.d.ts +43 -0
- package/package.json +55 -0
- package/style.css +91 -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,144 @@
|
|
|
1
|
+
# @riebeckite/plugin-series
|
|
2
|
+
|
|
3
|
+
Ordered multi-part posts ("series") for Riebeckite. At build time, notes that
|
|
4
|
+
share a series name get the same generated navigation listing every part in
|
|
5
|
+
order, with the current part marked and previous/next links.
|
|
6
|
+
|
|
7
|
+
[日本語](./README_ja.md)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`series()` reads series metadata from frontmatter, groups every matching
|
|
12
|
+
manifest entry, sorts the group, and appends a `<nav class="rb-series">` block
|
|
13
|
+
to each note in the series. Links use the permalinks resolved by Core, so
|
|
14
|
+
plugins such as `permalink` are respected. A single-note series renders no
|
|
15
|
+
navigation block.
|
|
16
|
+
|
|
17
|
+
The plugin is build-time only: it ships a stylesheet asset and no client
|
|
18
|
+
runtime.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { defineConfig } from "@riebeckite/core";
|
|
24
|
+
import { series } from "@riebeckite/plugin-series";
|
|
25
|
+
|
|
26
|
+
export default defineConfig({
|
|
27
|
+
// ...
|
|
28
|
+
plugins: [series()],
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Frontmatter contract
|
|
33
|
+
|
|
34
|
+
| Key | Type | Required | Description |
|
|
35
|
+
| --- | ---- | -------- | ----------- |
|
|
36
|
+
| `series` | `string` | yes | Series name used for grouping. |
|
|
37
|
+
| `series_order` | `number` | recommended | Position within the series (ascending). |
|
|
38
|
+
| `series_title` | `string` | no | Display title for the series heading. |
|
|
39
|
+
|
|
40
|
+
```yaml
|
|
41
|
+
---
|
|
42
|
+
title: Installing the thing
|
|
43
|
+
series: Build a thing
|
|
44
|
+
series_order: 2
|
|
45
|
+
---
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Notes missing a valid `series_order` are still included; they are ordered after
|
|
49
|
+
the numbered parts, using `date`/`created`/`published`, then `title`, then
|
|
50
|
+
`slug`. Ties always resolve deterministically.
|
|
51
|
+
|
|
52
|
+
## Options
|
|
53
|
+
|
|
54
|
+
| Option | Type | Default | Description |
|
|
55
|
+
| ------ | ---- | ------- | ----------- |
|
|
56
|
+
| `key` | `string` | `"series"` | Frontmatter key that names the series. |
|
|
57
|
+
| `orderKey` | `string` | `"series_order"` | Frontmatter key holding the numeric order. |
|
|
58
|
+
| `titleKey` | `string` | `"series_title"` | Frontmatter key overriding the series heading. |
|
|
59
|
+
| `heading` | `boolean` | `true` | Render the series heading above the list. |
|
|
60
|
+
| `className` | `string` | `"rb-series"` | Base CSS class for generated markup. |
|
|
61
|
+
| `positionLabel` | `boolean` | `false` | Add a `Part N of M` label for the current note. |
|
|
62
|
+
|
|
63
|
+
## Output
|
|
64
|
+
|
|
65
|
+
Each note in a series of two or more parts gets the following block appended to
|
|
66
|
+
its HTML:
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<nav class="rb-series" data-series="Build a thing"
|
|
70
|
+
aria-label="Series navigation">
|
|
71
|
+
<p class="rb-series__title">
|
|
72
|
+
<a class="rb-series__link" href="/build-a-thing">Build a thing</a>
|
|
73
|
+
</p>
|
|
74
|
+
<ol class="rb-series__list">
|
|
75
|
+
<li class="rb-series__item">
|
|
76
|
+
<a class="rb-series__link" href="/part-1" data-series-order="1">Part 1</a>
|
|
77
|
+
</li>
|
|
78
|
+
<li class="rb-series__item">
|
|
79
|
+
<a class="rb-series__link" href="/part-2" data-series-order="2"
|
|
80
|
+
aria-current="page">Part 2</a>
|
|
81
|
+
</li>
|
|
82
|
+
</ol>
|
|
83
|
+
<div class="rb-series__nav">
|
|
84
|
+
<a class="rb-series__prev" rel="prev" href="/part-1">← Part 1</a>
|
|
85
|
+
<a class="rb-series__next" rel="next" href="/part-3">Part 3 →</a>
|
|
86
|
+
</div>
|
|
87
|
+
</nav>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
All text and attributes are escaped. The injected HTML is written back to both
|
|
91
|
+
the manifest entry and the processed content object so the page route, feeds,
|
|
92
|
+
and search see the same markup.
|
|
93
|
+
|
|
94
|
+
## Exports
|
|
95
|
+
|
|
96
|
+
- `series(options?)` / `seriesPlugin(options?)` — plugin factory
|
|
97
|
+
- `buildSeriesIndex(manifest, name, options?)` — ordered members for one series
|
|
98
|
+
(`SeriesIndex | null`); useful for landing pages
|
|
99
|
+
- `renderSeriesIndex(manifest, name, options?)` — standalone `<section>` block
|
|
100
|
+
for a whole series
|
|
101
|
+
- `renderSeriesNavigation(index, currentSlug, options?)` — a single navigation
|
|
102
|
+
block
|
|
103
|
+
- `collectSeriesIndexes(manifest, options?)` — every series in first-seen order
|
|
104
|
+
- `resolveSeriesOptions(options?)` — options with defaults applied
|
|
105
|
+
- Types: `SeriesOptions`, `ResolvedSeriesOptions`, `SeriesMember`, `SeriesIndex`
|
|
106
|
+
|
|
107
|
+
### Series landing page
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
import { buildSeriesIndex, renderSeriesIndex } from "@riebeckite/plugin-series";
|
|
111
|
+
|
|
112
|
+
// inside a route component, with the resolved manifest:
|
|
113
|
+
const index = buildSeriesIndex(manifest, "Build a thing");
|
|
114
|
+
const html = renderSeriesIndex(manifest, "Build a thing");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Diagnostics
|
|
118
|
+
|
|
119
|
+
Emitted with `pluginName: "series"` and `severity: "warning"`:
|
|
120
|
+
|
|
121
|
+
| Code | Meaning |
|
|
122
|
+
| ---- | ------- |
|
|
123
|
+
| `series-invalid-name` | The series key is present but is not a non-empty string. |
|
|
124
|
+
| `series-missing-order` | The note has no valid numeric order key; fallback ordering is used. |
|
|
125
|
+
| `series-duplicate-order` | Two or more notes share the same `(series, order)` pair. |
|
|
126
|
+
|
|
127
|
+
## CSS hooks
|
|
128
|
+
|
|
129
|
+
`style.css` styles `.rb-series`, `.rb-series__title`, `.rb-series__position`,
|
|
130
|
+
`.rb-series__list`, `.rb-series__item`, `.rb-series__nav`, `.rb-series__prev`,
|
|
131
|
+
`.rb-series__next`, and the `.rb-series--index` variant. The current part is
|
|
132
|
+
matched with `.rb-series__item a[aria-current="page"]`.
|
|
133
|
+
|
|
134
|
+
## Limitations
|
|
135
|
+
|
|
136
|
+
- A note belongs to exactly one series.
|
|
137
|
+
- A series of one note produces no navigation block.
|
|
138
|
+
- `series_order` must be a finite number; numeric strings are not coerced.
|
|
139
|
+
- The plugin does not generate routes for series; combine
|
|
140
|
+
`renderSeriesIndex()` with your own page to build a series landing page.
|
|
141
|
+
|
|
142
|
+
## See also
|
|
143
|
+
|
|
144
|
+
- [Plugin guide](../../docs/plugins_en.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# @riebeckite/plugin-series
|
|
2
|
+
|
|
3
|
+
連載記事(シリーズ)を順番どおりに並べ、各記事へ共通のナビゲーションを差し込むプラグインです。ビルド時に、同じシリーズ名を持つノートをまとめて、目次・現在位置・前後の記事リンクを生成します。
|
|
4
|
+
|
|
5
|
+
[English](./README.md)
|
|
6
|
+
|
|
7
|
+
## 概要
|
|
8
|
+
|
|
9
|
+
`series()` は frontmatter からシリーズ情報を読み取り、該当するノートをグループ化して並べ替えたうえで、各ノートの HTML に `<nav class="rb-series">` ブロックを追加します。リンクには Core が解決したパーマリンクを使うため、`permalink` プラグインなどとも併用できます。1件だけのシリーズにはナビゲーションを出力しません。
|
|
10
|
+
|
|
11
|
+
このプラグインはビルド時のみ動作し、クライアント用のランタイムは持ちません(スタイルシートのみを登録します)。
|
|
12
|
+
|
|
13
|
+
## 設定する
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { defineConfig } from "@riebeckite/core";
|
|
17
|
+
import { series } from "@riebeckite/plugin-series";
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
// ...
|
|
21
|
+
plugins: [series()],
|
|
22
|
+
});
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## frontmatter の書き方
|
|
26
|
+
|
|
27
|
+
| キー | 型 | 必須 | 説明 |
|
|
28
|
+
| ---- | -- | ---- | ---- |
|
|
29
|
+
| `series` | `string` | はい | グループ化に使うシリーズ名。 |
|
|
30
|
+
| `series_order` | `number` | 推奨 | シリーズ内の並び順(昇順)。 |
|
|
31
|
+
| `series_title` | `string` | いいえ | 見出しに表示するシリーズ名。 |
|
|
32
|
+
|
|
33
|
+
```yaml
|
|
34
|
+
---
|
|
35
|
+
title: 導入編
|
|
36
|
+
series: 何かを作る
|
|
37
|
+
series_order: 2
|
|
38
|
+
---
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`series_order` が無い・不正なノートも対象に含まれます。その場合は番号付きの記事の後ろに並び、`date`/`created`/`published`、`title`、`slug` の順で安定して並べ替えます。同点の場合は常に決まった順序になります。
|
|
42
|
+
|
|
43
|
+
## オプション
|
|
44
|
+
|
|
45
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
46
|
+
| ---------- | -- | ------ | ---- |
|
|
47
|
+
| `key` | `string` | `"series"` | シリーズ名を持つ frontmatter キー。 |
|
|
48
|
+
| `orderKey` | `string` | `"series_order"` | 並び順の数値を持つ frontmatter キー。 |
|
|
49
|
+
| `titleKey` | `string` | `"series_title"` | 見出しのシリーズ名を上書きするキー。 |
|
|
50
|
+
| `heading` | `boolean` | `true` | リストの上に見出しを表示する。 |
|
|
51
|
+
| `className` | `string` | `"rb-series"` | 生成する HTML の基準クラス名。 |
|
|
52
|
+
| `positionLabel` | `boolean` | `false` | 現在の記事に「Part N of M」を付ける。 |
|
|
53
|
+
|
|
54
|
+
## 出力
|
|
55
|
+
|
|
56
|
+
2件以上あるシリーズの各ノートには、次のブロックが HTML の末尾に追加されます。
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<nav class="rb-series" data-series="何かを作る"
|
|
60
|
+
aria-label="Series navigation">
|
|
61
|
+
<p class="rb-series__title">
|
|
62
|
+
<a class="rb-series__link" href="/part-1">何かを作る</a>
|
|
63
|
+
</p>
|
|
64
|
+
<ol class="rb-series__list">
|
|
65
|
+
<li class="rb-series__item">
|
|
66
|
+
<a class="rb-series__link" href="/part-1" data-series-order="1">導入編</a>
|
|
67
|
+
</li>
|
|
68
|
+
<li class="rb-series__item">
|
|
69
|
+
<a class="rb-series__link" href="/part-2" data-series-order="2"
|
|
70
|
+
aria-current="page">実装編</a>
|
|
71
|
+
</li>
|
|
72
|
+
</ol>
|
|
73
|
+
<div class="rb-series__nav">
|
|
74
|
+
<a class="rb-series__prev" rel="prev" href="/part-1">← 導入編</a>
|
|
75
|
+
<a class="rb-series__next" rel="next" href="/part-3">仕上げ編 →</a>
|
|
76
|
+
</div>
|
|
77
|
+
</nav>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
テキストと属性はすべてエスケープします。生成した HTML は manifest の entry と処理済みコンテンツの両方へ書き戻すため、ページのルート表示・フィード・検索でも同じマークアップになります。
|
|
81
|
+
|
|
82
|
+
## 公開 API
|
|
83
|
+
|
|
84
|
+
- `series(options?)` / `seriesPlugin(options?)` — プラグインファクトリ
|
|
85
|
+
- `buildSeriesIndex(manifest, name, options?)` — 1つのシリーズの並び順付きメンバー(`SeriesIndex | null`)。ランディングページ向け
|
|
86
|
+
- `renderSeriesIndex(manifest, name, options?)` — シリーズ全体の `<section>` ブロック
|
|
87
|
+
- `renderSeriesNavigation(index, currentSlug, options?)` — ナビゲーション1つ分
|
|
88
|
+
- `collectSeriesIndexes(manifest, options?)` — 全シリーズを出現順で取得
|
|
89
|
+
- `resolveSeriesOptions(options?)` — 既定値を適用したオプション
|
|
90
|
+
- 型: `SeriesOptions`, `ResolvedSeriesOptions`, `SeriesMember`, `SeriesIndex`
|
|
91
|
+
|
|
92
|
+
### シリーズのランディングページ
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { buildSeriesIndex, renderSeriesIndex } from "@riebeckite/plugin-series";
|
|
96
|
+
|
|
97
|
+
// ルートコンポーネント内で、解決済みの manifest を使って:
|
|
98
|
+
const index = buildSeriesIndex(manifest, "何かを作る");
|
|
99
|
+
const html = renderSeriesIndex(manifest, "何かを作る");
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 診断
|
|
103
|
+
|
|
104
|
+
`pluginName: "series"`、`severity: "warning"` で出力します。
|
|
105
|
+
|
|
106
|
+
| コード | 意味 |
|
|
107
|
+
| ------ | ---- |
|
|
108
|
+
| `series-invalid-name` | シリーズのキーはあるが、空でない文字列になっていない。 |
|
|
109
|
+
| `series-missing-order` | 有効な数値の並び順キーが無く、代替の順序を使った。 |
|
|
110
|
+
| `series-duplicate-order` | 同じ `(シリーズ, 並び順)` の組を持つノートが複数ある。 |
|
|
111
|
+
|
|
112
|
+
## CSS フック
|
|
113
|
+
|
|
114
|
+
`style.css` は `.rb-series`、`.rb-series__title`、`.rb-series__position`、`.rb-series__list`、`.rb-series__item`、`.rb-series__nav`、`.rb-series__prev`、`.rb-series__next`、および `.rb-series--index` をスタイルします。現在の記事は `.rb-series__item a[aria-current="page"]` で判定できます。
|
|
115
|
+
|
|
116
|
+
## 制限
|
|
117
|
+
|
|
118
|
+
- 1つのノートが所属できるシリーズは1つだけです。
|
|
119
|
+
- 1件だけのシリーズにはナビゲーションを出力しません。
|
|
120
|
+
- `series_order` は有限の数値である必要があります。数値文字列は変換しません。
|
|
121
|
+
- シリーズ用のルートは生成しません。ランディングページを作る場合は `renderSeriesIndex()` を自前のページと組み合わせてください。
|
|
122
|
+
|
|
123
|
+
## 関連
|
|
124
|
+
|
|
125
|
+
- [プラグインガイド](../../docs/plugins_ja.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { resolveSeriesOptions } from "./src/series.js";
|
|
2
|
+
import type { SeriesOptions } from "./src/types.js";
|
|
3
|
+
export type { ResolvedSeriesOptions, SeriesIndex, SeriesMember, SeriesOptions, } from "./src/types.js";
|
|
4
|
+
export { buildSeriesIndex, collectSeriesIndexes, renderSeriesIndex, renderSeriesNavigation, } from "./src/series.js";
|
|
5
|
+
/**
|
|
6
|
+
* Series (ordered multi-part posts) for Riebeckite.
|
|
7
|
+
*
|
|
8
|
+
* Notes that share a `series` frontmatter value are gathered at build time and
|
|
9
|
+
* receive the same generated navigation (`<nav class="rb-series">`) listing
|
|
10
|
+
* every part in order, with the current part marked and previous/next links.
|
|
11
|
+
* Order is read from `series_order` (configurable); notes without a valid order
|
|
12
|
+
* fall back to `date`, then `title`, then `slug` for deterministic results.
|
|
13
|
+
*/
|
|
14
|
+
export declare function series(options?: SeriesOptions): import("@riebeckite/core").RiebeckitePlugin<SeriesOptions>;
|
|
15
|
+
export declare const seriesPlugin: typeof series;
|
|
16
|
+
/** Convenience re-export so tooling can resolve options without the factory. */
|
|
17
|
+
export { resolveSeriesOptions };
|
|
18
|
+
/** The default class name used by the plugin stylesheet. */
|
|
19
|
+
export declare const DEFAULT_CLASS_NAME: string;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import {
|
|
3
|
+
createStyleAsset,
|
|
4
|
+
definePlugin
|
|
5
|
+
} from "@riebeckite/core";
|
|
6
|
+
|
|
7
|
+
// src/series.ts
|
|
8
|
+
import {
|
|
9
|
+
escapeHtml,
|
|
10
|
+
escapeHtmlAttribute
|
|
11
|
+
} from "@riebeckite/core";
|
|
12
|
+
var DEFAULT_SERIES_CLASS_NAME = "rb-series";
|
|
13
|
+
function resolveSeriesOptions(options = {}) {
|
|
14
|
+
return {
|
|
15
|
+
key: options.key ?? "series",
|
|
16
|
+
orderKey: options.orderKey ?? "series_order",
|
|
17
|
+
titleKey: options.titleKey ?? "series_title",
|
|
18
|
+
heading: options.heading ?? true,
|
|
19
|
+
className: options.className ?? DEFAULT_SERIES_CLASS_NAME,
|
|
20
|
+
positionLabel: options.positionLabel ?? false
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function collectSeriesIndexes(manifest, options = {}) {
|
|
24
|
+
const resolved = resolveSeriesOptions(options);
|
|
25
|
+
const groups = /* @__PURE__ */ new Map();
|
|
26
|
+
const titles = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const entry of manifest.entries) {
|
|
28
|
+
const name = readSeriesName(entry, resolved.key);
|
|
29
|
+
if (!name) continue;
|
|
30
|
+
const group = groups.get(name);
|
|
31
|
+
if (group) group.push(entry);
|
|
32
|
+
else groups.set(name, [entry]);
|
|
33
|
+
if (!titles.has(name)) {
|
|
34
|
+
const title = readString(entry, resolved.titleKey);
|
|
35
|
+
if (title) titles.set(name, title);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const indexes = [];
|
|
39
|
+
for (const [name, entries] of groups) {
|
|
40
|
+
const members = [...entries].sort((a, b) => compareEntries(a, b, resolved)).map((entry) => toMember(manifest, entry, resolved, name));
|
|
41
|
+
indexes.push({ name, title: titles.get(name) ?? name, members });
|
|
42
|
+
}
|
|
43
|
+
return indexes;
|
|
44
|
+
}
|
|
45
|
+
function buildSeriesIndex(manifest, name, options = {}) {
|
|
46
|
+
return collectSeriesIndexes(manifest, options).find(
|
|
47
|
+
(index) => index.name === name
|
|
48
|
+
) ?? null;
|
|
49
|
+
}
|
|
50
|
+
function renderSeriesNavigation(index, currentSlug, options = {}) {
|
|
51
|
+
const resolved = resolveSeriesOptions(options);
|
|
52
|
+
const cls = resolved.className;
|
|
53
|
+
const members = index.members;
|
|
54
|
+
const position = members.findIndex((member) => member.slug === currentSlug);
|
|
55
|
+
const prev = position > 0 ? members[position - 1] : void 0;
|
|
56
|
+
const next = position >= 0 && position < members.length - 1 ? members[position + 1] : void 0;
|
|
57
|
+
const parts = [
|
|
58
|
+
`<nav class="${escapeHtmlAttribute(cls)}" data-series="${escapeHtmlAttribute(
|
|
59
|
+
index.name
|
|
60
|
+
)}" aria-label="Series navigation">`
|
|
61
|
+
];
|
|
62
|
+
if (resolved.heading && members.length > 0) {
|
|
63
|
+
const label = resolved.positionLabel && position >= 0 ? ` <span class="${escapeHtmlAttribute(
|
|
64
|
+
cls
|
|
65
|
+
)}__position">${escapeHtml(formatPosition(position + 1, members.length))}</span>` : "";
|
|
66
|
+
parts.push(
|
|
67
|
+
`<p class="${escapeHtmlAttribute(
|
|
68
|
+
cls
|
|
69
|
+
)}__title"><a class="${escapeHtmlAttribute(
|
|
70
|
+
cls
|
|
71
|
+
)}__link" href="${escapeHtmlAttribute(
|
|
72
|
+
members[0].permalink
|
|
73
|
+
)}">${escapeHtml(index.title)}</a>${label}</p>`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
parts.push(`<ol class="${escapeHtmlAttribute(cls)}__list">`);
|
|
77
|
+
members.forEach((member, i) => {
|
|
78
|
+
const current = member.slug === currentSlug;
|
|
79
|
+
const currentAttribute = current ? ' aria-current="page"' : "";
|
|
80
|
+
const order = member.order ?? i + 1;
|
|
81
|
+
parts.push(
|
|
82
|
+
`<li class="${escapeHtmlAttribute(cls)}__item"><a class="${escapeHtmlAttribute(
|
|
83
|
+
cls
|
|
84
|
+
)}__link" href="${escapeHtmlAttribute(
|
|
85
|
+
member.permalink
|
|
86
|
+
)}" data-series-order="${escapeHtmlAttribute(
|
|
87
|
+
String(order)
|
|
88
|
+
)}"${currentAttribute}>${escapeHtml(member.title)}</a></li>`
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
parts.push("</ol>");
|
|
92
|
+
parts.push(`<div class="${escapeHtmlAttribute(cls)}__nav">`);
|
|
93
|
+
if (prev) {
|
|
94
|
+
parts.push(
|
|
95
|
+
`<a class="${escapeHtmlAttribute(
|
|
96
|
+
cls
|
|
97
|
+
)}__prev" rel="prev" href="${escapeHtmlAttribute(
|
|
98
|
+
prev.permalink
|
|
99
|
+
)}">← ${escapeHtml(prev.title)}</a>`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (next) {
|
|
103
|
+
parts.push(
|
|
104
|
+
`<a class="${escapeHtmlAttribute(
|
|
105
|
+
cls
|
|
106
|
+
)}__next" rel="next" href="${escapeHtmlAttribute(
|
|
107
|
+
next.permalink
|
|
108
|
+
)}">${escapeHtml(next.title)} →</a>`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
parts.push("</div>");
|
|
112
|
+
parts.push("</nav>");
|
|
113
|
+
return parts.join("");
|
|
114
|
+
}
|
|
115
|
+
function renderSeriesIndex(manifest, name, options = {}) {
|
|
116
|
+
const index = buildSeriesIndex(manifest, name, options);
|
|
117
|
+
if (!index || index.members.length === 0) return "";
|
|
118
|
+
const resolved = resolveSeriesOptions(options);
|
|
119
|
+
const cls = resolved.className;
|
|
120
|
+
const parts = [
|
|
121
|
+
`<section class="${escapeHtmlAttribute(
|
|
122
|
+
cls
|
|
123
|
+
)} ${escapeHtmlAttribute(cls)}--index" data-series="${escapeHtmlAttribute(
|
|
124
|
+
index.name
|
|
125
|
+
)}">`,
|
|
126
|
+
`<h2 class="${escapeHtmlAttribute(cls)}__title">${escapeHtml(
|
|
127
|
+
index.title
|
|
128
|
+
)}</h2>`,
|
|
129
|
+
`<ol class="${escapeHtmlAttribute(cls)}__list">`
|
|
130
|
+
];
|
|
131
|
+
index.members.forEach((member, i) => {
|
|
132
|
+
const order = member.order ?? i + 1;
|
|
133
|
+
parts.push(
|
|
134
|
+
`<li class="${escapeHtmlAttribute(cls)}__item"><a class="${escapeHtmlAttribute(
|
|
135
|
+
cls
|
|
136
|
+
)}__link" href="${escapeHtmlAttribute(
|
|
137
|
+
member.permalink
|
|
138
|
+
)}" data-series-order="${escapeHtmlAttribute(
|
|
139
|
+
String(order)
|
|
140
|
+
)}">${escapeHtml(member.title)}</a></li>`
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
parts.push("</ol></section>");
|
|
144
|
+
return parts.join("");
|
|
145
|
+
}
|
|
146
|
+
function collectSeriesDiagnostics(manifest, options = {}) {
|
|
147
|
+
const resolved = resolveSeriesOptions(options);
|
|
148
|
+
const diagnostics = [];
|
|
149
|
+
const firstByOrder = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const entry of manifest.entries) {
|
|
151
|
+
if (!hasFrontmatterKey(entry, resolved.key)) continue;
|
|
152
|
+
const name = readSeriesName(entry, resolved.key);
|
|
153
|
+
if (!name) {
|
|
154
|
+
diagnostics.push({
|
|
155
|
+
code: "series-invalid-name",
|
|
156
|
+
severity: "warning",
|
|
157
|
+
pluginName: "series",
|
|
158
|
+
slug: entry.slug,
|
|
159
|
+
message: `Frontmatter \`${resolved.key}\` must be a non-empty string.`
|
|
160
|
+
});
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const order = readSeriesOrder(entry, resolved.orderKey);
|
|
164
|
+
if (order === void 0) {
|
|
165
|
+
diagnostics.push({
|
|
166
|
+
code: "series-missing-order",
|
|
167
|
+
severity: "warning",
|
|
168
|
+
pluginName: "series",
|
|
169
|
+
slug: entry.slug,
|
|
170
|
+
message: `Note in series \`${name}\` has no numeric \`${resolved.orderKey}\`; it is ordered by date, title, then slug.`,
|
|
171
|
+
meta: { series: name }
|
|
172
|
+
});
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const orderKey = `${name}\0${order}`;
|
|
176
|
+
const first = firstByOrder.get(orderKey);
|
|
177
|
+
if (first) {
|
|
178
|
+
diagnostics.push({
|
|
179
|
+
code: "series-duplicate-order",
|
|
180
|
+
severity: "warning",
|
|
181
|
+
pluginName: "series",
|
|
182
|
+
slug: entry.slug,
|
|
183
|
+
message: `Series \`${name}\` has more than one note with \`${resolved.orderKey}: ${order}\` (also in \`${first.slug}\`).`,
|
|
184
|
+
meta: { series: name, order }
|
|
185
|
+
});
|
|
186
|
+
} else {
|
|
187
|
+
firstByOrder.set(orderKey, entry);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return diagnostics;
|
|
191
|
+
}
|
|
192
|
+
function toMember(manifest, entry, resolved, name) {
|
|
193
|
+
return {
|
|
194
|
+
slug: entry.slug,
|
|
195
|
+
title: entry.title || entry.slug,
|
|
196
|
+
permalink: manifest.bySlug.get(entry.slug)?.permalink ?? entry.permalink,
|
|
197
|
+
order: readSeriesOrder(entry, resolved.orderKey) ?? null,
|
|
198
|
+
series: name
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
function compareEntries(a, b, resolved) {
|
|
202
|
+
const orderA = readSeriesOrder(a, resolved.orderKey) ?? Number.POSITIVE_INFINITY;
|
|
203
|
+
const orderB = readSeriesOrder(b, resolved.orderKey) ?? Number.POSITIVE_INFINITY;
|
|
204
|
+
if (orderA !== orderB) return orderA < orderB ? -1 : 1;
|
|
205
|
+
const dateA = readSeriesDate(a) ?? Number.POSITIVE_INFINITY;
|
|
206
|
+
const dateB = readSeriesDate(b) ?? Number.POSITIVE_INFINITY;
|
|
207
|
+
if (dateA !== dateB) return dateA < dateB ? -1 : 1;
|
|
208
|
+
if (a.title !== b.title) return a.title < b.title ? -1 : 1;
|
|
209
|
+
if (a.slug !== b.slug) return a.slug < b.slug ? -1 : 1;
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
function readSeriesName(entry, key) {
|
|
213
|
+
return readString(entry, key);
|
|
214
|
+
}
|
|
215
|
+
function readSeriesOrder(entry, key) {
|
|
216
|
+
const value = entry.frontmatter[key];
|
|
217
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
function readString(entry, key) {
|
|
221
|
+
const value = entry.frontmatter[key];
|
|
222
|
+
if (typeof value !== "string") return void 0;
|
|
223
|
+
const trimmed = value.trim();
|
|
224
|
+
return trimmed === "" ? void 0 : trimmed;
|
|
225
|
+
}
|
|
226
|
+
function readSeriesDate(entry) {
|
|
227
|
+
for (const key of ["date", "created", "published"]) {
|
|
228
|
+
const time = parseDate(entry.frontmatter[key]);
|
|
229
|
+
if (time !== void 0) return time;
|
|
230
|
+
}
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
function parseDate(value) {
|
|
234
|
+
if (value instanceof Date) {
|
|
235
|
+
const time = value.getTime();
|
|
236
|
+
return Number.isFinite(time) ? time : void 0;
|
|
237
|
+
}
|
|
238
|
+
if (typeof value === "string") {
|
|
239
|
+
const time = Date.parse(value);
|
|
240
|
+
return Number.isNaN(time) ? void 0 : time;
|
|
241
|
+
}
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
function hasFrontmatterKey(entry, key) {
|
|
245
|
+
return Object.hasOwn(entry.frontmatter, key);
|
|
246
|
+
}
|
|
247
|
+
function formatPosition(position, total) {
|
|
248
|
+
return `Part ${position} of ${total}`;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// index.ts
|
|
252
|
+
function series(options = {}) {
|
|
253
|
+
const tracked = /* @__PURE__ */ new Map();
|
|
254
|
+
return definePlugin({
|
|
255
|
+
name: "series",
|
|
256
|
+
options,
|
|
257
|
+
validateOptions: validateSeriesOptions,
|
|
258
|
+
onPostProcessed: ({ slug, content }) => {
|
|
259
|
+
tracked.set(slug, content);
|
|
260
|
+
},
|
|
261
|
+
onManifestCreated: ({ manifest, diagnostics }) => {
|
|
262
|
+
diagnostics.push(...collectSeriesDiagnostics(manifest, options));
|
|
263
|
+
const injected = /* @__PURE__ */ new Set();
|
|
264
|
+
for (const index of collectSeriesIndexes(manifest, options)) {
|
|
265
|
+
if (index.members.length < 2) continue;
|
|
266
|
+
for (const member of index.members) {
|
|
267
|
+
if (injected.has(member.slug)) continue;
|
|
268
|
+
const entry = manifest.bySlug.get(member.slug);
|
|
269
|
+
if (!entry) continue;
|
|
270
|
+
injected.add(member.slug);
|
|
271
|
+
const navigation = renderSeriesNavigation(index, member.slug, options);
|
|
272
|
+
entry.html = `${entry.html}
|
|
273
|
+
${navigation}`;
|
|
274
|
+
const content = tracked.get(member.slug);
|
|
275
|
+
if (content) content.html = entry.html;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
assets: [createStyleAsset("series")]
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
var seriesPlugin = series;
|
|
283
|
+
function validateSeriesOptions(options) {
|
|
284
|
+
if (!options) return [];
|
|
285
|
+
const issues = [];
|
|
286
|
+
for (const key of ["key", "orderKey", "titleKey", "className"]) {
|
|
287
|
+
const value = options[key];
|
|
288
|
+
if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
|
|
289
|
+
issues.push({ path: key, message: "Expected a non-empty string." });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
for (const key of ["heading", "positionLabel"]) {
|
|
293
|
+
if (options[key] !== void 0 && typeof options[key] !== "boolean") {
|
|
294
|
+
issues.push({ path: key, message: "Expected a boolean." });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return issues;
|
|
298
|
+
}
|
|
299
|
+
var DEFAULT_CLASS_NAME = resolveSeriesOptions({}).className;
|
|
300
|
+
export {
|
|
301
|
+
DEFAULT_CLASS_NAME,
|
|
302
|
+
buildSeriesIndex,
|
|
303
|
+
collectSeriesIndexes,
|
|
304
|
+
renderSeriesIndex,
|
|
305
|
+
renderSeriesNavigation,
|
|
306
|
+
resolveSeriesOptions,
|
|
307
|
+
series,
|
|
308
|
+
seriesPlugin
|
|
309
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ContentManifest, type Diagnostic } from "@riebeckite/core";
|
|
2
|
+
import type { ResolvedSeriesOptions, SeriesIndex, SeriesOptions } from "./types.js";
|
|
3
|
+
/** Base class applied when `options.className` is not set. */
|
|
4
|
+
export declare const DEFAULT_SERIES_CLASS_NAME = "rb-series";
|
|
5
|
+
/** Applies defaults to the user-supplied options. */
|
|
6
|
+
export declare function resolveSeriesOptions(options?: SeriesOptions): ResolvedSeriesOptions;
|
|
7
|
+
/**
|
|
8
|
+
* Groups every manifest entry that declares a series and returns one
|
|
9
|
+
* `SeriesIndex` per series, in first-seen order. Members are sorted by
|
|
10
|
+
* `orderKey`, then the `date`/`created`/`published` frontmatter value, then
|
|
11
|
+
* `title`, then `slug`, so ties resolve deterministically.
|
|
12
|
+
*/
|
|
13
|
+
export declare function collectSeriesIndexes(manifest: ContentManifest, options?: SeriesOptions): SeriesIndex[];
|
|
14
|
+
/** Returns a single series index, or `null` when no note declares `name`. */
|
|
15
|
+
export declare function buildSeriesIndex(manifest: ContentManifest, name: string, options?: SeriesOptions): SeriesIndex | null;
|
|
16
|
+
/**
|
|
17
|
+
* Renders the navigation block that is appended to each note in a series.
|
|
18
|
+
* `currentSlug` marks the active part with `aria-current="page"` and drives the
|
|
19
|
+
* previous/next links.
|
|
20
|
+
*/
|
|
21
|
+
export declare function renderSeriesNavigation(index: SeriesIndex, currentSlug: string, options?: SeriesOptions): string;
|
|
22
|
+
/**
|
|
23
|
+
* Renders a complete series as a standalone block, suitable for a landing page.
|
|
24
|
+
* Returns an empty string when the manifest has no member for `name`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function renderSeriesIndex(manifest: ContentManifest, name: string, options?: SeriesOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* Reports notes whose series metadata cannot be ordered reliably. Emitted
|
|
29
|
+
* diagnostics use `pluginName: "series"` and `severity: "warning"`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function collectSeriesDiagnostics(manifest: ContentManifest, options?: SeriesOptions): Diagnostic[];
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Public options accepted by the `series()` plugin factory. */
|
|
2
|
+
export type SeriesOptions = {
|
|
3
|
+
/** Frontmatter key that names the series. Defaults to `"series"`. */
|
|
4
|
+
key?: string;
|
|
5
|
+
/** Frontmatter key that holds the numeric order. Defaults to `"series_order"`. */
|
|
6
|
+
orderKey?: string;
|
|
7
|
+
/** Frontmatter key that overrides the displayed series title. Defaults to `"series_title"`. */
|
|
8
|
+
titleKey?: string;
|
|
9
|
+
/** Render the series heading above the part list. Defaults to `true`. */
|
|
10
|
+
heading?: boolean;
|
|
11
|
+
/** Base CSS class prefix. Defaults to `"rb-series"`. */
|
|
12
|
+
className?: string;
|
|
13
|
+
/** Render a `Part N of M` label for the current note. Defaults to `false`. */
|
|
14
|
+
positionLabel?: boolean;
|
|
15
|
+
};
|
|
16
|
+
/** Options after defaults have been applied. */
|
|
17
|
+
export type ResolvedSeriesOptions = {
|
|
18
|
+
key: string;
|
|
19
|
+
orderKey: string;
|
|
20
|
+
titleKey: string;
|
|
21
|
+
heading: boolean;
|
|
22
|
+
className: string;
|
|
23
|
+
positionLabel: boolean;
|
|
24
|
+
};
|
|
25
|
+
/** A single note that belongs to a series. */
|
|
26
|
+
export type SeriesMember = {
|
|
27
|
+
slug: string;
|
|
28
|
+
title: string;
|
|
29
|
+
permalink: string;
|
|
30
|
+
/** Numeric `orderKey` value, or `null` when it was missing or invalid. */
|
|
31
|
+
order: number | null;
|
|
32
|
+
/** The series name exactly as written in frontmatter. */
|
|
33
|
+
series: string;
|
|
34
|
+
};
|
|
35
|
+
/** An ordered series and all of its members. */
|
|
36
|
+
export type SeriesIndex = {
|
|
37
|
+
/** Series name from frontmatter (used as the grouping key). */
|
|
38
|
+
name: string;
|
|
39
|
+
/** Display title: the first `titleKey` value, or `name` when absent. */
|
|
40
|
+
title: string;
|
|
41
|
+
/** Members sorted by `order`, then date, title, and slug. */
|
|
42
|
+
members: SeriesMember[];
|
|
43
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-series",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
"./style.css": "./style.css"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@riebeckite/core": "0.0.1"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"LICENSE",
|
|
25
|
+
"README.md",
|
|
26
|
+
"README_ja.md",
|
|
27
|
+
"dist",
|
|
28
|
+
"style.css"
|
|
29
|
+
],
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
33
|
+
"directory": "packages/plugins/series"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
38
|
+
},
|
|
39
|
+
"description": "Ordered multi-part post navigation for Riebeckite.",
|
|
40
|
+
"keywords": [
|
|
41
|
+
"riebeckite",
|
|
42
|
+
"plugin",
|
|
43
|
+
"series",
|
|
44
|
+
"navigation"
|
|
45
|
+
],
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
48
|
+
},
|
|
49
|
+
"sideEffects": [
|
|
50
|
+
"./style.css"
|
|
51
|
+
],
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "node ../../../scripts/build_package.mjs"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
.rb-series {
|
|
2
|
+
--rb-series-paper: var(--rb-color-paper, #ffffff);
|
|
3
|
+
--rb-series-ink: var(--rb-color-ink, #1a1a1a);
|
|
4
|
+
--rb-series-muted: var(--rb-color-muted, #69645c);
|
|
5
|
+
--rb-series-rule: var(
|
|
6
|
+
--rb-color-border,
|
|
7
|
+
color-mix(in srgb, var(--rb-series-ink) 16%, transparent)
|
|
8
|
+
);
|
|
9
|
+
--rb-series-accent: var(--rb-color-accent, #b4471f);
|
|
10
|
+
margin: 2rem 0;
|
|
11
|
+
padding: 1rem 1.25rem;
|
|
12
|
+
border: 1px solid var(--rb-series-rule);
|
|
13
|
+
background: color-mix(
|
|
14
|
+
in srgb,
|
|
15
|
+
var(--rb-series-paper) 97%,
|
|
16
|
+
var(--rb-series-ink)
|
|
17
|
+
);
|
|
18
|
+
color: var(--rb-series-ink);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.rb-series__title {
|
|
22
|
+
margin: 0 0 0.75rem;
|
|
23
|
+
font-size: 0.9375rem;
|
|
24
|
+
font-weight: 600;
|
|
25
|
+
letter-spacing: 0.02em;
|
|
26
|
+
text-transform: uppercase;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.rb-series__title a,
|
|
30
|
+
.rb-series__list a {
|
|
31
|
+
color: inherit;
|
|
32
|
+
text-decoration: none;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.rb-series__title a:hover,
|
|
36
|
+
.rb-series__list a:hover {
|
|
37
|
+
text-decoration: underline;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.rb-series__position {
|
|
41
|
+
margin-left: 0.5rem;
|
|
42
|
+
color: var(--rb-series-muted);
|
|
43
|
+
font-size: 0.75rem;
|
|
44
|
+
font-weight: 400;
|
|
45
|
+
letter-spacing: 0;
|
|
46
|
+
text-transform: none;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.rb-series__list {
|
|
50
|
+
margin: 0;
|
|
51
|
+
padding-left: 1.25rem;
|
|
52
|
+
color: var(--rb-series-ink);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rb-series__item {
|
|
56
|
+
margin: 0.25rem 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.rb-series__item a[aria-current="page"] {
|
|
60
|
+
color: var(--rb-series-accent);
|
|
61
|
+
font-weight: 600;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.rb-series__nav {
|
|
65
|
+
display: flex;
|
|
66
|
+
gap: 1rem;
|
|
67
|
+
justify-content: space-between;
|
|
68
|
+
margin-top: 0.75rem;
|
|
69
|
+
padding-top: 0.75rem;
|
|
70
|
+
border-top: 1px solid var(--rb-series-rule);
|
|
71
|
+
font-size: 0.875rem;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.rb-series__prev,
|
|
75
|
+
.rb-series__next {
|
|
76
|
+
color: var(--rb-series-accent);
|
|
77
|
+
text-decoration: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.rb-series__prev:hover,
|
|
81
|
+
.rb-series__next:hover {
|
|
82
|
+
text-decoration: underline;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.rb-series--index {
|
|
86
|
+
margin: 2rem 0;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.rb-series--index .rb-series__title {
|
|
90
|
+
text-transform: none;
|
|
91
|
+
}
|