Skip to content

Generate challenges redirects/shortcuts at build time #1556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions node-scripts/generate-challenges-redirects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { appendFileSync } = require('node:fs');
const { slugs } = require('../content-testing/content');

let challengesRedirects = '\n';
slugs.challenges.forEach((slug) => {
const videoNumber = slug.split('-')[0];
challengesRedirects += `/${videoNumber} /challenges/${slug} 302!\n`;
});

const redirectsFilePath = './static/_redirects';
appendFileSync(redirectsFilePath, challengesRedirects);

console.log(
`${slugs.challenges.size} challenges redirects were appended to '${redirectsFilePath}'`
);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"dev": "gatsby develop -H 0.0.0.0",
"build": "gatsby build --verbose",
"build-ci": "npm run tags-transforms && npm run build",
"build-ci": "node node-scripts/generate-challenges-redirects && npm run tags-transforms && npm run build",
"serve": "gatsby serve",
"clean": "gatsby clean",
"test": "jest",
Expand Down
9 changes: 4 additions & 5 deletions static/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

# shortcuts - 302


/flock-view https://editor.p5js.org/codingtrain/sketches/fFNCIQw4e 302!
/decade https://donorbox.org/to-the-power-of-10 302!
/noc https://nostarch.com/nature-code 302!
Expand Down Expand Up @@ -62,7 +61,7 @@
/p5js /tracks/code-programming-with-p5-js 302!
/processing /tracks/learning-processing 302!
/genuary1 https://editor.p5js.org/codingtrain/sketches/vN8EEr59I 302!
/particles https://thecodingtrain.com/challenges/78-simple-particle-system 302!
/ca https://thecodingtrain.com/challenges/179-wolfram-ca 302!
/182 https://thecodingtrain.com/challenges/182-apollonian-gasket 302!
/180 https://thecodingtrain.com/challenges/180-falling-sand 302!
/particles /challenges/78-simple-particle-system 302!
/ca /challenges/179-wolfram-ca 302!

# challenges shortcuts will be appended to this file at build time as /{videoNumber} -> /challenges/{slug}
Loading