|
| 1 | +--- |
| 2 | +import { getCollection } from 'astro:content'; |
| 3 | +import BaseLayout from '../layouts/BaseLayout.astro'; |
| 4 | +
|
| 5 | +const posts = (await getCollection('blog')) |
| 6 | + .filter(post => !post.data.isDraft); |
| 7 | +
|
| 8 | +const tagCountMap = new Map<string, number>(); |
| 9 | +
|
| 10 | +for (const post of posts) { |
| 11 | + for (const tag of post.data.tags ?? []) { |
| 12 | + const normalized = tag.toLowerCase(); |
| 13 | + tagCountMap.set(normalized, (tagCountMap.get(normalized) ?? 0) + 1); |
| 14 | + } |
| 15 | +} |
| 16 | +
|
| 17 | +const tags = Array.from(tagCountMap.entries()) |
| 18 | + .map(([tag, count]) => ({ tag, count })) |
| 19 | + .sort((a, b) => b.count - a.count || a.tag.localeCompare(b.tag, 'tr')); |
| 20 | +
|
| 21 | +const title = 'Tüm Etiketler'; |
| 22 | +const description = 'Blogdaki tüm konu etiketlerini ve yazı sayılarını keşfedin.'; |
| 23 | +--- |
| 24 | + |
| 25 | +<BaseLayout title={title} description={description}> |
| 26 | + <section class="tags-page"> |
| 27 | + <div class="tags-head"> |
| 28 | + <h1>{title}</h1> |
| 29 | + <a href="/" class="back-link">← Ana sayfa</a> |
| 30 | + </div> |
| 31 | + |
| 32 | + <p class="tags-subtitle">Toplam <strong>{tags.length}</strong> etiket var. Bir etikete tıklayarak arşivde filtreleyebilirsin.</p> |
| 33 | + |
| 34 | + <div class="tags-grid"> |
| 35 | + {tags.map((item) => ( |
| 36 | + <a href={`/blog?tag=${item.tag}`} class="tag-card"> |
| 37 | + <span>#{item.tag}</span> |
| 38 | + <strong>{item.count}</strong> |
| 39 | + </a> |
| 40 | + ))} |
| 41 | + </div> |
| 42 | + </section> |
| 43 | +</BaseLayout> |
| 44 | + |
| 45 | +<style> |
| 46 | + .tags-page { max-width: 900px; margin: 0 auto; } |
| 47 | + .tags-head { display:flex; align-items:center; justify-content:space-between; gap:1rem; margin-bottom: 0.75rem; } |
| 48 | + .tags-head h1 { margin: 0; font-size: 2rem; } |
| 49 | + .back-link { font-weight: 600; } |
| 50 | + .tags-subtitle { color: var(--secondary); margin-bottom: 1.25rem; } |
| 51 | + .tags-grid { display:flex; flex-wrap:wrap; gap:0.75rem; } |
| 52 | + .tag-card { |
| 53 | + display:inline-flex; |
| 54 | + align-items:center; |
| 55 | + gap:0.55rem; |
| 56 | + border:1px solid var(--border); |
| 57 | + background: var(--card-bg); |
| 58 | + padding:0.6rem 0.95rem; |
| 59 | + border-radius:999px; |
| 60 | + text-decoration:none; |
| 61 | + color:var(--text); |
| 62 | + transition: all .2s ease; |
| 63 | + } |
| 64 | + .tag-card:hover { border-color: var(--accent); transform: translateY(-2px); } |
| 65 | + .tag-card strong { color: var(--accent); } |
| 66 | +</style> |
0 commit comments