@riebeckite/plugin-breadcrumbs 0.0.31 → 0.0.33

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
@@ -9,6 +9,10 @@ No client-side JavaScript is required.
9
9
 
10
10
  [日本語](./README_ja.md)
11
11
 
12
+ ## Live example
13
+
14
+ The breadcrumb trail above the article — **Riebeckite / Docs / Plugins / Breadcrumbs** — is this plugin's output. It is built from the page's folder and title, and the same trail is emitted as `BreadcrumbList` JSON-LD.
15
+
12
16
  ## Overview
13
17
 
14
18
  `breadcrumbs()` reads the entry's slug, splits it into segments, and produces a
@@ -85,7 +89,7 @@ import "@riebeckite/plugin-breadcrumbs/style.css";
85
89
  ## Exports
86
90
 
87
91
  - `breadcrumbs(options?)` — plugin factory
88
- - `breadcrumbsPlugin` — alias of `breadcrumbs`
92
+ - `breadcrumbs` — alias of `breadcrumbs`
89
93
  - `resolveBreadcrumbsOptions(options?)` — apply option defaults
90
94
  - `buildBreadcrumbItems({ manifest, entry, config, homeLabel })` — build the trail
91
95
  - `renderBreadcrumbNav(items, options)` — render the navigation HTML
package/README_ja.md CHANGED
@@ -9,6 +9,10 @@ JavaScript は不要です。
9
9
 
10
10
  [English](./README.md)
11
11
 
12
+ ## 実行例
13
+
14
+ 記事の上に表示されている **Riebeckite / Docs / Plugins / Breadcrumbs** が、このプラグインの出力です。ページのフォルダとタイトルから組み立てられ、同じ内容が `BreadcrumbList` の JSON-LD としても出力されます。
15
+
12
16
  ## 仕組み
13
17
 
14
18
  `breadcrumbs()` はエントリのスラッグを「/」で区切り、必ずサイトのホームから
@@ -19,7 +23,7 @@ JavaScript は不要です。
19
23
 
20
24
  途中のフォルダはマニフェストと突き合わせて解決します。フォルダ自身に
21
25
  インデックスノート(フォルダと同名のスラッグを持つノート)があればその
22
- タイトルを使い、なければセグメントをタイトルケース(先頭大文字)にして
26
+ タイトルを使い、なければセグメントをタイトルケース(先頭を大文字にする)にして
23
27
  代用します。最後のパンくずはそのノート自身で、パーマリンクへリンクします。
24
28
 
25
29
  マニフェストエントリの HTML にナビゲーションを挿入します。Core がその HTML を
@@ -29,7 +33,7 @@ JavaScript は不要です。
29
33
  ## JSON-LD
30
34
 
31
35
  `breadcrumbs()` は階層的な BreadcrumbList を `entry.headTags` の
32
- `<script type="application/ld+json">` として提供します。Site シェルがこれを
36
+ `<script type="application/ld+json">` として提供します。サイトシェルがこれを
33
37
  文書の `<head>` に描画します(リファレンスアプリの `_renderer.tsx` は
34
38
  `entry.headTags` を描画します)。アイテムの URL は設定の `baseUrl` に基づき
35
39
  絶対 URL に変換されます。
@@ -37,7 +41,7 @@ JavaScript は不要です。
37
41
  `seo` プラグインも有効な場合、seo 側は独自の 2 階層の BreadcrumbList
38
42
  (`ホーム / ノート`)を記事 JSON-LD に含めようとします。ページの `headTags`
39
43
  を seo 拡張へ渡すと、本プラグインが提供した BreadcrumbList を検出して seo 側の
40
- 暫定版を省略するため、Site 側で調整しなくても BreadcrumbList は 1 つだけに
44
+ 暫定版を省略するため、サイト側で調整しなくても BreadcrumbList は 1 つだけに
41
45
  なります。本プラグインからの出力自体を止めたい場合は `jsonLd: false` を使います。
42
46
 
43
47
  ## 使い方
@@ -84,7 +88,7 @@ import "@riebeckite/plugin-breadcrumbs/style.css";
84
88
  ## エクスポート
85
89
 
86
90
  - `breadcrumbs(options?)`:プラグインファクトリ
87
- - `breadcrumbsPlugin`:`breadcrumbs` のエイリアス
91
+ - `breadcrumbs`:`breadcrumbs` のエイリアス
88
92
  - `resolveBreadcrumbsOptions(options?)`:オプションの既定値を適用する
89
93
  - `buildBreadcrumbItems({ manifest, entry, config, homeLabel })`:パンくず列を組み立てる
90
94
  - `renderBreadcrumbNav(items, options)`:ナビゲーション HTML を生成する
@@ -4,24 +4,28 @@ import { html } from "hono/html";
4
4
 
5
5
  // src/breadcrumbs.ts
6
6
  import { resolvePublicFolderLocation } from "@riebeckite/core";
7
- var getBreadcrumbs = ({ view, entry, homeLabel = "" }) => {
8
- if (!view.findRoutableBySlug(entry.slug)) return [];
9
- const segments = publicPathSegments(entry.permalink);
7
+ function buildBreadcrumbItems(args) {
8
+ const { manifest, entry, config, homeLabel } = args;
9
+ if (!entry.slug) return [];
10
+ const segments = publicPathSegments(entry.publicLocation.permalink);
10
11
  const items = [];
11
- if (homeLabel) pushBreadcrumbItem(items, { name: homeLabel, url: "/" });
12
- for (let index = 0; index < segments.length - 1; index += 1) {
12
+ const homeName = homeLabel || config.site.title;
13
+ if (homeName) pushBreadcrumbItem(items, { name: homeName, url: "/" });
14
+ if (segments.length === 0) return items;
15
+ for (let index = 0; index < segments.length - 1; index++) {
13
16
  const pathname = `/${segments.slice(0, index + 1).join("/")}`;
14
- const target = view.discoverableEntries.find(
15
- (candidate) => candidate.permalink === pathname
16
- );
17
+ const location = resolvePublicFolderLocation(manifest, pathname);
17
18
  pushBreadcrumbItem(items, {
18
- name: target?.title || titleCaseSegment(segments[index]),
19
- ...target ? { url: target.permalink } : {}
19
+ name: location.type === "content" ? location.entry.title : titleCaseSegment(segments[index]),
20
+ ...location.type === "content" ? { url: location.entry.publicLocation.permalink } : location.type === "generated" ? { url: location.pathname } : {}
20
21
  });
21
22
  }
22
- pushBreadcrumbItem(items, { name: entry.title, url: entry.permalink });
23
+ pushBreadcrumbItem(items, {
24
+ name: entry.title,
25
+ url: entry.publicLocation.permalink
26
+ });
23
27
  return items;
24
- };
28
+ }
25
29
  function pushBreadcrumbItem(items, item) {
26
30
  const previous = items.at(-1);
27
31
  if (previous?.name === item.name) {
@@ -47,9 +51,10 @@ var Breadcrumbs = (async ({
47
51
  }) => {
48
52
  const site = useSiteContext();
49
53
  const article = useArticleContext();
50
- const items = explicitItems ?? (site && article?.entry ? await getBreadcrumbs({
51
- view: site.view,
54
+ const items = explicitItems ?? (site && article?.entry ? buildBreadcrumbItems({
55
+ manifest: site.manifest,
52
56
  entry: article.entry,
57
+ config: site.config,
53
58
  homeLabel: site.config.site.title
54
59
  }) : void 0);
55
60
  if (!items) return html``;
package/dist/index.d.ts CHANGED
@@ -16,5 +16,3 @@ export declare const BREADCRUMBS_PLUGIN_NAME = "breadcrumbs";
16
16
  * `<head>`. No client runtime is required.
17
17
  */
18
18
  export declare function breadcrumbs(options?: BreadcrumbsOptions): import("@riebeckite/core").RiebeckitePlugin<BreadcrumbsOptions>;
19
- /** Alias matching the `*Plugin` suffix used by other plugin factories. */
20
- export declare const breadcrumbsPlugin: typeof breadcrumbs;
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ var getBreadcrumbs = ({ view, entry, homeLabel = "" }) => {
37
37
  for (let index = 0; index < segments.length - 1; index += 1) {
38
38
  const pathname = `/${segments.slice(0, index + 1).join("/")}`;
39
39
  const target = view.discoverableEntries.find(
40
- (candidate) => candidate.permalink === pathname
40
+ (candidate) => normalizePathname(candidate.permalink) === pathname
41
41
  );
42
42
  pushBreadcrumbItem(items, {
43
43
  name: target?.title || titleCaseSegment(segments[index]),
@@ -58,6 +58,10 @@ function pushBreadcrumbItem(items, item) {
58
58
  function publicPathSegments(permalink) {
59
59
  return permalink.split("/").filter(Boolean);
60
60
  }
61
+ function normalizePathname(pathname) {
62
+ const segments = publicPathSegments(pathname);
63
+ return segments.length === 0 ? "/" : `/${segments.join("/")}`;
64
+ }
61
65
  function titleCaseSegment(segment) {
62
66
  return segment.length === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1);
63
67
  }
@@ -160,9 +164,10 @@ var Breadcrumbs = (async ({
160
164
  }) => {
161
165
  const site = useSiteContext();
162
166
  const article = useArticleContext();
163
- const items = explicitItems ?? (site && article?.entry ? await getBreadcrumbs({
164
- view: site.view,
167
+ const items = explicitItems ?? (site && article?.entry ? buildBreadcrumbItems({
168
+ manifest: site.manifest,
165
169
  entry: article.entry,
170
+ config: site.config,
166
171
  homeLabel: site.config.site.title
167
172
  }) : void 0);
168
173
  if (!items) return html``;
@@ -218,7 +223,6 @@ function breadcrumbs(options = {}) {
218
223
  ]
219
224
  });
220
225
  }
221
- var breadcrumbsPlugin = breadcrumbs;
222
226
  function breadcrumbOutputDependencies(entry, manifest) {
223
227
  const segments = entry.publicLocation.permalink.split("/").filter(Boolean);
224
228
  const dependencies = [];
@@ -261,7 +265,6 @@ export {
261
265
  BREADCRUMBS_PLUGIN_NAME,
262
266
  breadcrumbs_default as Breadcrumbs,
263
267
  breadcrumbs,
264
- breadcrumbsPlugin,
265
268
  buildBreadcrumbHeadTag,
266
269
  buildBreadcrumbItems,
267
270
  buildBreadcrumbJsonLd,
@@ -1,8 +1,14 @@
1
- import type { ContentManifest, ContentManifestEntry, PluginDataHelper, PublicContentEntry, PublicContentView, ResolvedRiebeckiteConfig } from "@riebeckite/core";
1
+ import type { ContentManifest, PluginDataHelper, PublicContentEntry, PublicContentView, ResolvedRiebeckiteConfig } from "@riebeckite/core";
2
2
  import type { BreadcrumbItem } from "./types.js";
3
- export type BuildBreadcrumbItemsArgs = {
3
+ type BuildBreadcrumbItemsArgs = {
4
4
  manifest: ContentManifest;
5
- entry: ContentManifestEntry;
5
+ entry: {
6
+ slug: string;
7
+ title: string;
8
+ publicLocation: {
9
+ permalink: string;
10
+ };
11
+ };
6
12
  config: ResolvedRiebeckiteConfig;
7
13
  homeLabel: string;
8
14
  };
@@ -12,3 +18,4 @@ export declare const getBreadcrumbs: PluginDataHelper<{
12
18
  entry: PublicContentEntry;
13
19
  homeLabel?: string;
14
20
  }, readonly BreadcrumbItem[]>;
21
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-breadcrumbs",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -21,13 +21,13 @@
21
21
  "./style.css": "./style.css"
22
22
  },
23
23
  "dependencies": {
24
- "hono": "^4.12.25",
25
- "@riebeckite/ui": "0.0.31",
26
- "@riebeckite/core": "0.0.31"
24
+ "@riebeckite/core": "0.0.33",
25
+ "@riebeckite/ui": "0.0.33",
26
+ "hono": "^4.12.25"
27
27
  },
28
28
  "devDependencies": {
29
- "tsx": "^4.22.4",
30
- "@riebeckite/test": "0.0.31"
29
+ "@riebeckite/test": "0.0.33",
30
+ "tsx": "^4.22.4"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"