Skip to content

Commit

Permalink
Better code for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
Princesseuh committed Dec 19, 2021
1 parent ced667e commit f54fbe0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/pages/articles/tags/[tag]/[...page].astro
Expand Up @@ -10,14 +10,10 @@ export async function getStaticPaths({ paginate }) {
return b.date.getTime() - a.date.getTime()
})
const tagList = new Set()
articles.forEach((article) => {
article.tags.forEach((tag) => {
tagList.add(tag)
})
})
const tags = articles.flatMap((article) => [...article.tags])
const uniqueTags = [...new Set<string>(tags)]
return Array.from(tagList).map((tag) => {
return uniqueTags.map((tag) => {
const filteredArticles = articles.filter((article) => article.tags.includes(tag))
return paginate(filteredArticles, { params: { tag }, pageSize: 6 })
})
Expand Down

0 comments on commit f54fbe0

Please sign in to comment.