Skip to content

Commit

Permalink
docs(nxdev): fix root level card links (#13555)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcabanes committed Dec 2, 2022
1 parent 0187000 commit 63820a9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
19 changes: 18 additions & 1 deletion nx-dev/data-access-documents/src/lib/documents.api.ts
Expand Up @@ -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) =>
Expand Down
9 changes: 9 additions & 0 deletions nx-dev/nx-dev/next.config.js
Expand Up @@ -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',
Expand Down
28 changes: 28 additions & 0 deletions nx-dev/nx-dev/redirect-rules.config.js
Expand Up @@ -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
*/
Expand All @@ -404,4 +431,5 @@ module.exports = {
nxCloudUrls,
schemaUrls,
tutorialRedirects,
packagesIndexes,
};

1 comment on commit 63820a9

@vercel
Copy link

@vercel vercel bot commented on 63820a9 Dec 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-git-master-nrwl.vercel.app
nx-dev-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.