@riebeckite/plugin-breadcrumbs 0.0.14 → 0.0.15

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/README.md CHANGED
@@ -20,8 +20,9 @@ has an index note of its own (a note with the folder slug), that note's title
20
20
  is used for the crumb, otherwise the segment is title-cased. The final crumb is
21
21
  the note itself and links to its permalink.
22
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.
23
+ The plugin injects the nav into the manifest entry's HTML. Core synchronizes
24
+ that HTML with the content the route renders, so the nav appears on generated
25
+ pages and in feeds.
25
26
 
26
27
  ## JSON-LD
27
28
 
@@ -113,4 +114,5 @@ import "@riebeckite/plugin-breadcrumbs/style.css";
113
114
 
114
115
  ## See also
115
116
 
116
- - [Plugin guide](../../../docs/en/reference/plugin-api.md)
117
+ - [Plugin guide](../../../docs/en/docs/reference/plugin-api.md)
118
+
package/README_ja.md CHANGED
@@ -20,8 +20,8 @@ JavaScript は不要です。
20
20
  タイトルを使い、なければセグメントをタイトルケース(先頭大文字)にして
21
21
  代用します。最後のパンくずはそのノート自身で、パーマリンクへリンクします。
22
22
 
23
- `entry.html` と、コンテンツルートが描画するキャッシュ済みの
24
- `PostContent.html` の両方を更新するため、生成ページとフィードの両方に
23
+ マニフェストエントリの HTML にナビゲーションを挿入します。Core がその HTML を
24
+ コンテンツルートの描画 HTML と同期するため、生成ページとフィードの両方に
25
25
  ナビゲーションが反映されます。
26
26
 
27
27
  ## JSON-LD
@@ -114,4 +114,5 @@ import "@riebeckite/plugin-breadcrumbs/style.css";
114
114
 
115
115
  ## ????
116
116
 
117
- - [?????????](../../../docs/ja/reference/plugin-api.md)
117
+ - [?????????](../../../docs/ja/docs/reference/plugin-api.md)
118
+
package/dist/index.d.ts CHANGED
@@ -8,10 +8,10 @@ export declare const BREADCRUMBS_PLUGIN_NAME = "breadcrumbs";
8
8
  * Slug-hierarchy breadcrumbs for Riebeckite notes.
9
9
  *
10
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.
11
+ * inserts a `<nav>` at the top of the manifest entry HTML, which is the final
12
+ * rendering source. The hierarchical BreadcrumbList JSON-LD is contributed
13
+ * through `entry.headTags` so the Site shell can render it in the document
14
+ * `<head>`. No client runtime is required.
15
15
  */
16
16
  export declare function breadcrumbs(options?: BreadcrumbsOptions): import("@riebeckite/core").RiebeckitePlugin<BreadcrumbsOptions>;
17
17
  /** Alias matching the `*Plugin` suffix used by other plugin factories. */
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  } from "@riebeckite/core";
6
6
 
7
7
  // src/breadcrumbs.ts
8
+ import { resolveFolderLocation } from "@riebeckite/core";
8
9
  function buildBreadcrumbItems(args) {
9
10
  const { manifest, entry, config, homeLabel } = args;
10
11
  const segments = entry.slug.split("/").filter(Boolean);
@@ -14,13 +15,13 @@ function buildBreadcrumbItems(args) {
14
15
  if (homeName) items.push({ name: homeName, url: "/" });
15
16
  for (let index = 0; index < segments.length - 1; index++) {
16
17
  const folderSlug = segments.slice(0, index + 1).join("/");
17
- const folderEntry = manifest.bySlug.get(folderSlug);
18
+ const location = resolveFolderLocation(manifest, folderSlug);
18
19
  items.push({
19
- name: folderEntry?.title ?? titleCaseSegment(segments[index]),
20
- url: `/${folderSlug}`
20
+ name: location.type === "content" ? location.entry.title : titleCaseSegment(segments[index]),
21
+ ...location.type === "content" ? { url: location.entry.publicLocation.permalink } : location.type === "generated" ? { url: location.pathname } : {}
21
22
  });
22
23
  }
23
- items.push({ name: entry.title, url: entry.permalink });
24
+ items.push({ name: entry.title, url: entry.publicLocation.permalink });
24
25
  return items;
25
26
  }
26
27
  function titleCaseSegment(segment) {
@@ -66,7 +67,7 @@ function renderBreadcrumbNav(items, options) {
66
67
  const isLast = index === items.length - 1;
67
68
  const crumb = isLast ? `<span class="${className}__current" aria-current="page">${escapeHtml(
68
69
  item.name
69
- )}</span>` : `<a class="${className}__link" href="${escapeHtmlAttribute(
70
+ )}</span>` : !item.url ? `<span class="${className}__text">${escapeHtml(item.name)}</span>` : `<a class="${className}__link" href="${escapeHtmlAttribute(
70
71
  item.url
71
72
  )}">${escapeHtml(item.name)}</a>`;
72
73
  const trailing = isLast ? "" : `<span class="${className}__separator" aria-hidden="true">${separator}</span>`;
@@ -82,7 +83,7 @@ function buildBreadcrumbJsonLd(config, items) {
82
83
  "@type": "ListItem",
83
84
  position: index + 1,
84
85
  name: item.name,
85
- item: buildAbsoluteUrl(config, item.url)
86
+ ...item.url ? { item: buildAbsoluteUrl(config, item.url) } : {}
86
87
  }))
87
88
  };
88
89
  }
@@ -118,18 +119,20 @@ ${html}`;
118
119
  var BREADCRUMBS_PLUGIN_NAME = "breadcrumbs";
119
120
  function breadcrumbs(options = {}) {
120
121
  const resolved = resolveBreadcrumbsOptions(options);
121
- const processed = /* @__PURE__ */ new Map();
122
122
  return definePlugin({
123
123
  name: BREADCRUMBS_PLUGIN_NAME,
124
+ optional: ["content.folder-pages"],
125
+ processedContentCache: {
126
+ version: "breadcrumbs-v1",
127
+ dependencyMode: "none"
128
+ },
129
+ outputDependencies: [{ type: "global" }],
124
130
  options,
125
131
  validateOptions: validateBreadcrumbsOptions,
126
- onPostProcessed: (context) => {
127
- processed.set(context.slug, context.content);
128
- },
129
132
  onManifestCreated: (context) => {
130
133
  const { config, manifest } = context;
131
134
  if (!config) return;
132
- for (const entry of manifest.entries) {
135
+ for (const entry of manifest.publicEntries) {
133
136
  if (entry.html.includes(BREADCRUMBS_ATTRIBUTE)) continue;
134
137
  const items = buildBreadcrumbItems({
135
138
  manifest,
@@ -151,10 +154,7 @@ function breadcrumbs(options = {}) {
151
154
  }
152
155
  }
153
156
  entry.html = html;
154
- const content = processed.get(entry.slug);
155
- if (content) content.html = html;
156
157
  }
157
- processed.clear();
158
158
  },
159
159
  assets: [createStyleAsset(BREADCRUMBS_PLUGIN_NAME)]
160
160
  });
@@ -6,13 +6,4 @@ export type BuildBreadcrumbItemsArgs = {
6
6
  config: ResolvedRiebeckiteConfig;
7
7
  homeLabel: string;
8
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
9
  export declare function buildBreadcrumbItems(args: BuildBreadcrumbItemsArgs): BreadcrumbItem[];
@@ -1,7 +1,7 @@
1
1
  /** One crumb in the generated breadcrumb trail. */
2
2
  export type BreadcrumbItem = {
3
3
  name: string;
4
- url: string;
4
+ url?: string;
5
5
  };
6
6
  export type BreadcrumbsOptions = {
7
7
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-breadcrumbs",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,11 +15,11 @@
15
15
  "./style.css": "./style.css"
16
16
  },
17
17
  "dependencies": {
18
- "@riebeckite/core": "0.0.14"
18
+ "@riebeckite/core": "0.0.15"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsx": "^4.22.4",
22
- "@riebeckite/test": "0.0.14"
22
+ "@riebeckite/test": "0.0.15"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"