Skip to content

Commit 3748e77

Browse files
committed
Refine homepage topics: show top 6 tags and add tags page
1 parent bea42c5 commit 3748e77

2 files changed

Lines changed: 83 additions & 2 deletions

File tree

src/pages/etiketler.astro

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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>

src/pages/index.astro

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const topicStats = Array.from(tagCountMap.entries())
3232
.map(([topic, count]) => ({ topic, count }))
3333
.sort((a, b) => b.count - a.count || a.topic.localeCompare(b.topic, 'tr'));
3434
35+
const featuredTopics = topicStats.slice(0, 6);
36+
const hiddenTopicCount = Math.max(topicStats.length - featuredTopics.length, 0);
37+
3538
const searchIndex = posts.map((post) => ({
3639
slug: post.slug,
3740
title: post.data.title,
@@ -73,14 +76,22 @@ const searchIndex = posts.map((post) => ({
7376
</section>
7477

7578
<section class="topics">
76-
<h2>Konu alanları</h2>
79+
<div class="topics-head">
80+
<h2>Konu alanları</h2>
81+
<a href="/etiketler" class="all-topics-link">Tüm Etiketleri Gör</a>
82+
</div>
7783
<div class="topic-chips">
78-
{topicStats.map((item) => (
84+
{featuredTopics.map((item) => (
7985
<a href={`/blog?tag=${item.topic}`} class="topic-chip">
8086
<span>#{item.topic}</span>
8187
<strong>{item.count}</strong>
8288
</a>
8389
))}
90+
{hiddenTopicCount > 0 && (
91+
<a href="/etiketler" class="topic-chip topic-chip-more">
92+
<span>+{hiddenTopicCount} daha</span>
93+
</a>
94+
)}
8495
</div>
8596
</section>
8697

@@ -310,9 +321,13 @@ const searchIndex = posts.map((post) => ({
310321
.featured-card h3 { font-size:1.1rem; margin:0.5rem 0; }
311322
.featured-card p { color: var(--secondary); font-size:0.95rem; }
312323

324+
.topics-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
325+
.topics-head h2 { margin-bottom: 0; text-align: left; }
326+
.all-topics-link { font-weight: 600; font-size: 0.92rem; }
313327
.topic-chips { display:flex; flex-wrap:wrap; gap:0.75rem; }
314328
.topic-chip { display:inline-flex; gap:0.55rem; align-items:center; border:1px solid var(--border); background:var(--card-bg); padding:0.55rem 0.85rem; border-radius:999px; text-decoration:none; color:var(--text); }
315329
.topic-chip strong { color: var(--accent); }
330+
.topic-chip-more { border-style: dashed; color: var(--secondary); }
316331

317332
.home-search-box { margin-bottom: 2rem; padding: 1rem; background: var(--card-bg); border: 1px solid var(--border); border-radius: 1rem; box-shadow: var(--shadow); }
318333
.home-search-label { display: block; font-weight: 600; margin-bottom: 0.5rem; }

0 commit comments

Comments
 (0)