Skip to content

Commit 8ab0d52

Browse files
authored
Merge pull request #1556 from fturmel/PR/generate-challenge-redirects
Generate challenges redirects/shortcuts at build time
2 parents e24c308 + 512a805 commit 8ab0d52

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const { appendFileSync } = require('node:fs');
2+
const { slugs } = require('../content-testing/content');
3+
4+
let challengesRedirects = '\n';
5+
slugs.challenges.forEach((slug) => {
6+
const videoNumber = slug.split('-')[0];
7+
challengesRedirects += `/${videoNumber} /challenges/${slug} 302!\n`;
8+
});
9+
10+
const redirectsFilePath = './static/_redirects';
11+
appendFileSync(redirectsFilePath, challengesRedirects);
12+
13+
console.log(
14+
`${slugs.challenges.size} challenges redirects were appended to '${redirectsFilePath}'`
15+
);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"dev": "gatsby develop -H 0.0.0.0",
1313
"build": "gatsby build --verbose",
14-
"build-ci": "npm run tags-transforms && npm run build",
14+
"build-ci": "node node-scripts/generate-challenges-redirects && npm run tags-transforms && npm run build",
1515
"serve": "gatsby serve",
1616
"clean": "gatsby clean",
1717
"test": "jest",

static/_redirects

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
# shortcuts - 302
2929

30-
3130
/flock-view https://editor.p5js.org/codingtrain/sketches/fFNCIQw4e 302!
3231
/decade https://donorbox.org/to-the-power-of-10 302!
3332
/noc https://nostarch.com/nature-code 302!
@@ -62,7 +61,7 @@
6261
/p5js /tracks/code-programming-with-p5-js 302!
6362
/processing /tracks/learning-processing 302!
6463
/genuary1 https://editor.p5js.org/codingtrain/sketches/vN8EEr59I 302!
65-
/particles https://thecodingtrain.com/challenges/78-simple-particle-system 302!
66-
/ca https://thecodingtrain.com/challenges/179-wolfram-ca 302!
67-
/182 https://thecodingtrain.com/challenges/182-apollonian-gasket 302!
68-
/180 https://thecodingtrain.com/challenges/180-falling-sand 302!
64+
/particles /challenges/78-simple-particle-system 302!
65+
/ca /challenges/179-wolfram-ca 302!
66+
67+
# challenges shortcuts will be appended to this file at build time as /{videoNumber} -> /challenges/{slug}

0 commit comments

Comments
 (0)