remove pug
This commit is contained in:
1 parent
e397c9ae1e
commit
68840c9c60
49 files changed
+1421
-806
No files matched your search
@@ -4,8 +4,9 @@ import yaml from 'js-yaml'
|
||||
import rimraf from 'rimraf'
|
||||
|
||||
import { Database, IMatter } from '../server/db'
|
||||
import { builtPath, dstMediaPath } from '../server/dir'
|
||||
import { THEME_FILENAME } from '../server/theme'
|
||||
import { builtPath, dstMediaPath, srcPath } from './dir'
|
||||
import { srcPath } from './dir'
|
||||
import { MakeHTML } from './make-html'
|
||||
|
||||
async function main() {
|
||||
@@ -17,40 +18,38 @@ async function main() {
|
||||
|
||||
await fs.copyFile(srcPath(THEME_FILENAME), builtPath(THEME_FILENAME))
|
||||
|
||||
const db = new Database(builtPath('data.db'))
|
||||
const db = new Database()
|
||||
db.init()
|
||||
|
||||
const files = await fg('**/*.md', {
|
||||
cwd: srcPath('_post'),
|
||||
cwd: srcPath('_posts'),
|
||||
})
|
||||
|
||||
// eslint-disable-next-line array-callback-return
|
||||
files.map((f) => {
|
||||
const path = f.replace(/\.md$/, '')
|
||||
let markdown = fs.readFileSync(srcPath('_post', f), 'utf8')
|
||||
const makeHtml = new MakeHTML()
|
||||
|
||||
const [h, c = ''] = markdown.substr(4).split(/---\n(.*)$/s)
|
||||
const header = yaml.safeLoad(h, {
|
||||
schema: yaml.JSON_SCHEMA,
|
||||
}) as IMatter
|
||||
markdown = c
|
||||
await Promise.all(
|
||||
files.map(async (f) => {
|
||||
const path = f.replace(/\.md$/, '')
|
||||
const markdown = fs.readFileSync(srcPath('_posts', f), 'utf8')
|
||||
|
||||
const makeHtml = new MakeHTML(path)
|
||||
const [h] = markdown.substr(4).split(/---\n(.*)$/s)
|
||||
const header = yaml.safeLoad(h) as IMatter
|
||||
|
||||
const content = makeHtml.clean(markdown)
|
||||
const excerptHtml = makeHtml.parse(
|
||||
markdown.split(/<!-- excerpt(?:_separator)? -->/)[0]
|
||||
)
|
||||
const contentHtml = makeHtml.parse(markdown)
|
||||
const r = await makeHtml.parse(srcPath('_posts', f))
|
||||
const contentHtml = r.html()
|
||||
const excerptHtml = contentHtml.split(
|
||||
/<!-- excerpt(?:_separator)? -->/
|
||||
)[0]
|
||||
|
||||
db.insert({
|
||||
...header,
|
||||
path,
|
||||
content,
|
||||
excerptHtml,
|
||||
contentHtml,
|
||||
db.insert({
|
||||
...header,
|
||||
path,
|
||||
content: r.clean(),
|
||||
excerptHtml,
|
||||
contentHtml,
|
||||
})
|
||||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
|
||||
Reference in new issue
Block a user