forked from kjj6198/build-your-own-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
32 lines (27 loc) · 892 Bytes
/
script.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
require('svelte/register');
const showdown = require('showdown');
const ejs = require('ejs');
const fs = require('fs');
const path = require('path');
const AppComponent = require('./src/App.svelte').default;
const Model = require('./Model');
// make github compatible:
// Build your own `compiler` -> build-your-own-compiler
const converter = new showdown.Converter({ ghCompatibleHeaderId: true });
const content = fs.readFileSync(path.resolve(__dirname, 'README.md'));
const model = new Model(converter.makeHtml(content.toString()));
const { html, head } = AppComponent.render({
data: model.serialize(),
});
ejs
.renderFile(path.resolve(__dirname, 'public', './index.ejs'), {
html,
head,
data: model.toJSON(),
lang: 'zh-TW',
})
.then((html) => {
fs.writeFileSync(path.resolve(__dirname, 'public', 'index.html'), html, {
encoding: 'utf8',
});
});