forked from jenkins-infra/contributor-spotlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
88 lines (83 loc) · 2.9 KB
/
gatsby-node.js
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
78
79
80
81
82
83
84
85
86
87
88
const _ = require(`lodash`);
const path = require(`path`);
const { slash } = require(`gatsby-core-utils`);
const { createFilePath } = require(`gatsby-source-filesystem`);
// Implement the Gatsby API “createPages”. This is
// called after the Gatsby bootstrap is finished, so you have
// access to any information necessary to programmatically
// create pages.
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
// The “graphql” function allows us to run arbitrary
// queries against the local Drupal graphql schema. Think of
// it like the site has a built-in database constructed
// from the fetched data that you can run queries against.
return graphql(`
{
allAsciidoc(limit: 1000) {
edges {
node {
id
html
document {
title
main
}
fields {
slug
}
pageAttributes {
datepublished
name
pronouns
location
firstcommit
linkedin
twitter
github
email
image
featured
intro
}
}
}
}
}
`).then((result) => {
if (result.errors) {
throw result.errors;
}
// Create Asciidoc pages.
const articleTemplate = path.resolve(
`./src/templates/contributor-details.jsx`
);
_.each(result.data.allAsciidoc.edges, (edge) => {
// Gatsby uses Redux to manage its internal state.
// Plugins and sites can use functions like "createPage"
// to interact with Gatsby.
createPage({
// Each page is required to have a `path` as well
// as a template component. The `context` is
// optional but is often necessary so the template
// can query data specific to each page.
path: edge.node.fields.slug,
component: slash(articleTemplate),
context: {
id: edge.node.id,
},
});
});
});
};
exports.onCreateNode = async ({ node, actions, getNode, loadNodeContent }) => {
const { createNodeField } = actions;
if (node.internal.type === `Asciidoc`) {
const value = createFilePath({ node, getNode });
createNodeField({
name: `slug`,
node,
value,
});
}
};