-
Notifications
You must be signed in to change notification settings - Fork 1
/
gatsby-node.js
65 lines (56 loc) · 2.1 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const path = require('path');
const fs = require('fs');
exports.createPages = async ({ actions }) => {
const { createPage, createRedirect } = actions;
const projectTemplate = path.resolve('src/templates/capstone-showcase-template.js');
// Read all JSON files in the projects_data directory
const projectDataDir = path.resolve('src/pages/capstone-showcase/projects_data');
const files = fs.readdirSync(projectDataDir);
// Custom sort function to order semesters correctly
const semesterOrder = { 'spring': 1, 'fall': 2 };
const jsonFiles = files.filter(file => file.endsWith('.json')).sort((a, b) => {
const [semesterA, yearA] = a.replace('.json', '').split('-');
const [semesterB, yearB] = b.replace('.json', '').split('-');
if (yearA === yearB) {
return semesterOrder[semesterA] - semesterOrder[semesterB];
}
return yearA - yearB;
});
const latestSemesterFile = jsonFiles[jsonFiles.length - 1];
jsonFiles.forEach(file => {
const semester = file.replace('.json', '');
const filePath = path.resolve(projectDataDir, file);
const fileContent = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
console.log(`Creating page for ${semester} with data:`, fileContent); // Debugging line
createPage({
path: `/capstone-showcase/${semester}`,
component: projectTemplate,
context: {
projects: fileContent,
},
});
});
// Redirect the base path to the latest semester
console.log(`Redirecting from /capstone-showcase to /capstone-showcase/${latestSemesterFile.replace('.json', '')}`);
createRedirect({
fromPath: '/capstone-showcase/',
toPath: `/capstone-showcase/${latestSemesterFile.replace('.json', '')}`,
// toPath: `/capstone-showcase/fall-2024`,
isPermanent: true,
redirectInBrowser: true,
});
};
exports.onCreateWebpackConfig = ({ stage, loaders, actions }) => {
if (stage === "build-html" || stage === "develop-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /react-google-slides/,
use: loaders.null(),
},
],
},
})
}
}