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