Example list on each example page

This commit is contained in:
Tim Schaub
2018-05-12 14:04:19 -06:00
parent d33026d12c
commit ac9b0c7c9f
4 changed files with 134 additions and 26 deletions

View File

@@ -50,7 +50,15 @@ exports.createPages = async (
{graphql, boundActionCreators},
{sourceInstanceName, baseCss = ''}
) => {
const {createPage} = boundActionCreators;
const {createPage, createRedirect} = boundActionCreators;
createRedirect({
fromPath: `/examples/`,
isPermanent: false,
redirectInBrowser: true,
toPath: `/examples/map/`
});
const {data} = await graphql(`
{
allFile(
@@ -100,6 +108,7 @@ exports.createPages = async (
const embedDirName = 'example-embeds';
const embedDir = path.join(__dirname, '..', '..', 'public', embedDirName);
const exampleDir = path.join(__dirname, '..', '..', 'public', 'examples');
rollupCache = await bundle.write({
format: 'es',
@@ -108,6 +117,7 @@ exports.createPages = async (
});
const writes = [];
const index = {};
for (const name in examples) {
const node = examples[name].md;
@@ -162,6 +172,10 @@ exports.createPages = async (
writes.push(writeFile(path.join(embedDir, embedName), embed));
const slug = markdownNode.fields.slug;
index[name] = {
title: markdownNode.frontmatter.title,
slug
};
createPage({
path: slug,
@@ -177,5 +191,9 @@ exports.createPages = async (
});
}
writes.push(
writeFile(path.join(exampleDir, 'index.json'), JSON.stringify(index))
);
await Promise.all(writes);
};