@riebeckite/plugin-breadcrumbs 0.0.5

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 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,112 @@
1
+ # @riebeckite/plugin-breadcrumbs
2
+
3
+ Build-time breadcrumb navigation derived from the note's slug hierarchy. For
4
+ every published entry the plugin inserts a `<nav>` at the top of the rendered
5
+ HTML and enriches the page with a hierarchical BreadcrumbList JSON-LD schema.
6
+ No client-side JavaScript is required.
7
+
8
+ [日本語](./README_ja.md)
9
+
10
+ ## Overview
11
+
12
+ `breadcrumbs()` reads the entry's slug, splits it into segments, and produces a
13
+ trail that always starts at the site home:
14
+
15
+ - `Home / folder / sub-folder / Note` for `folder/sub-folder/note`
16
+ - `Home / Note` for a note at the site root
17
+
18
+ Intermediate segments are resolved against the manifest first: when the folder
19
+ has an index note of its own (a note with the folder slug), that note's title
20
+ is used for the crumb, otherwise the segment is title-cased. The final crumb is
21
+ the note itself and links to its permalink.
22
+
23
+ The plugin updates both `entry.html` and the cached `PostContent.html` that the
24
+ content route renders, so the nav appears on generated pages and in feeds.
25
+
26
+ ## JSON-LD
27
+
28
+ `breadcrumbs()` contributes the hierarchical BreadcrumbList as an
29
+ `entry.headTags` `<script type="application/ld+json">` so the Site shell can
30
+ render it in the document `<head>` (the reference Riebeckite app renders
31
+ `entry.headTags` in `_renderer.tsx`). Item URLs are made absolute against the
32
+ configured site `baseUrl`.
33
+
34
+ When the `seo` plugin is also enabled it emits a two-level BreadcrumbList
35
+ (`Home / Note`) inside its own article JSON-LD. The two blocks coexist; to
36
+ avoid duplicate BreadcrumbList entities a Site can drop the seo plugin's
37
+ placeholder for article pages (shown in the reference app's content route) or
38
+ disable `jsonLd` on this plugin (`jsonLd: false`).
39
+
40
+ ## Usage
41
+
42
+ ```ts
43
+ import { defineConfig } from "@riebeckite/core";
44
+ import { breadcrumbs } from "@riebeckite/plugin-breadcrumbs";
45
+
46
+ export default defineConfig({
47
+ // ...
48
+ plugins: [breadcrumbs()],
49
+ });
50
+ ```
51
+
52
+ ## Options
53
+
54
+ | Option | Type | Default | Description |
55
+ | ------ | ---- | ------- | ----------- |
56
+ | `homeLabel` | `string` | site title | Home crumb label |
57
+ | `className` | `string` | `"rb-breadcrumbs"` | Root CSS class |
58
+ | `ariaLabel` | `string` | `"Breadcrumbs"` | Accessible nav name |
59
+ | `separator` | `string` | `"/"` | Text between crumbs |
60
+ | `jsonLd` | `boolean` | `true` | Emit/replace the BreadcrumbList script |
61
+
62
+ ```ts
63
+ breadcrumbs({
64
+ homeLabel: "Blog",
65
+ separator: "›",
66
+ });
67
+ ```
68
+
69
+ ## Output
70
+
71
+ ```html
72
+ <nav class="rb-breadcrumbs" data-breadcrumbs aria-label="Breadcrumbs">
73
+ <ol>
74
+ <li class="rb-breadcrumbs__item">
75
+ <a class="rb-breadcrumbs__link" href="/">Blog</a>
76
+ <span class="rb-breadcrumbs__separator" aria-hidden="true">/</span>
77
+ </li>
78
+ <li class="rb-breadcrumbs__item">
79
+ <a class="rb-breadcrumbs__link" href="/folder">Folder</a>
80
+ <span class="rb-breadcrumbs__separator" aria-hidden="true">/</span>
81
+ </li>
82
+ <li class="rb-breadcrumbs__item">
83
+ <span class="rb-breadcrumbs__current" aria-current="page">Note</span>
84
+ </li>
85
+ </ol>
86
+ </nav>
87
+ ```
88
+
89
+ ## Style
90
+
91
+ The package ships `style.css`. Register it like any other plugin stylesheet:
92
+
93
+ ```ts
94
+ import "@riebeckite/plugin-breadcrumbs/style.css";
95
+ ```
96
+
97
+ ## Exports
98
+
99
+ - `breadcrumbs(options?)` — plugin factory
100
+ - `breadcrumbsPlugin` — alias of `breadcrumbs`
101
+ - `resolveBreadcrumbsOptions(options?)` — apply option defaults
102
+ - `buildBreadcrumbItems({ manifest, entry, config, homeLabel })` — build the trail
103
+ - `renderBreadcrumbNav(items, options)` — render the navigation HTML
104
+ - `buildBreadcrumbJsonLd(config, items)` — build the JSON-LD object
105
+ - `injectBreadcrumbNav(html, nav)` / `injectBreadcrumbJsonLd(html, schema)` — HTML injection helpers
106
+ - Types: `BreadcrumbsOptions`, `ResolvedBreadcrumbsOptions`, `BreadcrumbItem`
107
+
108
+ ## Limitations
109
+
110
+ - The trail is fixed at build time. A full rebuild always recomputes correctly.
111
+ - Only the slug hierarchy is considered; folder ordering from frontmatter or
112
+ series plugins is intentionally ignored.
package/README_ja.md ADDED
@@ -0,0 +1,113 @@
1
+ # @riebeckite/plugin-breadcrumbs
2
+
3
+ ノートのスラッグ階層からパンくずナビゲーションをビルド時に生成する
4
+ プラグインです。公開対象の各エントリについて、記事上部に `<nav>` を挿入し、
5
+ 階層構造を反映した BreadcrumbList の JSON-LD も出力します。クライアント側
6
+ JavaScript は不要です。
7
+
8
+ [English](./README.md)
9
+
10
+ ## 仕組み
11
+
12
+ `breadcrumbs()` はエントリのスラッグを「/」で区切り、必ずサイトのホームから
13
+ 始まるパンくず列を作ります。
14
+
15
+ - `folder/sub-folder/note` の場合: `ホーム / folder / sub-folder / note`
16
+ - サイト直下のノートの場合: `ホーム / note`
17
+
18
+ 途中のフォルダはマニフェストと突き合わせて解決します。フォルダ自身に
19
+ インデックスノート(フォルダと同名のスラッグを持つノート)があればその
20
+ タイトルを使い、なければセグメントをタイトルケース(先頭大文字)にして
21
+ 代用します。最後のパンくずはそのノート自身で、パーマリンクへリンクします。
22
+
23
+ `entry.html` と、コンテンツルートが描画するキャッシュ済みの
24
+ `PostContent.html` の両方を更新するため、生成ページとフィードの両方に
25
+ ナビゲーションが反映されます。
26
+
27
+ ## JSON-LD
28
+
29
+ `breadcrumbs()` は階層的な BreadcrumbList を `entry.headTags` の
30
+ `<script type="application/ld+json">` として提供します。Site シェルがこれを
31
+ 文書の `<head>` に描画します(リファレンスアプリの `_renderer.tsx` は
32
+ `entry.headTags` を描画します)。アイテムの URL は設定の `baseUrl` に基づき
33
+ 絶対 URL に変換されます。
34
+
35
+ `seo` プラグインも有効な場合、seo 側の記事 JSON-LD に 2 階層の
36
+ BreadcrumbList(`ホーム / ノート`)が含まれます。この 2 つは共存するため、
37
+ BreadcrumbList の重複を避けたい Site は記事ページで seo の暫定版を除去して
38
+ ください(リファレンスアプリのコンテンツルートで実施例を確認できます)。
39
+ 無効にする場合は本プラグインの `jsonLd: false` も利用できます。
40
+
41
+ ## 使い方
42
+
43
+ ```ts
44
+ import { defineConfig } from "@riebeckite/core";
45
+ import { breadcrumbs } from "@riebeckite/plugin-breadcrumbs";
46
+
47
+ export default defineConfig({
48
+ // ...
49
+ plugins: [breadcrumbs()],
50
+ });
51
+ ```
52
+
53
+ ## オプション
54
+
55
+ | オプション | 型 | 既定値 | 説明 |
56
+ | ---------- | -- | ------ | ---- |
57
+ | `homeLabel` | `string` | サイトタイトル | ホームのパンくずラベル |
58
+ | `className` | `string` | `"rb-breadcrumbs"` | ルート要素の CSS クラス |
59
+ | `ariaLabel` | `string` | `"Breadcrumbs"` | ナビゲーションのアクセシブル名 |
60
+ | `separator` | `string` | `"/"` | パンくず間の文字 |
61
+ | `jsonLd` | `boolean` | `true` | BreadcrumbList スクリプトを出力・置換する |
62
+
63
+ ```ts
64
+ breadcrumbs({
65
+ homeLabel: "ブログ",
66
+ separator: "›",
67
+ });
68
+ ```
69
+
70
+ ## 出力
71
+
72
+ ```html
73
+ <nav class="rb-breadcrumbs" data-breadcrumbs aria-label="Breadcrumbs">
74
+ <ol>
75
+ <li class="rb-breadcrumbs__item">
76
+ <a class="rb-breadcrumbs__link" href="/">ブログ</a>
77
+ <span class="rb-breadcrumbs__separator" aria-hidden="true">/</span>
78
+ </li>
79
+ <li class="rb-breadcrumbs__item">
80
+ <a class="rb-breadcrumbs__link" href="/folder">フォルダ</a>
81
+ <span class="rb-breadcrumbs__separator" aria-hidden="true">/</span>
82
+ </li>
83
+ <li class="rb-breadcrumbs__item">
84
+ <span class="rb-breadcrumbs__current" aria-current="page">ノート</span>
85
+ </li>
86
+ </ol>
87
+ </nav>
88
+ ```
89
+
90
+ ## スタイル
91
+
92
+ パッケージに `style.css` が含まれます。他のプラグインと同じように読み込みます。
93
+
94
+ ```ts
95
+ import "@riebeckite/plugin-breadcrumbs/style.css";
96
+ ```
97
+
98
+ ## エクスポート
99
+
100
+ - `breadcrumbs(options?)` — プラグインファクトリ
101
+ - `breadcrumbsPlugin` — `breadcrumbs` のエイリアス
102
+ - `resolveBreadcrumbsOptions(options?)` — オプションの既定値を適用する
103
+ - `buildBreadcrumbItems({ manifest, entry, config, homeLabel })` — パンくず列を組み立てる
104
+ - `renderBreadcrumbNav(items, options)` — ナビゲーション HTML を生成する
105
+ - `buildBreadcrumbJsonLd(config, items)` — JSON-LD オブジェクトを生成する
106
+ - `injectBreadcrumbNav(html, nav)` / `injectBreadcrumbJsonLd(html, schema)` — HTML 注入ヘルパー
107
+ - 型: `BreadcrumbsOptions`, `ResolvedBreadcrumbsOptions`, `BreadcrumbItem`
108
+
109
+ ## 制約
110
+
111
+ - パンくず列はビルド時に確定します。再ビルドすれば常に正しく再計算されます。
112
+ - スラッグ階層のみを参照します。frontmatter の並び順や series プラグインの
113
+ 順序は意図的に考慮しません。
@@ -0,0 +1,18 @@
1
+ import type { BreadcrumbsOptions } from "./src/types.js";
2
+ export { buildBreadcrumbItems } from "./src/breadcrumbs.js";
3
+ export { resolveBreadcrumbsOptions } from "./src/options.js";
4
+ export { BREADCRUMBS_ATTRIBUTE, buildBreadcrumbHeadTag, buildBreadcrumbJsonLd, hasBreadcrumbHeadTag, injectBreadcrumbNav, renderBreadcrumbNav, } from "./src/render.js";
5
+ export type { BreadcrumbItem, BreadcrumbsOptions, ResolvedBreadcrumbsOptions, } from "./src/types.js";
6
+ export declare const BREADCRUMBS_PLUGIN_NAME = "breadcrumbs";
7
+ /**
8
+ * Slug-hierarchy breadcrumbs for Riebeckite notes.
9
+ *
10
+ * For every published entry it derives a trail from the note's slug and
11
+ * inserts a `<nav>` at the top of both `entry.html` and the cached
12
+ * `PostContent.html` that the content route renders. The hierarchical
13
+ * BreadcrumbList JSON-LD is contributed through `entry.headTags` so the Site
14
+ * shell can render it in the document `<head>`. No client runtime is required.
15
+ */
16
+ export declare function breadcrumbs(options?: BreadcrumbsOptions): import("@riebeckite/core").RiebeckitePlugin<BreadcrumbsOptions>;
17
+ /** Alias matching the `*Plugin` suffix used by other plugin factories. */
18
+ export declare const breadcrumbsPlugin: typeof breadcrumbs;
package/dist/index.js ADDED
@@ -0,0 +1,191 @@
1
+ // index.ts
2
+ import {
3
+ createStyleAsset,
4
+ definePlugin
5
+ } from "@riebeckite/core";
6
+
7
+ // src/breadcrumbs.ts
8
+ function buildBreadcrumbItems(args) {
9
+ const { manifest, entry, config, homeLabel } = args;
10
+ const segments = entry.slug.split("/").filter(Boolean);
11
+ if (segments.length === 0) return [];
12
+ const items = [];
13
+ const homeName = homeLabel || config.site.title;
14
+ if (homeName) items.push({ name: homeName, url: "/" });
15
+ for (let index = 0; index < segments.length - 1; index++) {
16
+ const folderSlug = segments.slice(0, index + 1).join("/");
17
+ const folderEntry = manifest.bySlug.get(folderSlug);
18
+ items.push({
19
+ name: folderEntry?.title ?? titleCaseSegment(segments[index]),
20
+ url: `/${folderSlug}`
21
+ });
22
+ }
23
+ items.push({ name: entry.title, url: entry.permalink });
24
+ return items;
25
+ }
26
+ function titleCaseSegment(segment) {
27
+ return segment.length === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1);
28
+ }
29
+
30
+ // src/options.ts
31
+ function resolveBreadcrumbsOptions(options) {
32
+ return {
33
+ homeLabel: options?.homeLabel?.trim() || "",
34
+ className: options?.className?.trim() || "rb-breadcrumbs",
35
+ ariaLabel: options?.ariaLabel?.trim() || "Breadcrumbs",
36
+ separator: options?.separator ?? "/",
37
+ jsonLd: options?.jsonLd ?? true
38
+ };
39
+ }
40
+
41
+ // src/render.ts
42
+ import {
43
+ escapeHtml,
44
+ escapeHtmlAttribute
45
+ } from "@riebeckite/core";
46
+
47
+ // src/url.ts
48
+ function buildAbsoluteUrl(config, pathOrUrl) {
49
+ if (!pathOrUrl) return config.site.baseUrl;
50
+ if (/^https?:\/\//.test(pathOrUrl)) return pathOrUrl;
51
+ return new URL(
52
+ pathOrUrl,
53
+ config.site.baseUrl || "https://example.com"
54
+ ).toString();
55
+ }
56
+
57
+ // src/render.ts
58
+ var BREADCRUMBS_ATTRIBUTE = "data-breadcrumbs";
59
+ function renderBreadcrumbNav(items, options) {
60
+ if (items.length === 0) return "";
61
+ const className = escapeHtmlAttribute(options.className);
62
+ const label = escapeHtmlAttribute(options.ariaLabel);
63
+ const separator = escapeHtml(options.separator);
64
+ const listItems = items.map((item, index) => {
65
+ const isLast = index === items.length - 1;
66
+ const crumb = isLast ? `<span class="${className}__current" aria-current="page">${escapeHtml(
67
+ item.name
68
+ )}</span>` : `<a class="${className}__link" href="${escapeHtmlAttribute(
69
+ item.url
70
+ )}">${escapeHtml(item.name)}</a>`;
71
+ const trailing = isLast ? "" : `<span class="${className}__separator" aria-hidden="true">${separator}</span>`;
72
+ return `<li class="${className}__item">${crumb}${trailing}</li>`;
73
+ }).join("");
74
+ return `<nav class="${className}" ${BREADCRUMBS_ATTRIBUTE} aria-label="${label}"><ol>${listItems}</ol></nav>`;
75
+ }
76
+ function buildBreadcrumbJsonLd(config, items) {
77
+ return {
78
+ "@context": "https://schema.org",
79
+ "@type": "BreadcrumbList",
80
+ itemListElement: items.map((item, index) => ({
81
+ "@type": "ListItem",
82
+ position: index + 1,
83
+ name: item.name,
84
+ item: buildAbsoluteUrl(config, item.url)
85
+ }))
86
+ };
87
+ }
88
+ function buildBreadcrumbHeadTag(schema) {
89
+ return {
90
+ tag: "script",
91
+ attrs: { type: "application/ld+json" },
92
+ children: JSON.stringify(schema)
93
+ };
94
+ }
95
+ function hasBreadcrumbHeadTag(headTags) {
96
+ return headTags?.some(
97
+ (tag) => tag.tag === "script" && typeof tag.children === "string" && tag.children.includes('"@type":"BreadcrumbList"')
98
+ ) ?? false;
99
+ }
100
+ function injectBreadcrumbNav(html, nav) {
101
+ if (nav === "" || html.includes(BREADCRUMBS_ATTRIBUTE)) return html;
102
+ const article = /<article\b[^>]*>/i.exec(html);
103
+ if (article) {
104
+ const end = article.index + article[0].length;
105
+ return `${html.slice(0, end)}${nav}${html.slice(end)}`;
106
+ }
107
+ const body = /<body\b[^>]*>/i.exec(html);
108
+ if (body) {
109
+ const end = body.index + body[0].length;
110
+ return `${html.slice(0, end)}${nav}${html.slice(end)}`;
111
+ }
112
+ return `${nav}
113
+ ${html}`;
114
+ }
115
+
116
+ // index.ts
117
+ var BREADCRUMBS_PLUGIN_NAME = "breadcrumbs";
118
+ function breadcrumbs(options = {}) {
119
+ const resolved = resolveBreadcrumbsOptions(options);
120
+ const processed = /* @__PURE__ */ new Map();
121
+ return definePlugin({
122
+ name: BREADCRUMBS_PLUGIN_NAME,
123
+ options,
124
+ validateOptions: validateBreadcrumbsOptions,
125
+ onPostProcessed: (context) => {
126
+ processed.set(context.slug, context.content);
127
+ },
128
+ onManifestCreated: (context) => {
129
+ const { manifest } = context;
130
+ for (const entry of manifest.entries) {
131
+ if (entry.html.includes(BREADCRUMBS_ATTRIBUTE)) continue;
132
+ const items = buildBreadcrumbItems({
133
+ manifest,
134
+ entry,
135
+ config: context.config,
136
+ homeLabel: resolved.homeLabel
137
+ });
138
+ if (items.length === 0) continue;
139
+ let html = entry.html;
140
+ const nav = renderBreadcrumbNav(items, resolved);
141
+ html = injectBreadcrumbNav(html, nav);
142
+ if (resolved.jsonLd) {
143
+ const schema = buildBreadcrumbJsonLd(context.config, items);
144
+ if (!hasBreadcrumbHeadTag(entry.headTags)) {
145
+ entry.headTags = [
146
+ ...entry.headTags ?? [],
147
+ buildBreadcrumbHeadTag(schema)
148
+ ];
149
+ }
150
+ }
151
+ entry.html = html;
152
+ const content = processed.get(entry.slug);
153
+ if (content) content.html = html;
154
+ }
155
+ processed.clear();
156
+ },
157
+ assets: [createStyleAsset(BREADCRUMBS_PLUGIN_NAME)]
158
+ });
159
+ }
160
+ var breadcrumbsPlugin = breadcrumbs;
161
+ function validateBreadcrumbsOptions(options) {
162
+ if (!options) return [];
163
+ const issues = [];
164
+ const assertNonEmptyString = (key) => {
165
+ const value = options[key];
166
+ if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) {
167
+ issues.push({ path: key, message: "Expected a non-empty string." });
168
+ }
169
+ };
170
+ assertNonEmptyString("homeLabel");
171
+ assertNonEmptyString("className");
172
+ assertNonEmptyString("ariaLabel");
173
+ assertNonEmptyString("separator");
174
+ if (options.jsonLd !== void 0 && typeof options.jsonLd !== "boolean") {
175
+ issues.push({ path: "jsonLd", message: "Expected a boolean." });
176
+ }
177
+ return issues;
178
+ }
179
+ export {
180
+ BREADCRUMBS_ATTRIBUTE,
181
+ BREADCRUMBS_PLUGIN_NAME,
182
+ breadcrumbs,
183
+ breadcrumbsPlugin,
184
+ buildBreadcrumbHeadTag,
185
+ buildBreadcrumbItems,
186
+ buildBreadcrumbJsonLd,
187
+ hasBreadcrumbHeadTag,
188
+ injectBreadcrumbNav,
189
+ renderBreadcrumbNav,
190
+ resolveBreadcrumbsOptions
191
+ };
@@ -0,0 +1,18 @@
1
+ import type { ContentManifest, ContentManifestEntry, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { BreadcrumbItem } from "./types.js";
3
+ export type BuildBreadcrumbItemsArgs = {
4
+ manifest: ContentManifest;
5
+ entry: ContentManifestEntry;
6
+ config: ResolvedRiebeckiteConfig;
7
+ homeLabel: string;
8
+ };
9
+ /**
10
+ * Builds the breadcrumb trail for a note from its slug hierarchy.
11
+ *
12
+ * The first crumb is always the site home (the site title unless the consumer
13
+ * provided a `homeLabel`); each intermediate slug segment becomes a crumb
14
+ * pointing at the folder's own URL. When the folder has an index note of its
15
+ * own, that note's title is used for the crumb instead of the raw segment.
16
+ * The final crumb is the note itself and points at its permalink.
17
+ */
18
+ export declare function buildBreadcrumbItems(args: BuildBreadcrumbItemsArgs): BreadcrumbItem[];
@@ -0,0 +1,2 @@
1
+ import type { BreadcrumbsOptions, ResolvedBreadcrumbsOptions } from "./types.js";
2
+ export declare function resolveBreadcrumbsOptions(options: BreadcrumbsOptions | undefined): ResolvedBreadcrumbsOptions;
@@ -0,0 +1,34 @@
1
+ import { type PluginHeadTag, type ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ import type { BreadcrumbItem, ResolvedBreadcrumbsOptions } from "./types.js";
3
+ /** Boolean attribute that marks the generated navigation for tests and styling. */
4
+ export declare const BREADCRUMBS_ATTRIBUTE = "data-breadcrumbs";
5
+ /**
6
+ * Renders the breadcrumb trail as a navigation landmark. Returns an empty
7
+ * string when there is nothing to show, so callers can leave HTML untouched.
8
+ */
9
+ export declare function renderBreadcrumbNav(items: readonly BreadcrumbItem[], options: ResolvedBreadcrumbsOptions): string;
10
+ /**
11
+ * Builds the BreadcrumbList schema.org JSON-LD object from the resolved
12
+ * trail. Item URLs are made absolute against the configured site base URL.
13
+ */
14
+ export declare function buildBreadcrumbJsonLd(config: ResolvedRiebeckiteConfig, items: readonly BreadcrumbItem[]): Record<string, unknown>;
15
+ /**
16
+ * Builds the BreadcrumbList JSON-LD `<script>` head tag so the Site shell can
17
+ * render it in the document `<head>` (see the `headTags` entry mechanism).
18
+ */
19
+ export declare function buildBreadcrumbHeadTag(schema: Record<string, unknown>): PluginHeadTag;
20
+ /**
21
+ * True when the entry already carries a BreadcrumbList JSON-LD head tag, so
22
+ * repeated plugin passes do not emit duplicates.
23
+ */
24
+ export declare function hasBreadcrumbHeadTag(headTags: readonly PluginHeadTag[] | undefined): boolean;
25
+ /**
26
+ * Places the completed navigation at the top of the note.
27
+ *
28
+ * When the HTML is a full page (it contains an `<article>` or `<body>` tag)
29
+ * the nav is inserted right after that opening tag. The manifest `html` we
30
+ * operate on is normally a content fragment the Site wraps in its own
31
+ * `<article>`, in which case the nav is simply prepended so it renders above
32
+ * the note's title.
33
+ */
34
+ export declare function injectBreadcrumbNav(html: string, nav: string): string;
@@ -0,0 +1,31 @@
1
+ /** One crumb in the generated breadcrumb trail. */
2
+ export type BreadcrumbItem = {
3
+ name: string;
4
+ url: string;
5
+ };
6
+ export type BreadcrumbsOptions = {
7
+ /**
8
+ * Label for the site-wide home crumb. When omitted, the site title from the
9
+ * resolved config (`site.title`) is used.
10
+ */
11
+ homeLabel?: string;
12
+ /** Class name applied to the nav and its child elements. */
13
+ className?: string;
14
+ /** Accessible name for the navigation landmark. */
15
+ ariaLabel?: string;
16
+ /** Text placed between siblings (defaults to "/"). */
17
+ separator?: string;
18
+ /**
19
+ * Emit a BreadcrumbList JSON-LD script. When the seo plugin already
20
+ * rendered one, its list is replaced with the hierarchical trail
21
+ * (defaults to `true`).
22
+ */
23
+ jsonLd?: boolean;
24
+ };
25
+ export type ResolvedBreadcrumbsOptions = {
26
+ homeLabel: string;
27
+ className: string;
28
+ ariaLabel: string;
29
+ separator: string;
30
+ jsonLd: boolean;
31
+ };
@@ -0,0 +1,2 @@
1
+ import type { ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
+ export declare function buildAbsoluteUrl(config: ResolvedRiebeckiteConfig, pathOrUrl: string): string;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@riebeckite/plugin-breadcrumbs",
3
+ "version": "0.0.5",
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.5"
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/breadcrumbs"
34
+ },
35
+ "homepage": "https://github.com/Rerurate514/riebeckite#readme",
36
+ "bugs": {
37
+ "url": "https://github.com/Rerurate514/riebeckite/issues"
38
+ },
39
+ "description": "Slug-hierarchy breadcrumb navigation for Riebeckite.",
40
+ "keywords": [
41
+ "riebeckite",
42
+ "plugin",
43
+ "breadcrumbs",
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,39 @@
1
+ .rb-breadcrumbs {
2
+ margin-block: 0 0.75rem;
3
+ }
4
+
5
+ .rb-breadcrumbs ol {
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ align-items: center;
9
+ gap: 0.375rem;
10
+ list-style: none;
11
+ margin: 0;
12
+ padding: 0;
13
+ }
14
+
15
+ .rb-breadcrumbs__item {
16
+ display: inline-flex;
17
+ align-items: center;
18
+ gap: 0.375rem;
19
+ }
20
+
21
+ .rb-breadcrumbs__link {
22
+ color: var(--rb-color-muted, inherit);
23
+ text-decoration: none;
24
+ }
25
+
26
+ .rb-breadcrumbs__link:hover {
27
+ color: var(--rb-color-accent, inherit);
28
+ text-decoration: underline;
29
+ }
30
+
31
+ .rb-breadcrumbs__current {
32
+ color: var(--rb-color-ink, inherit);
33
+ font-weight: 600;
34
+ }
35
+
36
+ .rb-breadcrumbs__separator {
37
+ color: var(--rb-color-muted, inherit);
38
+ opacity: 0.6;
39
+ }