-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
918d073
commit fc0e583
Showing
5 changed files
with
40 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
interface Props { | ||
tagAmounts: Record<string, number>; | ||
className?: string; | ||
} | ||
const { tagAmounts, className } = Astro.props; | ||
--- | ||
|
||
<span class={className}> | ||
{ | ||
Object.entries(tagAmounts) | ||
.sort((a, b) => b[1] - a[1]) | ||
.map(([tag, count], i) => ( | ||
<> | ||
<a | ||
href={`/tags/${tag}`} | ||
class="hover:underline" | ||
aria-label={`Posts tagged ${tag}`} | ||
>{`${tag}(${count})`}</a> | ||
{i < Object.entries(tagAmounts).length - 1 && ", "} | ||
</> | ||
)) | ||
} | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
--- | ||
import LatestPosts from "../../components/LatestPosts.astro"; | ||
import Tags from "../../components/Tags.astro"; | ||
import TagList from "../../components/TagList.astro"; | ||
import BaseLayout from "../../layouts/BaseLayout.astro"; | ||
import { getCollection } from "astro:content"; | ||
const posts = await getCollection("posts"); | ||
const tags = posts.flatMap((post) => post.data.tags); | ||
const tagAmounts = tags.reduce( | ||
(acc, tag) => { | ||
acc[tag] = (acc[tag] || 0) + 1; | ||
return acc; | ||
}, | ||
{} as Record<string, number> | ||
); | ||
--- | ||
|
||
<BaseLayout title="Altuğ's Blog"> | ||
<h1 class="text-4xl font-bold text-center mb-6">Latest Posts</h1> | ||
<LatestPosts count={5} /> | ||
<h1 class="text-4xl font-bold text-center my-6">Tags</h1> | ||
<p class="flex flex-row flex-wrap gap-2"> | ||
<Tags tags={posts.flatMap((post) => post.data.tags)} /> | ||
<TagList {tagAmounts} /> | ||
</p> | ||
</BaseLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters