-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgatsby-node.js
More file actions
121 lines (114 loc) · 4.09 KB
/
gatsby-node.js
File metadata and controls
121 lines (114 loc) · 4.09 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const fsExtra = require('fs-extra');
const {
DOC_NAV_PAGE_ID,
NOT_FOUND_PAGE_ID,
} = require('./src/configs/doc-configs');
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 {
sourceInstanceName: sourceName,
relativePath: relPath,
} = edge.node.parent;
// Tutorials module pageids follow pattern {subdirectory}_{final_url_stub} to give unique IDs in system but allow directory structure in URL
if (sourceName === 'tutorials') {
// One-level of subdirectory part of stub
const relPathSplit = relPath.split('/');
const pageIdSplit = pageId.split('__');
let finalPageId = pageId;
if (pageIdSplit.length > 1) {
finalPageId = pageIdSplit[1];
}
let finalPath = `/tutorials/${finalPageId}`;
if (relPathSplit.length > 1) {
finalPath = `/tutorials/${relPathSplit[0]}/${finalPageId}`;
}
actions.createPage({
path: finalPath,
component: require.resolve(
'./src/components/DevDocTemplate/index.tsx',
),
context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap },
});
} else if (relPath.startsWith('10.5')) {
actions.createPage({
path: `/10.5/${pageId}`,
component: require.resolve(
'./src/components/DevDocTemplate/index.tsx',
),
context: { pageId, navId: DOC_NAV_PAGE_ID, namePageIdMap },
});
} else {
actions.createPage({
path: `/${pageId}`,
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 },
});
}
});
};