refactor(v2): determine all available routes/url (#1264)

* refactor(v2): determine all available routes/url

* nits

* test(v2): routes snapshot

* sort for consistent snapshot test due to async ordering
This commit is contained in:
Endilie Yacop Sucipto 2019-03-07 02:51:16 +08:00 committed by Yangshun Tay
parent c73da00252
commit 2ad7413dd7
5 changed files with 114 additions and 41 deletions

View file

@ -5,7 +5,6 @@
* LICENSE file in the root directory of this source tree.
*/
const _ = require('lodash');
const path = require('path');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const webpackNiceLog = require('webpack-nicelog');
@ -22,25 +21,16 @@ module.exports = function createServerConfig(props) {
// Workaround for Webpack 4 Bug (https://github.com/webpack/webpack/issues/6522)
config.output.globalObject('this');
const {siteConfig, docsMetadatas, pagesMetadatas, contentsStore} = props;
const {siteConfig, routesPaths} = props;
// Static site generator webpack plugin.
const docsFlatMetadatas = Object.values(docsMetadatas);
// TODO: Generalize for blog plugin.
const blogPermalinks = _.get(contentsStore, ['blog', 'contents'], []);
const paths = [
...blogPermalinks,
...docsFlatMetadatas,
...pagesMetadatas,
].map(data => data.permalink);
config.plugin('siteGenerator').use(StaticSiteGeneratorPlugin, [
{
entry: 'main',
locals: {
baseUrl: siteConfig.baseUrl,
},
paths,
paths: routesPaths,
},
]);