|
|
@ -4,23 +4,28 @@ const fs = require('fs-extra')
|
|
|
|
const path = require('path')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = { getPosts:async()=>{
|
|
|
|
module.exports = { getPosts:async()=>{
|
|
|
|
let paths = await getPostMDFilePaths()
|
|
|
|
try {
|
|
|
|
let posts = await Promise.all(
|
|
|
|
let paths = await getPostMDFilePaths()
|
|
|
|
paths.map(async (item) => {
|
|
|
|
let posts = await Promise.all(
|
|
|
|
const content = await fs.readFile(item, 'utf-8')
|
|
|
|
paths.map(async (item) => {
|
|
|
|
const { data } = matter(content)
|
|
|
|
const content = await fs.readFile(item, 'utf-8')
|
|
|
|
const description = data.title?data.title:'这是一个简短描述,但是这篇随笔没有描述。'
|
|
|
|
const { data } = matter(content)
|
|
|
|
data.description = data.description?data.description:description
|
|
|
|
const description = data.title?data.title:'这是一个简短描述,但是这篇随笔没有描述。'
|
|
|
|
data.date = _convertDate(data.date)
|
|
|
|
data.description = data.description?data.description:description
|
|
|
|
data.category = data.category?data.category:data.tags[0]
|
|
|
|
data.date = _convertDate(data.date)
|
|
|
|
return {
|
|
|
|
data.category = data.category?data.category:data.tags[0]
|
|
|
|
frontMatter: data,
|
|
|
|
return {
|
|
|
|
regularPath: `/${item.replace('.md', '.html')}`
|
|
|
|
frontMatter: data,
|
|
|
|
}
|
|
|
|
regularPath: `/${item.replace('.md', '.html')}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
})
|
|
|
|
posts.sort(_compareDate)
|
|
|
|
)
|
|
|
|
return posts
|
|
|
|
posts.sort(_compareDate)
|
|
|
|
|
|
|
|
return posts
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} }
|
|
|
|
} }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|