-
+
{/*MAIN CONTENT*/}
diff --git a/nx-dev/models-document/src/lib/documents.models.ts b/nx-dev/models-document/src/lib/documents.models.ts
index 6961a22eb4..cb6433d9cd 100644
--- a/nx-dev/models-document/src/lib/documents.models.ts
+++ b/nx-dev/models-document/src/lib/documents.models.ts
@@ -29,6 +29,7 @@ export interface ProcessedDocument {
id: string;
name: string;
relatedDocuments: Record
;
+ parentDocuments?: RelatedDocument[];
tags: string[];
}
diff --git a/nx-dev/ui-common/src/lib/breadcrumbs.tsx b/nx-dev/ui-common/src/lib/breadcrumbs.tsx
index 54b10e84f3..71aef1949f 100644
--- a/nx-dev/ui-common/src/lib/breadcrumbs.tsx
+++ b/nx-dev/ui-common/src/lib/breadcrumbs.tsx
@@ -1,25 +1,71 @@
import { ChevronRightIcon } from '@heroicons/react/24/solid';
+import { ProcessedDocument } from '@nx/nx-dev/models-document';
import classNames from 'classnames';
-export function Breadcrumbs({ path }: { path: string }): JSX.Element {
- const cleanedPath = path.includes('?')
- ? path.slice(0, path.indexOf('?'))
- : path;
- const pages = [
- ...cleanedPath
- .split('/')
- .filter(Boolean)
- .map((segment, index, segments) => ({
- name: segment.includes('#')
- ? segment.slice(0, segment.indexOf('#'))
- : segment,
- // We do not have dedicated page view for executors & generators
- href: '/' + segments.slice(0, index + 1).join('/'),
- current: '/' + segments.slice(0, index + 1).join('/') === cleanedPath,
- })),
- ];
+interface Crumb {
+ id: string;
+ name: string;
+ href: string;
+ current: boolean;
+}
- if (pages.length === 1) {
+const sectionNames: Record = {
+ ci: 'CI',
+ 'extending-nx': 'Extending Nx',
+ 'nx-api': 'Nx API',
+};
+
+const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
+
+export function Breadcrumbs({
+ document,
+ path,
+}: {
+ document?: ProcessedDocument;
+ path?: string;
+}): JSX.Element {
+ let crumbs: Crumb[] = [];
+
+ if (path) {
+ const cleanedPath = path.includes('?')
+ ? path.slice(0, path.indexOf('?'))
+ : path;
+ crumbs = [
+ ...cleanedPath
+ .split('/')
+ .filter(Boolean)
+ .map((segment, index, segments) => {
+ const strippedName = segment.includes('#')
+ ? segment.slice(0, segment.indexOf('#'))
+ : segment;
+ const name =
+ sectionNames[strippedName] ||
+ strippedName.split('-').map(capitalize).join(' ');
+ return {
+ id: segment,
+ name,
+ // We do not have dedicated page view for executors & generators
+ href: '/' + segments.slice(0, index + 1).join('/'),
+ current:
+ '/' + segments.slice(0, index + 1).join('/') === cleanedPath,
+ };
+ }),
+ ];
+ }
+
+ if (document && document.parentDocuments) {
+ crumbs = document.parentDocuments.map((parentDocument, index) => ({
+ id: parentDocument.id,
+ name:
+ parentDocument.name ||
+ sectionNames[parentDocument.id] ||
+ parentDocument.id.split('-').map(capitalize).join(' '),
+ href: parentDocument.path,
+ current: index + 1 === document.parentDocuments?.length,
+ }));
+ }
+
+ if (crumbs.length < 2) {
return <>>;
}
@@ -27,8 +73,8 @@ export function Breadcrumbs({ path }: { path: string }): JSX.Element {