-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
executable file
·77 lines (69 loc) · 1.93 KB
/
gatsby-node.js
File metadata and controls
executable file
·77 lines (69 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const path = require(`path`);
const util = require("util");
const glob = require("glob");
const fs = require("fs");
const md5 = require("md5");
const hash = md5(`${new Date().getTime()}`);
const addPageDataVersion = async (file) => {
const stats = await util.promisify(fs.stat)(file);
if (stats.isFile()) {
console.log(`Adding version to page-data.json in ${file}..`);
let content = await util.promisify(fs.readFile)(file, "utf8");
const result = content.replace(
/page-data.json(\?v=[a-f0-9]{32})?/g,
`page-data.json?v=${hash}`
);
await util.promisify(fs.writeFile)(file, result, "utf8");
}
};
exports.onPostBootstrap = async () => {
const loader = path.join(
__dirname,
"node_modules/gatsby/cache-dir/loader.js"
);
await addPageDataVersion(loader);
};
exports.onPostBuild = async () => {
const publicPath = path.join(__dirname, "public");
const htmlAndJSFiles = glob.sync(`${publicPath}/**/*.{html,js}`);
for (let file of htmlAndJSFiles) {
await addPageDataVersion(file);
}
};
/**
* Here is the place where Gatsby creates the URLs for all the
* posts, tags, pages and authors that we fetched from the Contentful.
*/
exports.createPages = async ({ actions, graphql }) => {
const { createPage } = actions;
const result = await graphql(`
{
caseStudies: allContentfulCaseStudy(
sort: { datePublished: DESC }
filter: {
publishLocation: {
elemMatch: {
urlLocation: { eq: "https://sdv.dev/community-case-studies/" }
}
}
}
) {
edges {
node {
url
}
}
}
}
`);
const caseStudies = result.data.caseStudies.edges;
caseStudies.forEach(({ node }) => {
createPage({
path: `/community-case-studies/${node.url}/`,
component: require.resolve(`./src/templates/CaseStudy.js`),
context: {
url: node.url,
},
});
});
};