-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgatsby-node.js
87 lines (82 loc) · 2.75 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
const fsExtra = require('fs-extra');
const {
DOC_NAV_PAGE_ID,
NOT_FOUND_PAGE_ID,
} = require('./src/configs/doc-configs');
const { getDocLinkFromEdge } = require('./src/utils/gatsby-utils.js');
exports.onPostBuild = () => {
fsExtra.copyFileSync(
`${__dirname}/robots.txt`,
`${__dirname}/public/robots.txt`,
);
};
exports.createPages = async function ({ actions, graphql }) {
const { data } = await graphql(`
query {
allAsciidoc {
edges {
node {
html
document {
title
}
pageAttributes {
pageid
}
parent {
... on File {
name
sourceInstanceName
relativePath
}
}
}
}
}
}
`);
const namePageIdMap = {};
data.allAsciidoc.edges.forEach((e) => {
const {
sourceInstanceName: sourceName,
relativePath: relPath,
} = e.node.parent;
const pageId = e.node.pageAttributes.pageid;
if (sourceName === 'tutorials') {
const relPathSplit = relPath.split('/');
const pageIdSplit = pageId.split('__');
let finalPageId = pageId;
if (pageIdSplit.length > 1) {
finalPageId = pageIdSplit[1];
}
let mapPageId = `tutorials/${finalPageId}`;
if (relPathSplit.length > 1) {
mapPageId = `tutorials/${relPathSplit[0]}/${finalPageId}`;
}
namePageIdMap[e.node.parent.name] = mapPageId || NOT_FOUND_PAGE_ID;
} else {
namePageIdMap[e.node.parent.name] =
e.node.pageAttributes.pageid || NOT_FOUND_PAGE_ID;
}
});
data.allAsciidoc.edges.forEach((edge) => {
const { pageid: pageId } = edge.node.pageAttributes;
const docPath = getDocLinkFromEdge(edge);
actions.createPage({
path: docPath,
component: require.resolve(
'./src/components/DevDocTemplate/index.tsx',
),
context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap },
});
if (pageId === 'introduction') {
actions.createPage({
path: '/',
component: require.resolve(
'./src/components/DevDocTemplate/index.tsx',
),
context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap },
});
}
});
};