-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
195 lines (184 loc) · 6.94 KB
/
build.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
const handlebars = require('handlebars')
const { readFileSync, writeFileSync, readdirSync } = require('node:fs')
const { join } = require('node:path')
const galleries = require('./galleries.js')
const thisDomain = 'https://experibassmusic.eth.limo'
const wrappedLinkHelper = (text, url) => {
let target = ''
if (url.startsWith('https://') && !url.startsWith(thisDomain)) {
target = '_blank' // open external links in a new tab
}
return `<a href="${url}" target="${target}">${text}</a>`
}
const prefixedLinkHelper = (text, url) => {
let target = ''
let prefix = '//'
if (url.startsWith('https://') && !url.startsWith(thisDomain)) {
target = '_blank' // open external links in a new tab
//prefix += '/'
}
return `<a href="${url}" target="${target}">${prefix}${text}</a>`
}
handlebars.registerHelper('populategallery', (gallery) => {
let galleryHTML = ''
for (const img of gallery.images) {
const src = `${gallery.tld}${img.url}`
/// usse the image path without the file ext as the id
const divID = img.url.split('.').reverse().slice(1).join('.')
let source = `${img.credits || 'source unknown'}`
if (img.sourceURL) {
if (img.sourceURL.startsWith('https')) {
source = wrappedLinkHelper(img.credits || 'source', img.sourceURL)
}
}
galleryHTML +=
`<div class="img-container" id="${divID}">` +
`<a href="${src}">` +
`<img src="${src}"/>` +
'</a>' +
(img.desc ? `<p class="img-desc">${img.desc} ${source}</p>` : '') +
'</div>\n'
}
return galleryHTML.trim()
})
handlebars.registerHelper('wrappedlink', wrappedLinkHelper)
handlebars.registerHelper('hyperlink', prefixedLinkHelper)
handlebars.registerHelper('header', (maintext, subtext) => {
if (typeof subtext === 'string') {
subtext = subtext.trim().replace(/\\n/g, '<br>')
}
maintext = maintext.trim().replace(/\\n/g, '<br>')
return `
<div id='header'>
<div>
<h1>${handlebars.compile(maintext)()}</h1>
${typeof subtext === 'string' ? `<h2>${handlebars.compile(subtext)()}</h2>` : ''}
</div>
<hr />
</div>
`.trim()
})
handlebars.registerHelper('pawprint', () => {
return pawprint
.split(' ')
.map((chunk, i) => `<span>${chunk}</span>${(i + 1) % 5 ? '' : '<br />'}`)
.join(' ')
})
handlebars.registerHelper('cursorblink', () => {
return "<span class='cursor-blink'></span>"
})
process.chdir(__dirname)
const siteDir = join(__dirname, `./site`)
const viewsDir = join(siteDir, './src/views')
const layoutFileName = 'layout.handlebars'
const LAYOUT_FILE = readFileSync(`${viewsDir}/${layoutFileName}`, 'utf-8')
const LAYOUT = handlebars.compile(LAYOUT_FILE)
const pawprint = '33A8 1E0A 9FD6 6E1B 5D02 7649 5F47 E26A 5D22 1AEC'
const DRY_RUN = process.env['DRY_RUN']
const DEFAULT_CTX = {
themecolor: '#262638',
author: 'ΞXPΞRIBΛSS'
}
const ctx = {
index: {
tabtitle: 'Tandem vulpes vocem suam reperiet.',
desc: 'Stinky Lostkin has Claimed a Corner of the Internet',
stylesheets: ['<link rel="stylesheet" type="text/css" href="/src/styles/webrings.css" />'],
},
'cyberspace-independence': {
tabtitle: 'A Declaration of the Independence of Cyberspace',
desc:
'"A Declaration of the Independence of Cyberspace" is a widely distributed early paper ' +
'on the applicability (or lack thereof) of government to the rapidly growing Internet. ' +
'Commissioned for the pioneering Internet project 24 Hours in Cyberspace, ' +
'it was written by John Perry Barlow, a founder of the Electronic Frontier Foundation, ' +
'and published online on February 8, 1996, from Davos, Switzerland.',
author: 'John Perry Barlow',
keywords: ['cyberspace', 'independence'],
},
pixelsorts: {
tabtitle: 'Pixels Placed in (Dis)Order',
desc: 'organic Home-grown free-range pixelsorts',
stylesheets: ['<link rel="stylesheet" type="text/css" href="/src/styles/gallery.css" />'],
galleryImages: galleries.pixelsorts,
keywords: ['pixelsorting', 'pixelsort', 'glitch art'],
image: 'https://foxuments.experibassmusic.eth.limo/pixelsort-gens/boat-on-lake/final.jpg',
imageDims: { width: 1000, height: 1500 },
},
eve: {
tabtitle: 'Screenshots in Space',
desc: "When i'm not dyin, i'm killin and then dyin",
stylesheets: ['<link rel="stylesheet" type="text/css" href="/src/styles/gallery.css" />'],
galleryImages: galleries.eve,
keywords: ['eve online', 'screenshots'],
image: 'https://foxuments.experibassmusic.eth.limo/eve-screenshots/CataclysmicVariable.png',
imageDims: { width: 1280, height: 800 },
},
flags: {
tabtitle: 'Unified-pride-flags Flag Previews',
desc: 'Previews of the flags included in unified-pride-flags.',
author: '@KonkenBonken, @ExperiBass (GitHub)',
stylesheets: ['<link rel="stylesheet" type="text/css" href="/src/styles/flags.css" />'],
keywords: ['unified', 'cli', 'pride flags', 'lgbtqia'],
},
404: { tabtitle: 'Are You Lost? (404)', desc: 'Were you even Found?' },
rinkucomms: {
tabtitle: 'Rinku Inku Commission Sheet',
desc: "Rinku Inku's commission sheet.",
author: 'Rinku Inku',
themecolor: '#93E9BE',
stylesheets: ['<link rel="stylesheet" type="text/css" href="/src/styles/rinku.css" />'],
keywords: [],
},
}
function compileToHTML(page) {
const template = readFileSync(`${viewsDir}/${page}`, 'utf-8')
const templateName = page.split('.')[0]
const extra = {
...DEFAULT_CTX,
page: `${templateName}.html`,
...ctx[templateName],
}
extra.stylesheets ? extra.stylesheets = extra.stylesheets.join('') : null
let keywords = [
'⎇',
'ΘΔ',
'alterbeing',
'theriomythic',
'nonhuman',
'experibassmusic',
'ens',
'web3',
'true web3',
'assegai',
'cypherpunk',
]
if (extra.keywords) {
keywords.push(...extra.keywords)
}
extra.keywords = keywords
const body = handlebars.compile(template)
return {
name: extra.page,
content: LAYOUT({ body: body(extra), ...extra }),
}
}
const pages = readdirSync(viewsDir)
for (const page of pages.filter((v) => v.endsWith('.handlebars'))) {
if ([layoutFileName, 'menus.handlebars'].includes(page)) {
continue
}
const compiled = compileToHTML(page)
try {
if (!DRY_RUN) {
writeFileSync(`${siteDir}/${compiled.name}`, compiled.content)
}
console.log(page)
} catch (e) {
fatalError(e)
}
}
function fatalError(e) {
console.error(e)
process.exit(1)
}