diff --git a/nx-dev/data-access-documents/src/lib/documents.api.ts b/nx-dev/data-access-documents/src/lib/documents.api.ts index afcccf9a0eac4..23db3f9c0440d 100644 --- a/nx-dev/data-access-documents/src/lib/documents.api.ts +++ b/nx-dev/data-access-documents/src/lib/documents.api.ts @@ -75,11 +75,28 @@ export class DocumentsApi { if (!found) return null; + function interpolateUrl( + el: { id: string; path?: string }, + ancestorPath + ): string { + const isLinkExternal: (p: string) => boolean = (p: string) => + p.startsWith('http'); + const isLinkAbsolute: (p: string) => boolean = (p: string) => + p.startsWith('/'); + + // Using internal path or Constructing it from id (default behaviour) + if (!el.path) return '/' + ancestorPath.concat(el.id).join('/'); + // Support absolute & external paths + if (isLinkAbsolute(el.path) || isLinkExternal(el.path)) return el.path; + // Path is defined to point towards internal target, just use the value + return '/' + el.path; + } + const cardsTemplate = items ?.map((i) => ({ title: i.name, description: i.description ?? '', - url: '/' + (i.path ?? path.concat(i.id).join('/')), + url: interpolateUrl({ id: i.id, path: i.path }, path), })) .map( (card) => diff --git a/nx-dev/nx-dev/next.config.js b/nx-dev/nx-dev/next.config.js index ef023892ecfd9..d63c05b021e1c 100644 --- a/nx-dev/nx-dev/next.config.js +++ b/nx-dev/nx-dev/next.config.js @@ -204,6 +204,15 @@ module.exports = withNx({ permanent: true, }); + // Packages Indexes + for (let s of Object.keys(redirectRules.packagesIndexes)) { + rules.push({ + source: s, + destination: redirectRules.packagesIndexes[s], + permanent: true, + }); + } + // Docs rules.push({ source: '/docs', diff --git a/nx-dev/nx-dev/redirect-rules.config.js b/nx-dev/nx-dev/redirect-rules.config.js index d36dd931a899f..2f137056baa22 100644 --- a/nx-dev/nx-dev/redirect-rules.config.js +++ b/nx-dev/nx-dev/redirect-rules.config.js @@ -392,6 +392,33 @@ for (const path of oldAngularTutorialPaths) { tutorialRedirects[path] = angularRedirectDestination; } +const packagesIndexes = { + '/nx': '/packages/nx', + '/workspace': '/packages/workspace', + '/devkit': '/packages/devkit', + '/nx-plugin': '/packages/nx-plugin', + '/angular': '/packages/angular', + '/cypress': '/packages/cypress', + '/detox': '/packages/detox', + '/esbuild': '/packages/esbuild', + '/eslint-plugin-nx': '/packages/eslint', + '/expo': '/packages/expo', + '/express': '/packages/express', + '/jest': '/packages/jest', + '/js': '/packages/js', + '/linter': '/packages/linter', + '/nest': '/packages/nest', + '/next': '/packages/next', + '/node': '/packages/node', + '/react': '/packages/react', + '/react-native': '/packages/react', + '/rollup': '/packages/rollup', + '/storybook': '/packages/storybook', + '/vite': '/packages/vite', + '/web': '/packages/web', + '/webpack': '/packages/webpack', +}; + /** * Public export API */ @@ -404,4 +431,5 @@ module.exports = { nxCloudUrls, schemaUrls, tutorialRedirects, + packagesIndexes, };