Last active
April 30, 2018 00:46
-
-
Save stephensauceda/860f1a035d7fb1a5a280a6f765875a55 to your computer and use it in GitHub Desktop.
Export WordPress Posts to Static HTML with Next.js
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 fetch = require('isomorphic-unfetch') | |
const withSass = require('@zeit/next-sass') | |
module.exports = withSass({ | |
webpack: (config) => { | |
config.node = { fs: 'empty' } | |
return config | |
}, | |
exportPathMap: async (defaultPathMap) => { | |
const [postList, projectList, pageList] = await Promise.all([ | |
fetch(WP_POST_URL).then(res => res.json()), | |
fetch(WP_PROJECTS_URL).then(res => res.json()), | |
fetch(WP_PAGES_URL).then(res => res.json()) | |
]) | |
const posts = postList.reduce( | |
(pages, post) => | |
Object.assign({}, pages, { | |
[`/posts/${post.slug}`]: { | |
page: '/posts/show', | |
query: { slug: post.slug } | |
} | |
}), | |
{} | |
) | |
const projects = projectList.reduce( | |
(pages, project) => | |
Object.assign({}, pages, { | |
[`/work/${project.slug}`]: { | |
page: '/work/show', | |
query: { slug: project.slug } | |
} | |
}), | |
{} | |
) | |
const pages = pageList.reduce( | |
(list, page) => | |
Object.assign({}, list, { | |
[`/${page.slug}`]: { | |
page: '/page', | |
query: { slug: page.slug } | |
} | |
}), | |
{} | |
) | |
return Object.assign({}, posts, pages, projects, { | |
'/posts': { | |
page: '/posts' | |
}, | |
'/work': { | |
page: '/work' | |
}, | |
'/': { | |
page: '/index' | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment