Skip to content

Commit cfa87ca

Browse files
committed
Add Downloads collection to tags page
1 parent db057aa commit cfa87ca

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

‎src/pages/tags/[tag].astro‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type ContentItem =
1212
| (CollectionEntry<'articles'> & { type: 'article' })
1313
| (CollectionEntry<'caseStudies'> & { type: 'case-study' })
1414
| (CollectionEntry<'services'> & { type: 'service' })
15+
| (CollectionEntry<'downloads'> & { type: 'download' })
1516
1617
export interface Props {
1718
content: ContentItem[]
@@ -29,12 +30,16 @@ export async function getStaticPaths() {
2930
const allServices = await getCollection('services', ({ data }) => {
3031
return isDev() || (isProd() && data.isDraft !== true)
3132
})
33+
const allDownloads = await getCollection('downloads', ({ data }) => {
34+
return isDev() || (isProd() && data.isDraft !== true)
35+
})
3236
3337
// Combine all content and extract unique tags
3438
const allContent = [
3539
...allArticles.map(item => ({ ...item, type: 'article' })),
3640
...allCaseStudies.map(item => ({ ...item, type: 'case-study' })),
3741
...allServices.map(item => ({ ...item, type: 'service' })),
42+
...allDownloads.map(item => ({ ...item, type: 'download' })),
3843
]
3944
4045
const uniqueTags = [...new Set(allContent.map(item => item.data.tags).flat())]
@@ -79,6 +84,13 @@ type ImageObject = { src: string; alt: string }
7984
const isImageObject = (img: unknown): img is ImageObject => {
8085
return typeof img === 'object' && img !== null && 'src' in img && 'alt' in img
8186
}
87+
88+
const typeMetadata = {
89+
article: { label: 'Article', badgeClass: 'bg-primary', hrefBase: 'articles' },
90+
'case-study': { label: 'Case Study', badgeClass: 'bg-success', hrefBase: 'case-studies' },
91+
service: { label: 'Service', badgeClass: 'bg-accent', hrefBase: 'services' },
92+
download: { label: 'Download', badgeClass: 'bg-secondary', hrefBase: 'downloads' },
93+
} as const
8294
---
8395

8496
<BaseLayout pageTitle={`${displayName} - Tag`} path={path}>
@@ -101,12 +113,11 @@ const isImageObject = (img: unknown): img is ImageObject => {
101113
paginatedContent.length > 0 ? (
102114
<>
103115
<section class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 lg:gap-12 mb-12">
104-
{paginatedContent.map(item => (
105-
<article class="bg-bg rounded-2xl shadow-lg hover:shadow-xl transition-all duration-300 hover:-translate-y-1 overflow-hidden group">
106-
<a
107-
href={`/${item.type === 'case-study' ? 'case-studies' : item.type === 'service' ? 'services' : 'articles'}/${item.id}`}
108-
class="block h-full"
109-
>
116+
{paginatedContent.map(item => {
117+
const typeMeta = typeMetadata[item.type]
118+
return (
119+
<article class="bg-bg rounded-2xl shadow-lg hover:shadow-xl transition-all duration-300 hover:-translate-y-1 overflow-hidden group">
120+
<a href={`/${typeMeta.hrefBase}/${item.id}`} class="block h-full">
110121
{'image' in item.data && item.data.image && (
111122
<div class="aspect-video overflow-hidden">
112123
<img
@@ -133,17 +144,9 @@ const isImageObject = (img: unknown): img is ImageObject => {
133144
<div class="p-6 space-y-4">
134145
<div class="flex items-center gap-3 text-sm">
135146
<span
136-
class={`px-3 py-1 rounded-full text-white font-medium ${
137-
item.type === 'article'
138-
? 'bg-primary'
139-
: item.type === 'case-study'
140-
? 'bg-success'
141-
: 'bg-accent'
142-
}`}
147+
class={`px-3 py-1 rounded-full text-white font-medium ${typeMeta.badgeClass}`}
143148
>
144-
{item.type === 'case-study'
145-
? 'Case Study'
146-
: item.type.charAt(0).toUpperCase() + item.type.slice(1)}
149+
{typeMeta.label}
147150
</span>
148151
<time class="text-text-muted">
149152
{item.data.publishDate.toLocaleDateString('en-US', {
@@ -191,8 +194,9 @@ const isImageObject = (img: unknown): img is ImageObject => {
191194
</div>
192195
</div>
193196
</a>
194-
</article>
195-
))}
197+
</article>
198+
)
199+
})}
196200
</section>
197201

198202
{/* Pagination */}

0 commit comments

Comments
 (0)