diff --git a/src/lib/posts.ts b/src/lib/posts.ts index 0c31b6e..e5cbcf7 100644 --- a/src/lib/posts.ts +++ b/src/lib/posts.ts @@ -27,7 +27,7 @@ export async function getPosts(tag: string | null = null) { return posts; } -export async function getTags() { +export async function getTags() : Promise> { const allPostFiles = import.meta.glob('$content/post/*.md'); const iterablePostFiles = Object.entries(allPostFiles); @@ -37,5 +37,7 @@ export async function getTags() { return metadata.tags; }) ); - return new Set(allPosts.flat()); + return allPosts.flat().reduce((acc: Map, curr: string) => { + return acc[curr] ? ++acc[curr] : acc[curr] = 1, acc + }, new Map()); } diff --git a/src/routes/tag/+page.svelte b/src/routes/tag/+page.svelte index 4951f1d..7d60e17 100644 --- a/src/routes/tag/+page.svelte +++ b/src/routes/tag/+page.svelte @@ -13,8 +13,11 @@
- {#each allTags as tag} - {tag} + {#each Object.entries(allTags) as [tag, occ]} +
+ {tag} + ({occ}) +
{/each}

diff --git a/src/routes/tag/+page.server.ts b/src/routes/tag/+page.ts similarity index 81% rename from src/routes/tag/+page.server.ts rename to src/routes/tag/+page.ts index a5bf330..ec07e61 100644 --- a/src/routes/tag/+page.server.ts +++ b/src/routes/tag/+page.ts @@ -2,6 +2,6 @@ import type { PageLoad } from './$types'; import { getTags } from '$lib/posts'; export const load: PageLoad = async (_) => { - const allTags = await getTags(); + let allTags = await getTags(); return { allTags }; }; diff --git a/src/routes/tag/[slug]/+page.svelte b/src/routes/tag/[slug]/+page.svelte index ccf9660..7572bf9 100644 --- a/src/routes/tag/[slug]/+page.svelte +++ b/src/routes/tag/[slug]/+page.svelte @@ -10,7 +10,7 @@ {name} | {siteMetadata.blogName} -

{name}

+

{name} ({posts.length})