This repository has been archived by the owner on Aug 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathstatic.config.js
174 lines (165 loc) · 5.77 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
const _ = require("lodash");
const { createSharedData } = require("react-static/node");
const siteData = require("./static-config-helpers/site-data");
const {
getDocs,
getFaq,
getIntroduction,
getGallery,
getGuides,
getCommonProps
} = require("./static-config-helpers/md-data-transforms");
const { stage, landerBasePath } = require("./static-config-helpers/constants");
// HMR for dev
// This is much slower when developing tons of things that _aren't_ content changes
if (stage === "development") {
const { rebuildRoutes } = require("react-static/node");
const chokidar = require("chokidar");
chokidar.watch("src/content/**/*.md").on("all", () => rebuildRoutes());
}
export default {
getSiteData: () => siteData,
paths: {
root: process.cwd(), // The root of your project. Don't change this unless you know what you're doing.
src: "src", // The source directory. Must include an index.js entry file.
// See app.js for how stage is used to make client-side routing resolve correctly by stage.
dist: stage === "staging" ? `dist/${landerBasePath}` : "dist", // The production output directory.
devDist: "tmp/dev-server", // The development scratch directory.
public: "public" // The public directory (files copied to dist during build)
},
generateSourceMaps: false,
basePath: landerBasePath,
stagingBasePath: landerBasePath,
devBasePath: "",
plugins: [
"react-static-plugin-react-router",
"react-static-plugin-sitemap",
"react-static-plugin-styled-components"
],
// eslint-disable-next-line max-statements
getRoutes: async () => {
const trueDocs = await getDocs();
const faq = await getFaq();
const introduction = await getIntroduction();
const gallery = await getGallery();
const guides = await getGuides();
const commonProps = await getCommonProps();
// sure we *happen* to sort by id as part of data ingestion right now, but it shouldn't create unexpected behavior
// if we ever change that.
const homeIntro = _.find(introduction, intro => intro.data.id === 0);
// only one file here, use a selector-style fn if that ever changes
const faqIntro = faq[0];
const commonPropsIntro = commonProps[0];
const orderById = items => _.orderBy(items, ["data.id"], ["asc"]);
const allSidebarItems = [
...introduction,
...faq,
...guides,
commonPropsIntro,
...trueDocs
];
const sidebarContent = allSidebarItems.reduce((av, cv, i, arr) => {
const category = cv.data.category;
if (category && Array.isArray(av[category])) {
av[category] = av[category].concat(cv);
} else {
av[category] = [].concat(cv);
}
if (i === arr.length - 1) {
Object.keys(av).forEach(k => (av[k] = orderById(av[k])));
}
return av;
}, {});
// I'll be honest, I too was disappointed when I realized the elegant pattern of ${parentSlug}/#${childSlug}
// would end up requiring the generation of several of the routes together in a way which felt hard to reason
// about up front and less tangible to modify later
const docSubroutes = commonProps.concat(introduction, trueDocs);
const convertToSidebarArray = content => {
const { charts, containers, more } = content;
return [
...introduction,
...faq,
...guides,
commonPropsIntro,
...charts,
...containers,
...more
];
};
const sbContent = convertToSidebarArray(sidebarContent);
const sharedSidebarContent = createSharedData(sbContent);
return [
{
path: "/",
template: "src/pages/index"
},
{
path: "/about",
template: "src/pages/about",
sharedData: { sidebarContent: sharedSidebarContent }
},
{
// The "/guides" URL used to be a page, but is no longer. Because it is linked to from other documentation,
// do a redirect to the first guide.
path: "/guides",
template: "src/pages/redirect",
getData: () => {
const firstGuidePath = `/guides/${guides[0].data.slug}`;
return { redirect: firstGuidePath };
},
sharedData: { sidebarContent: sharedSidebarContent },
children: guides.map(g => ({
path: `/${g.data.slug}`,
template: g.component || "src/pages/docs-template",
getData: () => ({
doc: g,
title: `Victory | ${g.name}`,
sidebarContent: sbContent
})
}))
},
{
path: "/docs",
template: "src/pages/docs-template",
getData: () => ({
doc: homeIntro,
docs: trueDocs,
sidebarContent: sbContent
}),
children: docSubroutes.map(doc => ({
path: `/${doc.data.slug}`,
template: "src/pages/docs-template",
getData: () => ({ doc, sidebarContent: sbContent })
}))
},
{
path: "docs/faq",
template: "src/pages/docs-template",
getData: () => ({ doc: faqIntro, sidebarContent: sbContent })
},
{
path: "docs/common-props",
template: "src/pages/docs-template",
getData: () => ({ doc: commonPropsIntro, sidebarContent: sbContent })
},
{
path: "/gallery",
template: "src/pages/gallery",
getData: () => ({ gallery }),
sharedData: { sidebarContent: sharedSidebarContent },
children: gallery.map(galleryItem => ({
path: `/${galleryItem.data.slug}/`,
template: "src/pages/gallery-item-template",
getData: () => ({ galleryItem })
}))
},
// 404 Not Found
{
path: "/404",
template: "src/pages/404",
sharedData: { sidebarContent: sharedSidebarContent }
}
];
},
Document: require("./src/html").default
};