---
import BaseLayout from "../layouts/BaseLayout.astro"
import ArchivePostList from "../layouts/ArchivePostList.astro"
const allPosts = await Astro.glob("./posts/*.md")
const Blogs = await Astro.glob("../pages/posts/blogs/**/*.md")
const tags = ["寝室", "技术", "学习", "活动", "其他"]
const posts = []

tags.forEach((tag) => {
  const filteredPosts = allPosts.filter(post =>
    post.frontmatter.tags.includes(tag),
  )
  const filteredBlogs = Blogs.filter(
    post => post.frontmatter.tags?.includes(tag) ?? tag === "其他",
  )
  posts.push([...filteredPosts, ...filteredBlogs])
})
---

  <BaseLayout primaryTitle="归档">
    <section class="archive">
      <div class="section-content section-tag">
        {
        tags.map((tag, index) => {
          return (
            <div class="archive-tag">
              <h2 class="tag-header">{tag}</h2>
              <div class="tag-post-list">
                {posts[index].length !== 0
                  ? (
                    <ArchivePostList posts={posts[index]} />
                    )
                  : (
                    <div class="no-posts">暂无文章</div>
                    )}
              </div>
            </div>
          )
        })
      }
      </div>
    </section>
  </BaseLayout>
