From d5e4d90c8a2e7d171d6db67274613fb7266e6afb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=98=88=EC=A7=84?= Date: Fri, 17 Nov 2023 04:17:28 +0900 Subject: [PATCH] fix: sort recent post list by meta date --- .github/make-post-list.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/make-post-list.js b/.github/make-post-list.js index 3758f56..bb1ff1f 100644 --- a/.github/make-post-list.js +++ b/.github/make-post-list.js @@ -79,6 +79,7 @@ const getFileMeta = async (filePath) => { metadataJson[key] = value; } }); + metadataJson.filePath = filePath; return metadataJson; } else { @@ -96,19 +97,18 @@ const postCount = 5; stat: await getFileStat(path.join(process.cwd(), postBasePath, filePath)), })) ); - const filtered = fileStats - .sort(({ stat: a }, { stat: b }) => b.birthtimeMs - a.birthtimeMs) - .slice(0, postCount); const metas = await Promise.all( - filtered + fileStats .map(({ filePath }) => getFileMeta(getPostPath(filePath))) .filter(Boolean) ); - const posts = filtered.map(({ filePath, stat: { birthtime } }, index) => { + const filtered = metas + .sort((a, b) => new Date(b.date) - new Date(a.date)) + .slice(0, postCount); + const posts = filtered.map(({ filePath, index }) => { return { path: `${blogPath}/posts${filePath.replace(".mdx", "")}`, meta: metas[index], - birthtime, }; }); core.setOutput("posts", JSON.stringify(JSON.stringify(posts)));