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/src/utils.js
2020-06-20 01:08:44 -07:00

37 lines
856 B
JavaScript

import ModuleOrdering from '../content/ordering';
export const getModule = (allModules, division) => {
return ModuleOrdering[division].map(k => {
// rip spaghetti code, clean this up
if (typeof k === 'object') {
return {
name: k.name,
items: k.items.map(k2 => {
if (!allModules.hasOwnProperty(k2)) {
throw 'Module not found: ' + k2;
}
return {
...allModules[k2],
slug: `/${division}/${allModules[k2].frontmatter.id}`,
};
}),
};
} else {
if (!allModules.hasOwnProperty(k)) {
throw 'Module not found: ' + k;
}
return {
...allModules[k],
slug: `/${division}/${allModules[k].frontmatter.id}`,
};
}
});
};
export const graphqlToModulesObject = allMdx => {
return allMdx.edges.reduce((acc, cur) => {
acc[cur.node.frontmatter.id] = cur.node;
return acc;
}, {});
};