This commit is contained in:
Pacharapol Withayasakpunt committed 2020-02-28 13:03:53 +07:00
1 parent 3bc2a943bd
commit e3fbe853df
12 files changed
+280 -53

No files matched your search

+11 -4
View File
@@ -47,6 +47,8 @@ const db = new DataStore('assets/data.nedb')
...data,
date: formatDate(data.date),
filename: f,
type,
slug: f.replace(/^slides\//, '').replace(/\.md$/, ''),
h,
excerpt: computedExcerpt,
slides
@@ -66,14 +68,19 @@ const db = new DataStore('assets/data.nedb')
computedContent = computedContent.substr(computedExcerpt.length)
}
if (data.date) {
console.log(formatDate(data.date))
}
await db.insert({
...data,
date: formatDate(data.date),
filename: f,
type: f.split('/')[0],
slug: f.startsWith('posts/blog/')
? f.replace(/^posts\/blog\//, '').replace(/\.md$/, '')
: f.startsWith('posts/')
? (() => {
const ff = f.split('/')
return ff[ff.length - 1].replace(/\.md$/, '')
})()
: f.replace(/^[^/]+?\//, '').replace(/\.md$/, ''),
h,
excerpt: computedExcerpt,
remaining: computedContent
+6 -6
View File
@@ -24,30 +24,30 @@ dataRouter.get('/*', (req, res) => {
}
})
dataRouter.post('/', async (req, res, next) => {
dataRouter.post('/:type', async (req, res, next) => {
try {
const { q, cond = {}, project, offset, limit } = req.body
const $and = [
{ filename: { $regex: /^posts\// } },
{ type: req.params.type },
cond
] as any[]
]
if (q) {
const parser = new QSearch({
dialect: 'nedb',
schema: {
title: {},
filename: {},
slug: {},
excerpt: {},
date: { type: 'date' }
}
})
$and.push(parser.parse(q))
$and.push(parser.parse(q).cond)
}
const count = await db.count({ $and })
let c = db.find({ $and }, project).skip(offset || 0)
let c = db.find({ $and }, project).sort({ date: -1 }).skip(offset || 0)
if (limit !== null) {
c = c.limit(limit || 5)
+2
View File
@@ -9,6 +9,8 @@ export default class MakeHtml {
})
constructor (public id = 'el-' + Math.random().toString(36).substr(2)) {
this.md.setFlavor('github')
this.md.addExtension({
type: 'lang',
filter (text) {