@riebeckite/plugin-breadcrumbs 0.0.31 → 0.0.32

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.
@@ -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.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``;
@@ -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
3
  export 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
  };
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.32",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,12 +22,12 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "hono": "^4.12.25",
25
- "@riebeckite/ui": "0.0.31",
26
- "@riebeckite/core": "0.0.31"
25
+ "@riebeckite/core": "0.0.32",
26
+ "@riebeckite/ui": "0.0.32"
27
27
  },
28
28
  "devDependencies": {
29
29
  "tsx": "^4.22.4",
30
- "@riebeckite/test": "0.0.31"
30
+ "@riebeckite/test": "0.0.32"
31
31
  },
32
32
  "publishConfig": {
33
33
  "access": "public"