仲恺不冷的个人博客

顺其自然,为所当为

博客搭建记录

使用 Qwik 框架搭建静态博客

export const getPosts = async (): Promise<PostSummary[]> => {
  const modules = await import.meta.glob("/src/routes/posts/**/index.md");
  const posts = await asyncMap(Object.keys(modules), async (path) => {
    const data = (await modules[path]()) as DocumentHeadProps;
    return {
      title: data.head.title || "",
      description:
        data.head.meta.find((m) => m.name === "description")?.content || "",
      date: data.head.frontmatter.date as string,
      permalink: data.head.frontmatter.permalink as string,
    };
  });

  return posts.sort((a, b) => {
    const dateA = new Date(a.date as string).getTime();
    const dateB = new Date(b.date as string).getTime();
    return dateB - dateA;
  });
};