Skip to content

Instantly share code, notes, and snippets.

@dim2k2006
Created March 26, 2020 06:46
Show Gist options
  • Save dim2k2006/7b9c84f0087fcdc3422244045ff94aed to your computer and use it in GitHub Desktop.
Save dim2k2006/7b9c84f0087fcdc3422244045ff94aed to your computer and use it in GitHub Desktop.
const api = require('./src/api');
const routes = require('./src/routes');
const exportPathMap = async () => {
const categories = await api.getCategories();
const tags = categories
.map((category) => ({
...category,
tags: category.tags.map((tag) => ({ ...tag, categorySlug: category.link })),
}))
.reduce((accumulator, { tags: categoryTags }) => [...accumulator, ...categoryTags], []);
const posters = await api.getPosters();
const categoryPages = categories
.reduce((accumulator, category) => ({
...accumulator,
[routes.categoryPath(category.link)]: {
page: routes.categoryPattern(),
query: { cid: category.link },
},
}), {});
const tagPages = tags
.reduce((accumulator, tag) => ({
...accumulator,
[routes.tagPath(tag.categorySlug, tag.slug)]: {
page: routes.tagPattern(),
query: { cid: tag.categorySlug, tid: tag.slug },
},
}), {});
const posterPages = posters
.reduce((accumulator, poster) => ({
...accumulator,
[routes.posterPath(poster.id)]: {
page: routes.posterPattern(),
query: { pid: poster.id },
},
}), {});
return {
'/': { page: '/' },
'/licenses': { page: '/licenses' },
...categoryPages,
...tagPages,
...posterPages,
};
};
module.exports = exportPathMap;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment