Skip to content

Commit

Permalink
fix: sort recent post list by meta date
Browse files Browse the repository at this point in the history
  • Loading branch information
ooooorobo committed Nov 16, 2023
1 parent e9a9284 commit d5e4d90
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions .github/make-post-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const getFileMeta = async (filePath) => {
metadataJson[key] = value;
}
});
metadataJson.filePath = filePath;

return metadataJson;
} else {
Expand All @@ -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)));
Expand Down

0 comments on commit d5e4d90

Please sign in to comment.