Skip to content

Commit b33499d

Browse files
committed
Filter articles list view page by featured tags, add redirect from /tags to /articles
1 parent bad9f79 commit b33499d

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎astro.config.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ export default defineConfig({
117117
{ protocol: 'http' },
118118
],
119119
},
120+
redirects: {
121+
'/tags': '/articles',
122+
},
120123
/** Change URL between development and production environments */
121124
site: getSiteUrl(),
122125
trailingSlash: 'never',

‎src/pages/articles/index.astro‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ import Carousel from '@components/Carousel/index.astro'
88
const allArticles = await getCollection('articles', ({ data }) => isDev() || data.isDraft !== true)
99
1010
const allTags = await getCollection('tags')
11+
const featuredTags = allTags.filter(tag => tag.data.featured === true)
1112
1213
const getArticlesForTag = (tagEntry: CollectionEntry<'tags'>) => {
1314
return allArticles.filter(article => {
1415
return article.data.tags.some(tagRef => tagRef.id === tagEntry.id)
1516
})
1617
}
1718
18-
const tagsWithContent = allTags.filter(tag => getArticlesForTag(tag).length > 0)
19+
const tagsWithContent = featuredTags.filter(tag => getArticlesForTag(tag).length > 0)
1920
2021
const tagsWithNoContent = allTags.filter(tag => getArticlesForTag(tag).length === 0)
2122
@@ -25,8 +26,8 @@ for (const tag of tagsWithNoContent) {
2526
)
2627
}
2728
28-
const pageDescription = 'Browse all article tags'
29-
const pageTitle = 'All Tags'
29+
const pageDescription = 'Browse all articles by tag'
30+
const pageTitle = 'All Articles'
3031
const path = '/tags'
3132
const section = 'Tags'
3233
---

0 commit comments

Comments
 (0)