-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.config.js
160 lines (137 loc) · 4.18 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
import fs from 'fs'
import axios from 'axios'
import React, { Component } from 'react'
import { ServerStyleSheet } from 'styled-components'
import SiteMetadata from './src/lib/siteMetadata'
import rssGen from './src/lib/rssGen'
import Env from './env'
const marked = require('marked')
export default {
getSiteProps: () => ({
title: 'David York',
metadata: SiteMetadata.metadata,
}),
siteRoot: Env.siteRoot,
getRoutes: async () => {
var getSiblings = (post) => {
var idx = 0;
var found = false;
for (var i = 0; i < SiteMetadata.posts.length && !found; i++) {
if (post == SiteMetadata.posts[i]) {
idx = i;
found = true;
}
}
var prevIdx = (idx - 1 < 0) ? SiteMetadata.posts.length - 1 : idx - 1;
var nextIdx = (idx + 1 >= SiteMetadata.posts.length) ? 0 : idx + 1;
var metaData = SiteMetadata.metadata;
var rv = {
prev: metaData[prevIdx],
next: metaData[nextIdx]
};
return rv;
};
var getPostsFromTag = (tag) => {
var rv = [];
var meta = SiteMetadata.metadata;
for (var i = 0; i < meta.length; i++) {
if ((meta[i].tags.indexOf(tag.tag) >= 0) || (meta[i].tags.indexOf(tag.title) >= 0)) {
rv.push(meta[i]);
}
}
return rv;
};
// These are top-level, not children of "domain.com/blog/..."
var postRoutes = SiteMetadata.metadata.map( meta => {
const siblings = getSiblings(meta.postname);
return {
path: meta.route,
component: 'src/containers/Post',
getProps: () => {
return {
markdown: meta.markdown,
metadata: meta,
next:siblings.prev,
prev:siblings.next
};
}
};
});
// These are the tags that describe groups of posts
var tagRoutes = SiteMetadata.tags.map( x => {
return {
path: 'tag/' + x.tag,
component: 'src/containers/TagFlow',
getProps: () => {
var props = {
tag: x,
posts: getPostsFromTag(x)
};
return props;
}
}
});
return [
{
path: '/',
component: 'src/containers/Home',
},
{
path: '/about',
component: 'src/containers/Page',
getProps: () => ({
markdown: marked(fs.readFileSync('./src/pages/about.md', 'utf-8')),
metadata: JSON.parse(fs.readFileSync('./src/pages/about.json', 'utf-8'))
})
},
{
path: '/test-blog',
component: 'src/containers/Blog',
getProps: () => ({
postRoutes,
}),
},
...tagRoutes,
...postRoutes,
{
is404: true,
component: 'src/containers/404',
},
];
},
renderToHtml: (render, Comp, meta) => {
const sheet = new ServerStyleSheet()
const html = render(sheet.collectStyles(<Comp />))
meta.styleTags = sheet.getStyleElement()
return html
},
onBuild: () => {
rssGen.Generate();
},
onStart: ({ devServerConfig }) => {
rssGen.Generate();
},
Document: class CustomHtml extends Component {
render () {
const { Html, Head, Body, children, renderMeta } = this.props
return (
<Html>
<Head>
<meta charSet="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>David York</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.11/semantic.min.css" />
<link rel="stylesheet" href="/css/davideyork.css" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="apple-touch-icon" href="/content/images/apple-touch-icon.png" />
<link rel="apple-touch-icon" sizes="72x72" href="/content/images/apple-touch-icon-72x72.png" />
<link rel="apple-touch-icon" sizes="114x114" href="/content/images/apple-touch-icon-114x114.png" />
<link rel="apple-touch-icon" sizes="144x144" href="/content/images/apple-touch-icon-144x144.png" />
{ renderMeta.styleTags }
</Head>
<Body>{ children }</Body>
</Html>
)
}
},
}