committed by
GitHub
parent
de040e6727
commit
27659baca6
.github/workflows
netlify.tomlsimple-cms-icon.pngwebsite
.babelrc.gitignore.markdownlint.json.nvmrcREADME.md
data
gatsby-browser.jsgatsby-config.jsgatsby-node.jspackage.jsonsite.ymlsrc
cms
components
blog-post-template.jsbutton.jschat-button.jscommunity-channels-list.jscommunity.jscontainer.jsdocs-nav.jsdocs-template.jsdocsearch.jsedit-link.jsevent-box.jsfeatures.jsfooter.jsgithub-button.jsgrid.jsheader.jshero-title.jshome-section.jslayout.jslead.jsmarkdown.jsmarkdownify.jsmeta-info.jsnotification.jsnotifications.jspage-hero.jspage.jsrelease.jssection-label.jssidebar-layout.jstable-of-contents.jstwitter-meta.jsvideo-embed.jswhats-new.jswidget-doc.jswidgets.js
global-styles.jshtml.jsimg
bow.svgcollab.svgdemo.giffeature-access.svgfeature-editor.svgfeature-workflow.svggithub.svgheart.svghelix.svgnetlify-logo.svgplay.svgscreenshot-content.pngscreenshot-editor.jpgscreenshot-editor.pngscreenshot-editorial.pngscreenshot-identity.pngsearch.svgsimple-cms-logo.svgsmashing-logo.svgwavy-divider.svg
pages
templates
theme.jsutils.jswriting-guide
static
.keep_redirects
yarn.lockadmin
img
11ty-logo.svgcloudinary-console-details.pngcreate-password.pngemail-subject.png
favicon
apple-touch-icon.pngbrowserconfig.xmlfavicon-16x16.pngfavicon-32x32.pngfavicon.icoicon-512x512.pngmstile-144x144.pngmstile-150x150.pngmstile-310x150.pngmstile-310x310.pngmstile-70x70.pngsafari-pinned-tab.svg
gatsby.svggithub-statuses-deploy-previews.pnghugo.svghugo_shortcode_gist.pngmetalsmith.svgmiddleman.svgnextjs.svgnuxt.svgpreact.svgpreview-link-check.pngpreview-link-published.pngpreview-link-unpublished.pngscreen shot 2018-01-05 at 4.25.07 pm.pngscreen-shot-2020-08-20-at-14.36.26.pngscreen-shot-2021-11-15-at-4.16.53-pm.pngscreen-shot-2021-11-16-at-1.34.18-PM.pngscreenshot-jekyll-tutorial-blog.pngsimple-cms-external-media-library.pngsimple-cms.pngslack.pngslack.svguc-logo-horizontal.svgwidgets-markdown.PNG
104
website/gatsby-node.js
Normal file
104
website/gatsby-node.js
Normal file
@ -0,0 +1,104 @@
|
||||
const path = require('path');
|
||||
const { createFilePath } = require('gatsby-source-filesystem');
|
||||
|
||||
exports.createPages = async ({ graphql, actions }) => {
|
||||
const { createPage } = actions;
|
||||
|
||||
const docPage = path.resolve('./src/templates/doc-page.js');
|
||||
const blogPost = path.resolve('./src/templates/blog-post.js');
|
||||
|
||||
// get all markdown with a frontmatter path field and title
|
||||
const allMarkdown = await graphql(`
|
||||
{
|
||||
allMarkdownRemark(filter: { frontmatter: { title: { ne: null } } }) {
|
||||
edges {
|
||||
node {
|
||||
fields {
|
||||
slug
|
||||
}
|
||||
frontmatter {
|
||||
title
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
|
||||
if (allMarkdown.errors) {
|
||||
console.error(allMarkdown.errors); // eslint-disable-line no-console
|
||||
throw Error(allMarkdown.errors);
|
||||
}
|
||||
|
||||
allMarkdown.data.allMarkdownRemark.edges.forEach(({ node }) => {
|
||||
const { slug } = node.fields;
|
||||
|
||||
let template = docPage;
|
||||
|
||||
if (slug.includes('blog/')) {
|
||||
template = blogPost;
|
||||
}
|
||||
|
||||
createPage({
|
||||
path: slug,
|
||||
component: template,
|
||||
context: {
|
||||
slug,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function pad(n) {
|
||||
return n >= 10 ? n : `0${n}`;
|
||||
}
|
||||
|
||||
exports.onCreateNode = ({ node, actions, getNode }) => {
|
||||
const { createNodeField } = actions;
|
||||
|
||||
if (node.internal.type === 'MarkdownRemark') {
|
||||
const value = createFilePath({ node, getNode });
|
||||
const { relativePath } = getNode(node.parent);
|
||||
|
||||
let slug = value;
|
||||
|
||||
if (relativePath.includes('blog/')) {
|
||||
const date = new Date(node.frontmatter.date);
|
||||
const year = date.getFullYear();
|
||||
const month = date.getMonth() + 1;
|
||||
const filename = path.basename(relativePath, '.md');
|
||||
slug = `/blog/${year}/${pad(month)}/${filename}`;
|
||||
|
||||
createNodeField({
|
||||
node,
|
||||
name: 'date',
|
||||
value: date.toJSON(),
|
||||
});
|
||||
}
|
||||
|
||||
// used for doc posts
|
||||
createNodeField({
|
||||
node,
|
||||
name: 'slug',
|
||||
value: slug,
|
||||
});
|
||||
|
||||
// used to create GitHub edit link
|
||||
createNodeField({
|
||||
node,
|
||||
name: 'path',
|
||||
value: relativePath,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
exports.onCreateWebpackConfig = ({ actions }) => {
|
||||
actions.setWebpackConfig({
|
||||
resolve: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
alias: {
|
||||
moment$: 'moment/moment.js',
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user