Skip to content

Commit

Permalink
docs(nxdev): add tutorial redirect rules (#14346)
Browse files Browse the repository at this point in the history
closes #14134
  • Loading branch information
bcabanes authored Jan 13, 2023
1 parent abfa864 commit 9e07cf4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
25 changes: 4 additions & 21 deletions nx-dev/nx-dev/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const path = require('path');
const redirectRules = require('./redirect-rules.config');

/**
* TODO@ben: Temporary solution before Nextjs' assets management tasks is up and running
* TODO@ben: Use watch method instead.
*/
copySync(
path.resolve(__dirname + '/../../docs'),
Expand Down Expand Up @@ -43,27 +43,10 @@ module.exports = withNx({
const rules = [];

// Tutorials
rules.push({
source: '/(l|latest)/(r|react)/tutorial/1-code-generation',
destination: '/react-tutorial/1-code-generation',
permanent: true,
});
rules.push({
source: '/(l|latest)/(a|angular)/tutorial/1-code-generation',
destination: '/angular-tutorial/1-code-generation',
permanent: true,
});
rules.push({
source: '/(l|latest)/(n|node)/tutorial/1-code-generation',
destination: '/node-tutorial/1-code-generation',
permanent: true,
});
for (const [source, destination] of Object.entries(
redirectRules.tutorialRedirects
)) {
for (let s of Object.keys(redirectRules.tutorialRedirects)) {
rules.push({
source,
destination,
source: s,
destination: redirectRules.tutorialRedirects[s],
permanent: true,
});
}
Expand Down
23 changes: 19 additions & 4 deletions nx-dev/nx-dev/redirect-rules.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,21 @@ const nxCloudUrls = {
};

/**
* Tutorial Updates
* Tutorial Updates (updated 2023-01-13)
*/
const tutorialBaseUrls = {
'/(l|latest)/(a|angular)/tutorial/1-code-generation':
'/getting-started/angular-standalone-tutorial',
'/(l|latest)/(a|node)/tutorial/1-code-generation':
'/getting-started/node-tutorial',
'/(l|latest)/(r|react)/tutorial/1-code-generation':
'/getting-started/react-standalone-tutorial',
'/angular-tutorial/1-code-generation':
'/getting-started/angular-standalone-tutorial',
'/node-tutorial/1-code-generation': '/getting-started/node-tutorial',
'/react-tutorial/1-code-generation':
'/getting-started/react-standalone-tutorial',
};
const oldReactTutorialPaths = [
'/react-tutorial/01-create-application',
'/react-tutorial/02-add-e2e-test',
Expand All @@ -349,7 +362,7 @@ const oldReactTutorialPaths = [
'/react-tutorial/11-test-affected-projects',
'/react-tutorial/12-summary',
];
const reactRedirectDestination = '/react-tutorial/1-code-generation';
const reactRedirectDestination = '/getting-started/react-standalone-tutorial';
const reactTutorialRedirects = oldReactTutorialPaths.reduce((acc, path) => {
acc[path] = reactRedirectDestination;
return acc;
Expand All @@ -364,12 +377,13 @@ const oldNodeTutorialPaths = [
'/node-tutorial/07-test-affected-projects',
'/node-tutorial/08-summary',
];
const nodeRedirectDestination = '/node-tutorial/1-code-generation';
const nodeRedirectDestination = '/getting-started/node-tutorial';
const nodeTutorialRedirects = oldNodeTutorialPaths.reduce((acc, path) => {
acc[path] = nodeRedirectDestination;
return acc;
}, {});
const tutorialRedirects = Object.assign(
tutorialBaseUrls,
reactTutorialRedirects,
nodeTutorialRedirects
);
Expand All @@ -389,7 +403,8 @@ const oldAngularTutorialPaths = [
'/angular-tutorial/12-summary',
];

const angularRedirectDestination = '/angular-tutorial/1-code-generation';
const angularRedirectDestination =
'/getting-started/angular-standalone-tutorial';
for (const path of oldAngularTutorialPaths) {
tutorialRedirects[path] = angularRedirectDestination;
}
Expand Down
6 changes: 3 additions & 3 deletions nx-dev/nx-dev/redirect-rules.config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Redirect rules configuration', () => {

for (const url of oldReactUrls) {
expect(redirectRules.tutorialRedirects[url]).toEqual(
'/react-tutorial/1-code-generation'
'/getting-started/react-standalone-tutorial'
);
}
});
Expand All @@ -60,7 +60,7 @@ describe('Redirect rules configuration', () => {

for (const url of oldAngularUrls) {
expect(redirectRules.tutorialRedirects[url]).toEqual(
'/angular-tutorial/1-code-generation'
'/getting-started/angular-standalone-tutorial'
);
}
});
Expand All @@ -79,7 +79,7 @@ describe('Redirect rules configuration', () => {

for (const url of oldNodeTutorialPaths) {
expect(redirectRules.tutorialRedirects[url]).toEqual(
'/node-tutorial/1-code-generation'
'/getting-started/node-tutorial'
);
}
});
Expand Down

1 comment on commit 9e07cf4

@vercel
Copy link

@vercel vercel bot commented on 9e07cf4 Jan 13, 2023

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-nrwl.vercel.app
nx-five.vercel.app
nx.dev
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.