From 9c434c3425421a1cf69dc14fdc36e2d4bda262e2 Mon Sep 17 00:00:00 2001 From: ppst Date: Fri, 7 Apr 2023 09:10:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=8D=95=E8=8E=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/index.js | 39 ++++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index a9f6680..6fbeb8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "markdown-from-posts", - "version": "1.0.5", + "version": "1.0.6", "description": "从posts文件夹中读取文件,根据时间,category,tags进行排列", "main": "src/index.js", "exports": { diff --git a/src/index.js b/src/index.js index b35ba5d..f95e4c1 100644 --- a/src/index.js +++ b/src/index.js @@ -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) { + + } + } }