@riebeckite/plugin-breadcrumbs 0.0.24 → 0.0.26

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.
@@ -1,9 +1,9 @@
1
1
  import type { BreadcrumbItem } from "../src/types.js";
2
2
  export type BreadcrumbsProps = {
3
- items: readonly BreadcrumbItem[];
3
+ items?: readonly BreadcrumbItem[];
4
4
  ariaLabel?: string;
5
5
  className?: string;
6
6
  separator?: string;
7
7
  };
8
- declare const Breadcrumbs: ({ items, ariaLabel, className, separator, }: Readonly<BreadcrumbsProps>) => import("hono/jsx/jsx-dev-runtime").JSX.Element;
8
+ declare const Breadcrumbs: ({ items: explicitItems, ariaLabel, className, separator, }: Readonly<BreadcrumbsProps>) => Promise<import("hono/utils/html").HtmlEscapedString>;
9
9
  export default Breadcrumbs;
@@ -1,12 +1,59 @@
1
+ // components/breadcrumbs.tsx
2
+ import { useArticleContext, useSiteContext } from "@riebeckite/ui";
3
+ import { html } from "hono/html";
4
+
5
+ // src/breadcrumbs.ts
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);
10
+ const items = [];
11
+ if (homeLabel) pushBreadcrumbItem(items, { name: homeLabel, url: "/" });
12
+ for (let index = 0; index < segments.length - 1; index += 1) {
13
+ const pathname = `/${segments.slice(0, index + 1).join("/")}`;
14
+ const target = view.discoverableEntries.find(
15
+ (candidate) => candidate.permalink === pathname
16
+ );
17
+ pushBreadcrumbItem(items, {
18
+ name: target?.title || titleCaseSegment(segments[index]),
19
+ ...target ? { url: target.permalink } : {}
20
+ });
21
+ }
22
+ pushBreadcrumbItem(items, { name: entry.title, url: entry.permalink });
23
+ return items;
24
+ };
25
+ function pushBreadcrumbItem(items, item) {
26
+ const previous = items.at(-1);
27
+ if (previous?.name === item.name) {
28
+ items[items.length - 1] = item;
29
+ return;
30
+ }
31
+ items.push(item);
32
+ }
33
+ function publicPathSegments(permalink) {
34
+ return permalink.split("/").filter(Boolean);
35
+ }
36
+ function titleCaseSegment(segment) {
37
+ return segment.length === 0 ? segment : segment.charAt(0).toUpperCase() + segment.slice(1);
38
+ }
39
+
1
40
  // components/breadcrumbs.tsx
2
41
  import { jsx, jsxs } from "hono/jsx/jsx-runtime";
3
- var Breadcrumbs = (({
4
- items,
42
+ var Breadcrumbs = (async ({
43
+ items: explicitItems,
5
44
  ariaLabel = "Breadcrumb",
6
45
  className = "rb-breadcrumbs",
7
46
  separator = "/"
8
47
  }) => {
9
- if (items.length === 0) return null;
48
+ const site = useSiteContext();
49
+ const article = useArticleContext();
50
+ const items = explicitItems ?? (site && article?.entry ? await getBreadcrumbs({
51
+ view: site.view,
52
+ entry: article.entry,
53
+ homeLabel: site.config.site.title
54
+ }) : void 0);
55
+ if (!items) return html``;
56
+ if (items.length === 0) return html``;
10
57
  return /* @__PURE__ */ jsx("nav", { class: className, "data-breadcrumbs": true, "aria-label": ariaLabel, children: /* @__PURE__ */ jsx("ol", { children: items.map((item, index) => /* @__PURE__ */ jsxs("li", { class: `${className}__item`, children: [
11
58
  index === items.length - 1 ? /* @__PURE__ */ jsx("span", { class: `${className}__current`, "aria-current": "page", children: item.name }) : item.url ? /* @__PURE__ */ jsx("a", { class: `${className}__link`, href: item.url, children: item.name }) : /* @__PURE__ */ jsx("span", { class: `${className}__text`, children: item.name }),
12
59
  index < items.length - 1 ? /* @__PURE__ */ jsx("span", { class: `${className}__separator`, "aria-hidden": "true", children: separator }) : null
package/dist/index.js CHANGED
@@ -148,14 +148,24 @@ function hasBreadcrumbListType(value) {
148
148
  }
149
149
 
150
150
  // components/breadcrumbs.tsx
151
+ import { useArticleContext, useSiteContext } from "@riebeckite/ui";
152
+ import { html } from "hono/html";
151
153
  import { jsx, jsxs } from "hono/jsx/jsx-runtime";
152
- var Breadcrumbs = (({
153
- items,
154
+ var Breadcrumbs = (async ({
155
+ items: explicitItems,
154
156
  ariaLabel = "Breadcrumb",
155
157
  className = "rb-breadcrumbs",
156
158
  separator = "/"
157
159
  }) => {
158
- if (items.length === 0) return null;
160
+ const site = useSiteContext();
161
+ const article = useArticleContext();
162
+ const items = explicitItems ?? (site && article?.entry ? await getBreadcrumbs({
163
+ view: site.view,
164
+ entry: article.entry,
165
+ homeLabel: site.config.site.title
166
+ }) : void 0);
167
+ if (!items) return html``;
168
+ if (items.length === 0) return html``;
159
169
  return /* @__PURE__ */ jsx("nav", { class: className, "data-breadcrumbs": true, "aria-label": ariaLabel, children: /* @__PURE__ */ jsx("ol", { children: items.map((item, index) => /* @__PURE__ */ jsxs("li", { class: `${className}__item`, children: [
160
170
  index === items.length - 1 ? /* @__PURE__ */ jsx("span", { class: `${className}__current`, "aria-current": "page", children: item.name }) : item.url ? /* @__PURE__ */ jsx("a", { class: `${className}__link`, href: item.url, children: item.name }) : /* @__PURE__ */ jsx("span", { class: `${className}__text`, children: item.name }),
161
171
  index < items.length - 1 ? /* @__PURE__ */ jsx("span", { class: `${className}__separator`, "aria-hidden": "true", children: separator }) : null
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-breadcrumbs",
3
- "version": "0.0.24",
3
+ "version": "0.0.26",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -22,11 +22,12 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "hono": "^4.12.25",
25
- "@riebeckite/core": "0.0.24"
25
+ "@riebeckite/core": "0.0.26",
26
+ "@riebeckite/ui": "0.0.26"
26
27
  },
27
28
  "devDependencies": {
28
29
  "tsx": "^4.22.4",
29
- "@riebeckite/test": "0.0.24"
30
+ "@riebeckite/test": "0.0.26"
30
31
  },
31
32
  "publishConfig": {
32
33
  "access": "public"