-
Notifications
You must be signed in to change notification settings - Fork 52
/
static.config.js
107 lines (101 loc) · 3.25 KB
/
static.config.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import hashSum from 'hash-sum';
import marked from 'marked';
import path from 'path';
import slugify from 'slugify';
const BASE_URL = 'https://pokeapi.co/api';
export default {
plugins: [
'react-static-plugin-react-router',
['react-static-plugin-google-tag-manager', {id: 'GTM-MD89GGQ'}],
],
minLoadTime: 200,
getSiteData: () => {
let alerts = require('./alerts.json');
if (!Array.isArray(alerts)) {
console.error(
'/alerts.json must contain an array of alert objects'
);
alerts = [];
}
return {
alerts: alerts
.filter(alert => alert.active !== false)
.map(alert => ({
htmlMessage: marked(alert.message),
level: alert.level || 'info',
id: hashSum(alert),
})),
};
},
getRoutes: async () => {
return [
{
path: '404',
template: 'src/pages/404.js',
},
{
path: '/',
template: 'src/pages/index.js',
},
{
path: '/about',
template: 'src/pages/about.js',
},
{
path: '/docs/',
template: 'src/pages/docs.js',
},
{
path: '/docs/v1',
template: 'src/pages/docs/v1.js',
},
{
path: '/docs/v2',
template: 'src/pages/docs/v2.js',
getData: async () => {
let docs = require('./src/docs/index.js').default;
return {
docs: processDocs(docs),
};
},
},
{
path: '/docs/graphql',
template: 'src/pages/docs/graphql.js',
}
];
},
};
function processDocs(docs) {
return docs.map(doc => ({
name: doc.name,
id: slugify(doc.name, {lower: true}) + '-section',
htmlDescription: doc.description ? marked(doc.description) : null,
resources: doc.resources?.map(resource => ({
name: resource.name,
id: slugify(resource.name, {lower: true}),
htmlDescription: resource.description
? marked(resource.description)
: null,
exampleRequest: resource.exampleRequest ? BASE_URL + resource.exampleRequest : null,
exampleResponse: resource.exampleResponse
? JSON.parse(
JSON.stringify(resource.exampleResponse, null, 2).replace(
/\$BASE_URL/g,
BASE_URL
)
)
: null,
responseModels: resource.responseModels.map(model => ({
name: model.name,
id: slugify(model.name, {lower: true}),
fields: model.fields.map(field => ({
name: field.name,
htmlDescription: marked(field.description),
type: field.type,
})),
})),
})),
endOfSection: doc.endOfSection,
}));
}