@riebeckite/plugin-taxonomy 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +227 -0
- package/README_ja.md +225 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +675 -0
- package/dist/src/collections.d.ts +17 -0
- package/dist/src/feeds.d.ts +10 -0
- package/dist/src/locations.d.ts +14 -0
- package/dist/src/options.d.ts +13 -0
- package/dist/src/pages.d.ts +9 -0
- package/dist/src/seo.d.ts +11 -0
- package/dist/src/slug.d.ts +10 -0
- package/dist/src/types.d.ts +145 -0
- package/dist/src/url.d.ts +7 -0
- package/dist/src/xml.d.ts +1 -0
- package/package.json +60 -0
- package/style.css +107 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright Rerurate_514
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# @riebeckite/plugin-taxonomy
|
|
2
|
+
|
|
3
|
+
Build-time tag and folder taxonomy for Riebeckite: listing data, per-term
|
|
4
|
+
RSS / Atom / JSON feeds, related-tag navigation, and SEO metadata. No
|
|
5
|
+
client-side JavaScript is required.
|
|
6
|
+
|
|
7
|
+
[日本語](./README_ja.md)
|
|
8
|
+
|
|
9
|
+
## Overview
|
|
10
|
+
|
|
11
|
+
`taxonomy()` reads the manifest's public entries and produces two sets of
|
|
12
|
+
listing terms with the Core collection contract (`buildContentCollections`):
|
|
13
|
+
|
|
14
|
+
- **Tag terms** group by `tags` under `/tags/<slug>`.
|
|
15
|
+
- **Folder terms** group by folder under `/folders/<path>`.
|
|
16
|
+
|
|
17
|
+
Entries always link through their resolved `permalink`; the plugin never
|
|
18
|
+
reconstructs a URL from a slug.
|
|
19
|
+
|
|
20
|
+
The plugin owns data, feeds, and SEO only. It deliberately does **not** register
|
|
21
|
+
application routes. Per-term feeds are written as static files through the
|
|
22
|
+
build's generated-output sink, and an app renders `/tags/<tag>` and
|
|
23
|
+
`/folders/<path>` from the exported helpers (see
|
|
24
|
+
[App-route wiring](#app-route-wiring)).
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { defineConfig } from "@riebeckite/core";
|
|
30
|
+
import { taxonomy } from "@riebeckite/plugin-taxonomy";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
// ...
|
|
34
|
+
plugins: [
|
|
35
|
+
taxonomy({
|
|
36
|
+
tags: true,
|
|
37
|
+
folders: true,
|
|
38
|
+
related: true,
|
|
39
|
+
folderIndexes: true,
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
| ------ | ---- | ------- | ----------- |
|
|
49
|
+
| `tags` | `boolean` | `true` | Generate tag terms |
|
|
50
|
+
| `folders` | `boolean` | `true` | Generate folder terms |
|
|
51
|
+
| `tagsBasePath` | `string` | `"/tags"` | Tag listing prefix |
|
|
52
|
+
| `foldersBasePath` | `string` | `"/folders"` | Folder listing prefix |
|
|
53
|
+
| `folderDepth` | `number` | `0` | Folder grouping depth; `0` keeps the full path |
|
|
54
|
+
| `minEntries` | `number` | `1` | Drop terms with fewer entries |
|
|
55
|
+
| `related` | `boolean` | `true` | Compute related-tag navigation |
|
|
56
|
+
| `relatedLimit` | `number` | `8` | Maximum related tags per tag |
|
|
57
|
+
| `folderIndexes` | `boolean` | `false` | Resolve `<folder>/index.md` to `/<folder>` |
|
|
58
|
+
| `feeds` | `{ rss?, atom?, json? }` | all `true` | Per-term feed formats |
|
|
59
|
+
| `feedLimit` | `number` | `50` | Maximum entries per feed |
|
|
60
|
+
| `resolveTitle` | `(context) => string` | `#value` / path | Custom term title |
|
|
61
|
+
| `className` | `string` | `"rr-taxonomy"` | Root CSS class of page fragments |
|
|
62
|
+
| `dataEndpoint` | `string` | `"/taxonomy/index.json"` | JSON data endpoint path |
|
|
63
|
+
|
|
64
|
+
## Data endpoint
|
|
65
|
+
|
|
66
|
+
The plugin registers one JSON endpoint (the endpoint contract is mounted by the
|
|
67
|
+
HonoX integration, so it never contains framework routing itself):
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
GET /taxonomy/index.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"tags": [
|
|
76
|
+
{
|
|
77
|
+
"kind": "tag",
|
|
78
|
+
"value": "featured",
|
|
79
|
+
"title": "#featured",
|
|
80
|
+
"path": "/tags/featured",
|
|
81
|
+
"permalink": "/tags/featured",
|
|
82
|
+
"count": 1,
|
|
83
|
+
"entries": [{ "slug": "example", "permalink": "/notes/example", "title": "Example Note", "updated": null, "summary": "..." }],
|
|
84
|
+
"related": [],
|
|
85
|
+
"feeds": { "rss": "/tags/featured/feed.xml", "atom": "/tags/featured/atom.xml", "json": "/tags/featured/feed.json" }
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"folders": []
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The payload is a deterministic, JSON-safe projection: it never includes rendered
|
|
93
|
+
HTML, so it is safe to ship to an app route or a browser.
|
|
94
|
+
|
|
95
|
+
## Generated feeds
|
|
96
|
+
|
|
97
|
+
At build time the plugin emits one feed per term and format through
|
|
98
|
+
`context.output.emit`:
|
|
99
|
+
|
|
100
|
+
| Format | Path |
|
|
101
|
+
| ------ | ---- |
|
|
102
|
+
| RSS 2.0 | `/tags/<slug>/feed.xml` |
|
|
103
|
+
| Atom | `/tags/<slug>/atom.xml` |
|
|
104
|
+
| JSON Feed 1.1 | `/tags/<slug>/feed.json` |
|
|
105
|
+
|
|
106
|
+
Folder terms get the same files under `/folders/<path>/…`. Feed channels carry
|
|
107
|
+
their own term title and self link, so a tag subscription is distinguishable
|
|
108
|
+
from the site-wide feeds owned by `@riebeckite/plugin-seo`. Only published,
|
|
109
|
+
non-`noindex` entries reach the manifest's public view and therefore the feeds.
|
|
110
|
+
|
|
111
|
+
## Related tags
|
|
112
|
+
|
|
113
|
+
When `related` is enabled, each tag term carries tags that co-occur on the same
|
|
114
|
+
entries, ranked by shared-entry count then alphabetically, clamped to
|
|
115
|
+
`relatedLimit`. Related navigation is rendered by `renderTaxonomyPage`:
|
|
116
|
+
|
|
117
|
+
```html
|
|
118
|
+
<nav class="rr-taxonomy__related" aria-label="Related tags" data-rr-taxonomy-related>
|
|
119
|
+
<ul>
|
|
120
|
+
<li class="rr-taxonomy__related-item">
|
|
121
|
+
<a class="rr-taxonomy__related-link" href="/tags/featured" data-rr-taxonomy-related-count="2">#featured</a>
|
|
122
|
+
</li>
|
|
123
|
+
</ul>
|
|
124
|
+
</nav>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## SEO
|
|
128
|
+
|
|
129
|
+
`buildTaxonomySeo(config, term)` returns `SeoMetadata` for a listing page. It
|
|
130
|
+
delegates to the configured Core `seo` extension point (for example
|
|
131
|
+
`@riebeckite/plugin-seo`) so titles, canonical URLs, and JSON-LD stay consistent
|
|
132
|
+
with the rest of the site, and falls back to a minimal object when no SEO
|
|
133
|
+
provider is registered.
|
|
134
|
+
|
|
135
|
+
## Folder index notes
|
|
136
|
+
|
|
137
|
+
With `folderIndexes: true`, the plugin's `resolveContentLocations` hook maps a
|
|
138
|
+
note at `<folder>/index.md` to `/<folder>` instead of `/<folder>/index`. The
|
|
139
|
+
chosen permalink is recorded as `metadata["taxonomy.folder"]`. A location is
|
|
140
|
+
never claimed when another note already owns it; the conflict is reported as a
|
|
141
|
+
diagnostic instead.
|
|
142
|
+
|
|
143
|
+
## App-route wiring
|
|
144
|
+
|
|
145
|
+
The application owns routing. Register the listing paths in the app and render
|
|
146
|
+
them from the plugin's data:
|
|
147
|
+
|
|
148
|
+
```tsx
|
|
149
|
+
// app/routes/tags/[slug{.+}].tsx
|
|
150
|
+
import { ssgParams } from "hono/ssg";
|
|
151
|
+
import { createRoute } from "honox/factory";
|
|
152
|
+
import {
|
|
153
|
+
buildTaxonomyIndex,
|
|
154
|
+
buildTaxonomySeo,
|
|
155
|
+
renderTaxonomyPage,
|
|
156
|
+
resolveTaxonomyOptionsFromConfig,
|
|
157
|
+
} from "@riebeckite/plugin-taxonomy";
|
|
158
|
+
import Article from "../../components/article/article";
|
|
159
|
+
import { config } from "../../config";
|
|
160
|
+
import { content } from "../../content";
|
|
161
|
+
|
|
162
|
+
export default createRoute(
|
|
163
|
+
ssgParams(async () => {
|
|
164
|
+
const options = resolveTaxonomyOptionsFromConfig(config);
|
|
165
|
+
const manifest = await content.getManifest();
|
|
166
|
+
return buildTaxonomyIndex(manifest.publicEntries, options).tags.map(
|
|
167
|
+
(term) => ({ slug: term.path.replace(/^\/tags\//, "") }),
|
|
168
|
+
);
|
|
169
|
+
}),
|
|
170
|
+
async (c) => {
|
|
171
|
+
const options = resolveTaxonomyOptionsFromConfig(config);
|
|
172
|
+
const manifest = await content.getManifest();
|
|
173
|
+
const term = buildTaxonomyIndex(manifest.publicEntries, options).tags.find(
|
|
174
|
+
(candidate) => candidate.path === c.req.path,
|
|
175
|
+
);
|
|
176
|
+
c.set("seo", term ? buildTaxonomySeo(config, term) : undefined);
|
|
177
|
+
if (!term) return c.notFound();
|
|
178
|
+
const page = renderTaxonomyPage(term, options);
|
|
179
|
+
c.set("headTags", page.headTags);
|
|
180
|
+
return c.render(<Article content={page} />);
|
|
181
|
+
},
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
A folder route follows the same shape with `.folders` and `/folders/`. The
|
|
186
|
+
`renderTaxonomyPage` result is `PostContent`-compatible (`frontmatter` + `html`),
|
|
187
|
+
so it drops into the reference `Article` primitive; `headTags` adds the feed
|
|
188
|
+
discovery `<link rel="alternate">` elements to the document head.
|
|
189
|
+
|
|
190
|
+
## Style
|
|
191
|
+
|
|
192
|
+
The package ships `style.css` with the stable `rr-taxonomy` root hook and
|
|
193
|
+
`--rr-taxonomy-*` tokens (falling back to `--rb-*`). Register it like any other
|
|
194
|
+
plugin stylesheet:
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
import "@riebeckite/plugin-taxonomy/style.css";
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Exports
|
|
201
|
+
|
|
202
|
+
- `taxonomy(options?)` — plugin factory
|
|
203
|
+
- `taxonomyPlugin` — alias of `taxonomy`
|
|
204
|
+
- `resolveTaxonomyOptions(options?)` — apply option defaults
|
|
205
|
+
- `resolveTaxonomyOptionsFromConfig(config)` — read resolved options back from a config
|
|
206
|
+
- `buildTaxonomyIndex(entries, options)` — build tag and folder terms
|
|
207
|
+
- `serializeTaxonomyIndex(index)` / `serializeTaxonomyTerm(term)` — JSON-safe projections
|
|
208
|
+
- `renderTaxonomyPage(term, options)` / `renderRelatedTerms(term, options)` — page fragments
|
|
209
|
+
- `renderTermFeed(config, term, format, limit?)` / `buildFeedHeadTags(term)` — per-term feeds
|
|
210
|
+
- `buildTaxonomySeo(config, term)` — listing-page SEO metadata
|
|
211
|
+
- `resolveFolderIndexLocations(entries, options, diagnostics)` — folder-index location strategy
|
|
212
|
+
- `slugifyTaxonomyValue(value)` — URL/file slug
|
|
213
|
+
- `buildTaxonomyAbsoluteUrl(config, pathOrUrl)` — absolute URLs
|
|
214
|
+
- Types: `TaxonomyOptions`, `ResolvedTaxonomyOptions`, `TaxonomyTerm`, `TaxonomyIndex`, `TaxonomyPage`, `TaxonomyTermData`, `TaxonomyIndexData`
|
|
215
|
+
|
|
216
|
+
## Limitations
|
|
217
|
+
|
|
218
|
+
- Taxonomy is fixed at build time. A full rebuild always recomputes correctly.
|
|
219
|
+
- Per-term feeds are static build output; the fixed JSON data endpoint is the
|
|
220
|
+
only runtime surface. A dev server does not enumerate per-term feed files.
|
|
221
|
+
- Terms only reflect the manifest's public view; unpublished or `noindex`
|
|
222
|
+
entries are excluded.
|
|
223
|
+
|
|
224
|
+
## See also
|
|
225
|
+
|
|
226
|
+
- [Plugin guide](../../../docs/en/plugin-system.md)
|
|
227
|
+
- [Content system](../../../docs/en/content-system.md)
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# @riebeckite/plugin-taxonomy
|
|
2
|
+
|
|
3
|
+
Riebeckite のビルド時タクソノミー(タグ・フォルダ)プラグインです。一覧用データ、
|
|
4
|
+
語ごとの RSS / Atom / JSON フィード、関連タグナビゲーション、SEO メタデータを
|
|
5
|
+
生成します。クライアント JavaScript は不要です。
|
|
6
|
+
|
|
7
|
+
[English](./README.md)
|
|
8
|
+
|
|
9
|
+
## 概要
|
|
10
|
+
|
|
11
|
+
`taxonomy()` はマニフェストの公開エントリを読み、Core の collection contract
|
|
12
|
+
(`buildContentCollections`)で 2 種類の一覧語を生成します。
|
|
13
|
+
|
|
14
|
+
- **タグ**: `tags` でグルーピングし `/tags/<slug>` に配置します。
|
|
15
|
+
- **フォルダ**: フォルダでグルーピングし `/folders/<path>` に配置します。
|
|
16
|
+
|
|
17
|
+
エントリのリンクには常に解決済みの `permalink` を使い、slug から URL を組み立てる
|
|
18
|
+
ことはありません。
|
|
19
|
+
|
|
20
|
+
このプラグインが持つのはデータ・フィード・SEO だけです。アプリケーションの
|
|
21
|
+
ルートは登録しません。語ごとのフィードはビルドの generated-output sink 経由で
|
|
22
|
+
静的ファイルとして出力し、`/tags/<tag>` と `/folders/<path>` のページは
|
|
23
|
+
エクスポートしたヘルパーを使ってアプリ側で描画します
|
|
24
|
+
([アプリルートの配線](#アプリルートの配線) を参照)。
|
|
25
|
+
|
|
26
|
+
## 使い方
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { defineConfig } from "@riebeckite/core";
|
|
30
|
+
import { taxonomy } from "@riebeckite/plugin-taxonomy";
|
|
31
|
+
|
|
32
|
+
export default defineConfig({
|
|
33
|
+
// ...
|
|
34
|
+
plugins: [
|
|
35
|
+
taxonomy({
|
|
36
|
+
tags: true,
|
|
37
|
+
folders: true,
|
|
38
|
+
related: true,
|
|
39
|
+
folderIndexes: true,
|
|
40
|
+
}),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## オプション
|
|
46
|
+
|
|
47
|
+
| オプション | 型 | 既定値 | 説明 |
|
|
48
|
+
| ---------- | -- | ------ | ---- |
|
|
49
|
+
| `tags` | `boolean` | `true` | タグ語を生成する |
|
|
50
|
+
| `folders` | `boolean` | `true` | フォルダ語を生成する |
|
|
51
|
+
| `tagsBasePath` | `string` | `"/tags"` | タグ一覧のパス接頭辞 |
|
|
52
|
+
| `foldersBasePath` | `string` | `"/folders"` | フォルダ一覧のパス接頭辞 |
|
|
53
|
+
| `folderDepth` | `number` | `0` | フォルダのグルーピング深さ。`0` は完全パス |
|
|
54
|
+
| `minEntries` | `number` | `1` | これ未満のエントリ数しかない語を除外する |
|
|
55
|
+
| `related` | `boolean` | `true` | 関連タグナビゲーションを生成する |
|
|
56
|
+
| `relatedLimit` | `number` | `8` | タグごとの関連タグ上限 |
|
|
57
|
+
| `folderIndexes` | `boolean` | `false` | `<folder>/index.md` を `/<folder>` に解決する |
|
|
58
|
+
| `feeds` | `{ rss?, atom?, json? }` | すべて `true` | 語ごとのフィード形式 |
|
|
59
|
+
| `feedLimit` | `number` | `50` | フィードあたりの最大エントリ数 |
|
|
60
|
+
| `resolveTitle` | `(context) => string` | `#value` / パス | 語の表示タイトル |
|
|
61
|
+
| `className` | `string` | `"rr-taxonomy"` | ページ断片のルート CSS クラス |
|
|
62
|
+
| `dataEndpoint` | `string` | `"/taxonomy/index.json"` | JSON データのエンドポイント |
|
|
63
|
+
|
|
64
|
+
## データエンドポイント
|
|
65
|
+
|
|
66
|
+
プラグインは JSON エンドポイントを 1 つ登録します(endpoint contract は HonoX
|
|
67
|
+
integration が接続するため、プラグイン自身は framework のルーティングを持ちません)。
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
GET /taxonomy/index.json
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"tags": [
|
|
76
|
+
{
|
|
77
|
+
"kind": "tag",
|
|
78
|
+
"value": "featured",
|
|
79
|
+
"title": "#featured",
|
|
80
|
+
"path": "/tags/featured",
|
|
81
|
+
"permalink": "/tags/featured",
|
|
82
|
+
"count": 1,
|
|
83
|
+
"entries": [{ "slug": "example", "permalink": "/notes/example", "title": "Example Note", "updated": null, "summary": "..." }],
|
|
84
|
+
"related": [],
|
|
85
|
+
"feeds": { "rss": "/tags/featured/feed.xml", "atom": "/tags/featured/atom.xml", "json": "/tags/featured/feed.json" }
|
|
86
|
+
}
|
|
87
|
+
],
|
|
88
|
+
"folders": []
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
ペイロードは決定的で JSON 安全な射影です。描画済み HTML を含まないため、アプリの
|
|
93
|
+
ルートやブラウザへそのまま渡せます。
|
|
94
|
+
|
|
95
|
+
## 生成されるフィード
|
|
96
|
+
|
|
97
|
+
ビルド時に、語と形式ごとに 1 つのフィードを `context.output.emit` で出力します。
|
|
98
|
+
|
|
99
|
+
| 形式 | パス |
|
|
100
|
+
| ---- | ---- |
|
|
101
|
+
| RSS 2.0 | `/tags/<slug>/feed.xml` |
|
|
102
|
+
| Atom | `/tags/<slug>/atom.xml` |
|
|
103
|
+
| JSON Feed 1.1 | `/tags/<slug>/feed.json` |
|
|
104
|
+
|
|
105
|
+
フォルダ語も同じファイルを `/folders/<path>/…` に持ちます。フィードの channel は
|
|
106
|
+
語ごとのタイトルと self link を持つため、タグの購読と
|
|
107
|
+
`@riebeckite/plugin-seo` が持つサイト全体のフィードを区別できます。公開かつ
|
|
108
|
+
`noindex` でないエントリだけがマニフェストの公開ビューに入り、フィードへ届きます。
|
|
109
|
+
|
|
110
|
+
## 関連タグ
|
|
111
|
+
|
|
112
|
+
`related` が有効なとき、各タグ語は同じエントリに共起するタグを保持します。共起
|
|
113
|
+
エントリ数で降順、同数ならアルファベット順に並べ、`relatedLimit` で打ち切ります。
|
|
114
|
+
ナビゲーションは `renderTaxonomyPage` が描画します。
|
|
115
|
+
|
|
116
|
+
```html
|
|
117
|
+
<nav class="rr-taxonomy__related" aria-label="Related tags" data-rr-taxonomy-related>
|
|
118
|
+
<ul>
|
|
119
|
+
<li class="rr-taxonomy__related-item">
|
|
120
|
+
<a class="rr-taxonomy__related-link" href="/tags/featured" data-rr-taxonomy-related-count="2">#featured</a>
|
|
121
|
+
</li>
|
|
122
|
+
</ul>
|
|
123
|
+
</nav>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## SEO
|
|
127
|
+
|
|
128
|
+
`buildTaxonomySeo(config, term)` は一覧ページの `SeoMetadata` を返します。設定済みの
|
|
129
|
+
Core `seo` 拡張ポイント(たとえば `@riebeckite/plugin-seo`)へ委譲するため、
|
|
130
|
+
タイトル・canonical URL・JSON-LD がサイト全体と揃います。SEO プロバイダーが無い
|
|
131
|
+
場合は最小限のオブジェクトへフォールバックします。
|
|
132
|
+
|
|
133
|
+
## フォルダ index note
|
|
134
|
+
|
|
135
|
+
`folderIndexes: true` のとき、プラグインの `resolveContentLocations` フックが
|
|
136
|
+
`<folder>/index.md` のノートを `/<folder>/index` ではなく `/<folder>` に解決します。
|
|
137
|
+
選ばれた permalink は `metadata["taxonomy.folder"]` に記録されます。すでに他の
|
|
138
|
+
ノートが所有している location は決して奪わず、衝突は診断として報告します。
|
|
139
|
+
|
|
140
|
+
## アプリルートの配線
|
|
141
|
+
|
|
142
|
+
ルーティングはアプリケーションが所有します。一覧パスをアプリに登録し、プラグインの
|
|
143
|
+
データから描画してください。
|
|
144
|
+
|
|
145
|
+
```tsx
|
|
146
|
+
// app/routes/tags/[slug{.+}].tsx
|
|
147
|
+
import { ssgParams } from "hono/ssg";
|
|
148
|
+
import { createRoute } from "honox/factory";
|
|
149
|
+
import {
|
|
150
|
+
buildTaxonomyIndex,
|
|
151
|
+
buildTaxonomySeo,
|
|
152
|
+
renderTaxonomyPage,
|
|
153
|
+
resolveTaxonomyOptionsFromConfig,
|
|
154
|
+
} from "@riebeckite/plugin-taxonomy";
|
|
155
|
+
import Article from "../../components/article/article";
|
|
156
|
+
import { config } from "../../config";
|
|
157
|
+
import { content } from "../../content";
|
|
158
|
+
|
|
159
|
+
export default createRoute(
|
|
160
|
+
ssgParams(async () => {
|
|
161
|
+
const options = resolveTaxonomyOptionsFromConfig(config);
|
|
162
|
+
const manifest = await content.getManifest();
|
|
163
|
+
return buildTaxonomyIndex(manifest.publicEntries, options).tags.map(
|
|
164
|
+
(term) => ({ slug: term.path.replace(/^\/tags\//, "") }),
|
|
165
|
+
);
|
|
166
|
+
}),
|
|
167
|
+
async (c) => {
|
|
168
|
+
const options = resolveTaxonomyOptionsFromConfig(config);
|
|
169
|
+
const manifest = await content.getManifest();
|
|
170
|
+
const term = buildTaxonomyIndex(manifest.publicEntries, options).tags.find(
|
|
171
|
+
(candidate) => candidate.path === c.req.path,
|
|
172
|
+
);
|
|
173
|
+
c.set("seo", term ? buildTaxonomySeo(config, term) : undefined);
|
|
174
|
+
if (!term) return c.notFound();
|
|
175
|
+
const page = renderTaxonomyPage(term, options);
|
|
176
|
+
c.set("headTags", page.headTags);
|
|
177
|
+
return c.render(<Article content={page} />);
|
|
178
|
+
},
|
|
179
|
+
);
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
フォルダのルートも `.folders` と `/folders/` に置き換えると同じ形です。
|
|
183
|
+
`renderTaxonomyPage` の戻り値は `PostContent` 互換(`frontmatter` + `html`)なので、
|
|
184
|
+
参照アプリの `Article` primitive にそのまま渡せます。`headTags` はフィード検出用の
|
|
185
|
+
`<link rel="alternate">` を document head に追加します。
|
|
186
|
+
|
|
187
|
+
## スタイル
|
|
188
|
+
|
|
189
|
+
パッケージは安定した `rr-taxonomy` ルートフックと `--rr-taxonomy-*` トークン
|
|
190
|
+
(`--rb-*` へフォールバック)を持つ `style.css` を同梱します。他のプラグイン
|
|
191
|
+
スタイルシートと同じように登録してください。
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
import "@riebeckite/plugin-taxonomy/style.css";
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## エクスポート
|
|
198
|
+
|
|
199
|
+
- `taxonomy(options?)` — プラグインファクトリー
|
|
200
|
+
- `taxonomyPlugin` — `taxonomy` の別名
|
|
201
|
+
- `resolveTaxonomyOptions(options?)` — 既定値を適用する
|
|
202
|
+
- `resolveTaxonomyOptionsFromConfig(config)` — config から解決済みオプションを読む
|
|
203
|
+
- `buildTaxonomyIndex(entries, options)` — タグ・フォルダ語を構築する
|
|
204
|
+
- `serializeTaxonomyIndex(index)` / `serializeTaxonomyTerm(term)` — JSON 安全な射影
|
|
205
|
+
- `renderTaxonomyPage(term, options)` / `renderRelatedTerms(term, options)` — ページ断片
|
|
206
|
+
- `renderTermFeed(config, term, format, limit?)` / `buildFeedHeadTags(term)` — 語ごとのフィード
|
|
207
|
+
- `buildTaxonomySeo(config, term)` — 一覧ページの SEO メタデータ
|
|
208
|
+
- `resolveFolderIndexLocations(entries, options, diagnostics)` — フォルダ index の location 戦略
|
|
209
|
+
- `slugifyTaxonomyValue(value)` — URL・ファイル用の slug
|
|
210
|
+
- `buildTaxonomyAbsoluteUrl(config, pathOrUrl)` — 絶対 URL
|
|
211
|
+
- 型: `TaxonomyOptions`, `ResolvedTaxonomyOptions`, `TaxonomyTerm`, `TaxonomyIndex`, `TaxonomyPage`, `TaxonomyTermData`, `TaxonomyIndexData`
|
|
212
|
+
|
|
213
|
+
## 制約
|
|
214
|
+
|
|
215
|
+
- タクソノミーはビルド時に固定されます。フルビルドで常に正しく再計算されます。
|
|
216
|
+
- 語ごとのフィードは静的なビルド成果物です。実行時のサーフェスは固定の JSON
|
|
217
|
+
データエンドポイントだけです。dev サーバーは語ごとのフィードファイルを列挙
|
|
218
|
+
しません。
|
|
219
|
+
- 語はマニフェストの公開ビューのみを反映します。非公開または `noindex` の
|
|
220
|
+
エントリは除外されます。
|
|
221
|
+
|
|
222
|
+
## 関連
|
|
223
|
+
|
|
224
|
+
- [プラグインガイド](../../../docs/ja/plugin-system.md)
|
|
225
|
+
- [コンテンツシステム](../../../docs/ja/content-system.md)
|