-
Notifications
You must be signed in to change notification settings - Fork 0
/
static.config.js
executable file
·152 lines (144 loc) · 3.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
import axios from 'axios'
import path from 'path'
import { mkDir, mkFile } from './fs'
import fs from 'fs'
import { buildFeed, grabContents } from 'podcats'
// annoying to duplicate this code here from src/utils/prefixMp3
export const decorateURL = url =>
`https://${['dts.podtrac.com/redirect.mp3/', 'chtbl.com/track/9DG54/'].reduce(
(result, prefix) => `${prefix}${result}`,
url.substring(8), // remove https://
)}`
/// config
const myURL = 'https://seekjustice.fm'
const description =
'A weekly deep dive into Criminal Justice with Erik Rasmussen and Dennis Schrantz'
const image = 'https://seekjustice.fm/art.jpg'
const ghURL = 'https://github.com/erikras/seekjustice'
const rss = myURL + '/rss.xml'
const contentFolder = 'content'
const author = {
name: 'Erik Rasmussen and Dennis Schrantz',
email: 'seekjusticefm@gmail.com',
link: 'https://seekjustice.fm',
}
const feedOptions = {
// blog feed options
title: 'Seek Justice',
description,
link: myURL,
id: myURL,
copyright: 'Copyright – Erik Rasmussen and Dennis Schrantz',
decorateURL,
feedLinks: {
// atom: safeJoin(myURL, 'atom.xml'),
// json: safeJoin(myURL, 'feed.json'),
rss: 'https://seekjusticefm.netlify.com/rss.xml',
},
author,
}
const iTunesChannelFields = {
// itunes options
summary: 'Seek Justice',
author: author.name,
keywords: [
'Criminal Justice',
'Crime',
'Prison',
'Reform',
'Police',
'Jail',
'Justice',
'Politics',
],
categories: [
{ cat: 'News & Politics' },
{ cat: 'Society & Culture', child: 'Philosophy' },
],
image,
explicit: false,
owner: author,
type: 'episodic',
}
// preprocessing'
const filenames = fs.readdirSync(contentFolder).reverse() // reverse chron
const filepaths = filenames.map(file =>
path.join(process.cwd(), contentFolder, file),
)
const contents = grabContents(filepaths, myURL)
const frontmatters = contents.map(c => c.frontmatter)
// generate HTML
export default {
plugins: [
'react-static-plugin-styled-components',
'react-static-plugin-typescript',
],
entry: path.join(__dirname, 'src', 'index.tsx'),
siteRoot: myURL,
getSiteData: async () => {
// generate RSS
let feed = await buildFeed(
contents,
myURL,
author,
feedOptions,
iTunesChannelFields,
)
mkFile('/dist/rss.xml', feed.rss2())
// const replace = require('replace-in-file')
// await replace({
// files: 'dist/rss.xml',
// from: /seekjustice\.fm\/media\/001\.mp3/g,
// to:
// 'anchor.fm/s/28c46d0/podcast/play/2712062/https%3A%2F%2Fd3ctxlq1ktw2nl.cloudfront.net%2Fproduction%2F2019-2-22%2F11711811-44100-2-b79f339062d6b.mp3',
// })
return {
title: 'Seek Justice',
description,
rss,
frontmatters,
ghURL,
myURL,
image,
mostRecentEpisode: contents[0], // necessary evil to show on '/'
}
},
getRoutes: async () => {
return [
{
path: '/',
getData: () => ({
contents,
}),
children: contents.map(content => ({
path: `/${content.frontmatter.slug}`,
component: 'src/pages/episode',
getData: () => ({
content,
myURL,
}),
})),
},
{
path: '/card',
getData: () => ({
contents,
}),
children: contents.map(content => ({
path: `/${content.frontmatter.slug}`,
component: 'src/pages/card',
getData: () => ({
content,
myURL,
}),
})),
},
]
},
}
function safeJoin(a, b) {
/** strip starting/leading slashes and only use our own */
let a1 = a.slice(-1) === '/' ? a.slice(0, a.length - 1) : a
let b1 = b.slice(0) === '/' ? b.slice(1) : b
return `${a1}/${b1}`
}