This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/gatsby-node.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-06-20 08:08:44 +00:00
import ModuleOrdering, { divisions } from './content/ordering';
2020-06-15 23:19:07 +00:00
exports.createPages = async ({ actions }) => {
2020-06-20 08:10:27 +00:00
const { createPage } = actions;
2020-06-15 23:19:07 +00:00
2020-06-20 08:10:27 +00:00
// Generate Module Pages //
const moduleTemplate = require.resolve(`./src/templates/moduleTemplate.tsx`);
Object.keys(ModuleOrdering).forEach(division => {
const processItem = item => {
if (typeof item === 'object') {
// this is a nested module
item.items.forEach(x => processItem(x));
} else {
createPage({
path: `/${division}/${item}`,
component: moduleTemplate,
context: {
// additional data can be passed via context
id: item,
division: division,
},
});
}
};
ModuleOrdering[division].forEach(item => processItem(item));
});
// End Generate Module Pages //
2020-06-17 01:39:47 +00:00
2020-06-20 08:10:27 +00:00
// Generate Syllabus Pages //
const syllabusTemplate = require.resolve(
`./src/templates/syllabusTemplate.tsx`
2020-06-20 08:10:27 +00:00
);
divisions.forEach(division => {
createPage({
path: `/${division}`,
component: syllabusTemplate,
context: {
division: division,
},
});
});
// End Generate Syllabus Pages //
2020-06-15 23:19:07 +00:00
};
exports.createSchemaCustomization = ({ actions }) => {
2020-06-20 08:10:27 +00:00
const { createTypes } = actions;
const typeDefs = `
2020-06-22 16:29:47 +00:00
type MdxFrontmatter implements Node {
2020-06-22 20:51:12 +00:00
prerequisites: [String]
2020-06-15 23:19:07 +00:00
}
`;
2020-06-20 08:10:27 +00:00
createTypes(typeDefs);
2020-06-20 08:08:44 +00:00
};