Created
March 26, 2020 06:46
-
-
Save dim2k2006/7b9c84f0087fcdc3422244045ff94aed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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