-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
199 lines (165 loc) · 5.43 KB
/
index.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
const fs = require('fs')
const fse = require('fs-extra')
const glob = require('glob')
const moment = require('moment')
const path = require('path')
const {createFile, createLink} = require('ritter')
const {plugins: {render, raw, read, markdown, minifyCss, minifyHtml, yamlFrontMatter}} = require('ritter')
const doc = createFile({
baseUrl: 'https://i.love.software/',
copyright: '© David Herrmann',
color: '#49045f',
description: 'code by David Herrmann',
menu: [
{name: 'Blog', url: 'blog/'}
],
source: './site',
title: 'I ♡ SOFTWARE'
})
const dependencies = []
const link = createLink(dependencies)
const preventCaching = url => url + '?v=aljv5RGPao'
const header = ({configuration, file}) => `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<link rel="apple-touch-icon" sizes="180x180" href="${preventCaching(link(doc('apple-touch-icon.png', raw())))}">
<link rel="icon" type="image/png" href="${preventCaching(link(doc('favicon-32x32.png', raw())))}" sizes="32x32">
<link rel="icon" type="image/png" href="${preventCaching(link(doc('favicon-16x16.png', raw())))}" sizes="16x16">
<link rel="manifest" href="${preventCaching(link(doc('manifest.json', read())))}">
<link rel="mask-icon" href="${preventCaching(link(doc('safari-pinned-tab.svg', read())))}" color="${configuration.color}">
<link rel="shortcut icon" href="${preventCaching(link(doc('favicon.ico', raw())))}">
<meta name="apple-mobile-web-app-title" content="${configuration.title}">
<meta name="application-name" content="${configuration.title}">
<meta name="theme-color" content="${configuration.color}">
<base href="${configuration.baseUrl}">
<title>
${file.meta.title
? file.meta.title + ' · ' + configuration.title
: configuration.title}
</title>
<!-- TODO canonical link, rss link, language in html and body-->
<style>${doc('css/theme.css', read(), minifyCss()).content}</style>
<script async src="${link(doc('js/calc-results.js', read()))}"></script>
</head>
<body>
`
const sidebar = ({configuration, file}) => `
<div class="sidebar">
<div class="container">
<div class="sidebar-about">
<a href="${configuration.baseUrl}">
<h1>
I <i class="icon" aria-hidden="true">${doc('images/heart-o.svg', read()).content}</i> SOFTWARE
</h1>
</a>
<p class="lead">
${configuration.description}
</p>
</div>
<ul class="sidebar-nav">
<li><a href="/">Home</a></li>
${configuration.menu.map(({name, url}) => `
<li><a href="${url}">${name}</a></li>
`).join('')}
</ul>
<p class="footnote">${configuration.copyright}</p>
</div>
</div>
`
const footer = context => `
</body>
</html>
`
const frame = context => `
${header(context)}
${sidebar(context)}
<div class="content container">
${context.file.content}
</div>
${footer(context)}
`
const normalise = link => link.replace(/index.html$/, '')
const index = () => context => Object.assign({}, context, {
file: Object.assign({}, context.file, {
path: context.file.path.replace(/.html$/, '/index.html')
})
})
const post = ({showLink} = {}) => ({file}) => `
<div class="post">
<h1 class="post-title">
${showLink
? `<a href="${normalise(link(doc(file, render(post()), render(frame), index(), minifyHtml())))}">
${file.meta.title}
</a>`
: `${file.meta.title}`
}
</h1>
<span class="post-date">${moment(file.meta.date).format('LL')}</span>
${file.content}
</div>
`
const blogFiles = configuration => glob.sync('blog/*.md', {cwd: configuration.source})
const posts = ({configuration}) => `
<div class="posts">
${blogFiles(configuration)
.map(path =>
doc(path,
read(),
yamlFrontMatter(),
markdown(),
render(post({showLink: true})),
minifyHtml()).content)
.join('')}
</div>
`
const title = title => context => Object.assign({}, context, {
file: Object.assign({}, context.file, {
meta: Object.assign({}, context.file.meta, {
title
})
})
})
const postListItem = ({file}) => `
<li>
<span>
<a href="${file.path}">${file.meta.title}</a>
<time class="pull-right post-list">${moment(file.meta.date).format('LL')}</time>
</span>
</li>
`
const postList = ({configuration, file}) => `
<h1 class="title">${file.meta.title}</h1>
<ul class="posts">
${blogFiles(configuration)
.map(path =>
doc(path,
read(),
yamlFrontMatter(),
render(postListItem)).content).join('')}
</ul>
`
link(doc('blog/index.html', title('Blog'), render(postList), render(frame)))
const homeFile = doc('index.html', render(context => `
${header(context)}
${sidebar(context)}
<div class="content container">
${posts(context)}
</div>
${footer(context)}
`), minifyHtml())
link(homeFile)
link(doc('CNAME', read()))
link(doc('google01a0df28d4492e88.html', read()))
link(doc('mstile-150x150.png', raw()))
link(doc('android-chrome-192x192.png', raw()))
link(doc('android-chrome-512x512.png', raw()))
console.log(dependencies.map(file => file.path))
const writeTargetFile = file => {
const targetPath = path.join('public', file.path)
fse.mkdirsSync(path.dirname(targetPath))
fs.writeFileSync(targetPath, file.content)
}
dependencies.forEach(writeTargetFile)