-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate.js
121 lines (106 loc) · 2.96 KB
/
generate.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
const fs = require('fs')
const path = require('path')
const {init, end, generatePage, copyStatic} = require('sitio')
const md = require('markdown-it')({
html: true,
linkify: true,
breaks: true,
typographer: true
})
const themes = [
'cyprio',
'jeen',
'lebo',
'barbieri',
'wardrobe',
'subtle',
'zen',
'creative-portfolio',
'dbyll',
'ghostwriter',
'cocoa',
'numa'
]
async function main () {
await init({
themes
})
await generatePage('/', 'sitio/component-utils/article.js', {
html: md.render(fs.readFileSync('introduction.md', 'utf-8')),
data: {
name: 'Introduction'
}
})
await generatePage('/for-cms-makers', 'sitio/component-utils/article.js', {
html: md.render(fs.readFileSync('for-cms-makers.md', 'utf-8')),
data: {
name: 'For CMS makers'
}
})
await generatePage('/for-personal-websites', 'sitio/component-utils/article.js', {
html: md.render(fs.readFileSync('for-personal-websites.md', 'utf-8')),
data: {
name: 'For personal websites'
}
})
await generatePage('/for-theme-writers', 'sitio/component-utils/article.js', {
html: md.render(fs.readFileSync('for-theme-writers.md', 'utf-8')),
data: {
name: 'For theme writers'
}
})
let scenarios = fs.readdirSync('scenarios')
.map(filename => ({
name: filename.split('.')[0],
html: fs.readFileSync(path.join('scenarios', filename), 'utf-8')
}))
.filter(({name}) => name)
await generatePage('/scenarios', 'scenarios.js', {
scenarioList: scenarios.map(scn => scn.name)
})
scenarios.forEach(async scn => {
await generatePage('/scenarios/' + scn.name, 'scenarios.js', {
chosen: scn,
scenarioList: scenarios.map(scn => scn.name)
})
})
// themes pages
var screenshots = {}
for (let i = 0; i < themes.length; i++) {
let theme = themes[i]
screenshots[theme] = fs.readdirSync(path.join('themes', theme, 'screenshots'))
.map(filename => path.join('themes', theme, 'screenshots', filename))
}
for (let theme in screenshots) {
await generatePage('/themes/' + theme, 'show-theme.js', {
theme,
descHTML: md.render(
fs.readFileSync(path.join('themes', theme, 'desc.md'), 'utf-8')
),
screenshots: [
screenshots[theme].filter(n => n.endsWith('article.png'))[0],
screenshots[theme].filter(n => n.endsWith('list.png'))[0],
screenshots[theme].filter(n => n.endsWith('article-mobile.png'))[0],
screenshots[theme].filter(n => n.endsWith('list-mobile.png'))[0]
]
})
}
await generatePage('/themes', 'sitio/component-utils/list.js', {
root: '/',
basepath: '/themes',
items: Object.keys(screenshots)
.map(theme => ({
path: path.join('themes', theme),
name: theme,
cover: '/' + screenshots[theme].filter(n => n.endsWith('list.png'))[0]
})),
page: 1
})
await copyStatic([
'*.css',
'CNAME',
'themes/*/screenshots/*'
])
await end()
}
main()