File watching

This commit is contained in:
Aaron Carlino 2019-11-18 17:51:57 +13:00
parent bf0a4aea46
commit ab377a35be
4 changed files with 35 additions and 30 deletions

View File

@ -12,13 +12,6 @@ module.exports = {
`gatsby-plugin-sass`, `gatsby-plugin-sass`,
`gatsby-plugin-sharp`, `gatsby-plugin-sharp`,
`gatsby-plugin-sitemap`, `gatsby-plugin-sitemap`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `files`,
path: `${__dirname}/static`
}
},
{ {
resolve: `gatsby-source-git`, resolve: `gatsby-source-git`,
options: { options: {
@ -37,6 +30,20 @@ module.exports = {
patterns: `docs/en/**` patterns: `docs/en/**`
} }
}, },
{
resolve: `gatsby-source-filesystem`,
options: {
name: `ss3-files`,
path: `${__dirname}/.cache/gatsby-source-git/3`
}
},
{
resolve: `gatsby-source-filesystem`,
options: {
name: `ss4-files`,
path: `${__dirname}/.cache/gatsby-source-git/4`
}
},
{ {
resolve: 'gatsby-transformer-remark', resolve: 'gatsby-transformer-remark',
options: { options: {
@ -45,7 +52,8 @@ module.exports = {
resolve: `gatsby-remark-prismjs`, resolve: `gatsby-remark-prismjs`,
options: { options: {
aliases: { aliases: {
ss: 'html', ss: `html`,
sh: `bash`,
} }
} }
}, },

View File

@ -1,7 +1,6 @@
const path = require('path'); const path = require('path');
const { createFilePath } = require(`gatsby-source-filesystem`); const { createFilePath } = require(`gatsby-source-filesystem`);
const fileToTitle = require('./src/utils/fileToTitle'); const fileToTitle = require('./src/utils/fileToTitle');
const crypto = require('crypto');
const createSlug = (filePath, version) => { const createSlug = (filePath, version) => {
const parts = filePath.split('/'); const parts = filePath.split('/');
@ -13,11 +12,10 @@ const createSlug = (filePath, version) => {
.toLowerCase() .toLowerCase()
}; };
exports.onCreateNode = async ({ node, getNode, actions }) => { exports.onCreateNode = async ({ node, getNode, actions, createContentDigest }) => {
if (node.internal.type !== 'MarkdownRemark') { if (node.internal.type !== 'MarkdownRemark') {
return; return;
} }
const { createNode } = actions; const { createNode } = actions;
const fileNode = getNode(node.parent); const fileNode = getNode(node.parent);
const version = fileNode.sourceInstanceName; const version = fileNode.sourceInstanceName;
@ -50,10 +48,10 @@ exports.onCreateNode = async ({ node, getNode, actions }) => {
const docInternal = { const docInternal = {
type: `SilverstripeDocument`, type: `SilverstripeDocument`,
contentDigest: crypto contentDigest: createContentDigest({
.createHash(`md5`) ...docData,
.update(JSON.stringify(docData)) rawMarkdownBody: node.rawMarkdownBody,
.digest(`hex`), }),
}; };
const nodeData = { const nodeData = {
...node, ...node,
@ -62,7 +60,6 @@ exports.onCreateNode = async ({ node, getNode, actions }) => {
parent: node.id, parent: node.id,
internal: docInternal, internal: docInternal,
} }
createNode(nodeData); createNode(nodeData);
}; };
@ -75,20 +72,8 @@ exports.createPages = async ({ actions, graphql }) => {
{ {
allSilverstripeDocument { allSilverstripeDocument {
nodes { nodes {
id
slug slug
parent {
... on MarkdownRemark {
parent {
... on File {
gitRemote {
sourceInstanceName
ref
webLink
}
}
}
}
}
} }
} }
}`); }`);
@ -103,6 +88,7 @@ exports.createPages = async ({ actions, graphql }) => {
path: node.slug, path: node.slug,
component: docTemplate, component: docTemplate,
context: { context: {
id: node.id,
slug: node.slug, slug: node.slug,
} }
}); });

View File

@ -9,7 +9,7 @@ const Template: StatelessComponent<SingleFileQuery> = (result): ReactElement =>
const currentNode = result.data.silverstripeDocument; const currentNode = result.data.silverstripeDocument;
const { html } = currentNode.parent; const { html } = currentNode.parent;
const { title, slug } = currentNode; const { title, slug } = currentNode;
const { relativePath, gitRemote: { ref, webLink, sourceInstanceName } } = currentNode.parent.parent; const { relativePath, gitRemote: { ref, webLink } } = currentNode.parent.parent;
const editLink = `${webLink}/edit/${ref}/${relativePath}`; const editLink = `${webLink}/edit/${ref}/${relativePath}`;
useEffect(() => { useEffect(() => {
setCurrentNode(slug); setCurrentNode(slug);

View File

@ -205,3 +205,14 @@ h1, h2, h3 {
} }
} }
:not(pre) > code[class*="language-"] {
background: #f5f6f8;
color: #5d6778;
text-shadow: none;
}
.algolia-autocomplete {
width: 100%;
}
.gatsby-highlight {
margin: 2rem 0;
}