-
Notifications
You must be signed in to change notification settings - Fork 0
/
11ty.js
73 lines (54 loc) · 1.47 KB
/
11ty.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
// Dynamic creation of speakers pages
const { spawn } = require('child_process')
const fetch = require('node-fetch')
const fs = require('fs')
const express = require('express')
const app = express()
const PORT = 3007
const STAPIURL = `http://localhost:1337`
const path = require('path')
const filendir = require('filendir')
const speakers = async () => {
await fetch(`${STAPIURL}/speakers`)
.catch((err) => {
console.error(err)
})
.then((res) => res.json())
.then((speakers) => {
console.log(`Found ${speakers.length} speaker(s)`)
for (const speaker of speakers) {
const { title, slug } = speaker
const content = `--- \ntitle: ${title}\ntags: speaker\n---\n`
try {
// const filename = `${slug}.md`
const filename = path.join('src', 'speakers', `${slug}.md`)
console.log(`Writing ${filename}`)
fs.writeFileSync(filename, content)
} catch (err) {
console.error(err)
}
}
})
}
const init = async () => {
await speakers()
let watcher = spawn('npm', ['run', 'build'])
watcher.stdout.on('data', (data) => {
console.log(`${data}`)
})
app.use(express.static('_site'))
app.get('/reload', async (req, res) => {
await services()
console.log('Rebuilding Eleventy')
watcher.kill()
watcher = spawn('npm', ['run', 'build'])
watcher.stdout.on('data', (data) => {
console.log(`${data}`)
})
return res.sendStatus(200)
})
app.listen(PORT, () =>
console.log(`Example app listening on port ${PORT}!`)
)
}
init()