-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
93 lines (83 loc) · 2.39 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
89
90
91
92
93
import path from 'path';
async function createTranscriptPage({ actions, graphql, reporter }) {
const templates = {
wom: path.resolve(`src/templates/womTranscript.js`),
pwom: path.resolve(`src/templates/pwomTranscript.js`),
raj: path.resolve(`src/templates/rajTranscript.js`),
oe: path.resolve(`src/templates/oeTranscript.js`),
sp: path.resolve(`src/templates/spTranscript.js`),
acol: path.resolve(`src/templates/acolTranscript.js`),
jsb: path.resolve(`src/templates/jsbTranscript.js`),
};
const { createPage } = actions;
const { data, errors } = await graphql(`
query {
transcripts: allMarkdownRemark {
nodes {
fileAbsolutePath
id
}
}
}
`);
if (errors) {
reporter.panicOnBuild(
`Error while running GraphQL query when creating Transcript Page.`
);
return;
}
data.transcripts.nodes.forEach((node) => {
const SOURCE_ROOT = `${__dirname}/src/sources`;
const filePath = node.fileAbsolutePath.slice(SOURCE_ROOT.length, -3);
const parts = filePath.substring(1).split('/');
// normalize parts, filePath will be either
// /lang/group/source/book/unit or
// /lang/source/book/unit
if (parts.length === 4) {
parts.splice(1, 0, 'group');
}
// get source, book, and unit from path
const [, , source, book, unit] = parts;
if (templates[source]) {
createPage({
path: filePath,
component: templates[source],
context: {
id: node.id,
slug: filePath,
source,
book,
regex: `/${book}/`,
timingBase: `/${book}/${unit}/`,
},
});
}
});
}
export async function createPages(parms) {
await Promise.all([createTranscriptPage(parms)]);
}
// exports.onCreatePage = ({ page, actions }) => {
// const { createPage } = actions;
// // notice the addition of .*
// if (page.path.match(/^\/.*\/cmi/)) {
// // notice page.context.language
// page.matchPath = `/${page.context.language}/cmi/*`;
// createPage(page);
// }
// };
/*
* Get out of memory error when building on Netlify when project includes fomantic-ui
export function onCreateWebpackConfig({ actions }) {
actions.setWebpackConfig({
resolve: {
alias: {
'../../theme.config$': path.join(
__dirname,
'src/fomantic-less/theme.config'
),
},
},
});
}
*/