diff --git a/src/lib/utils.ts b/src/lib/utils.ts index a22f221..cecbf65 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -90,3 +90,15 @@ export const generateSourceUrl = ( ) => { return `${GLOBAL.rootUrl}/${contentType}/${sourceUrl}`; }; + +export const countTags = (tags: string[]) => { + const tagCount: Record = {}; + tags.forEach((tag) => { + if (tagCount[tag]) { + tagCount[tag]++; + } else { + tagCount[tag] = 1; + } + }); + return tagCount; +} diff --git a/src/pages/blog/html-intro.md b/src/pages/blog/html-intro.md index a198c1d..f95260c 100644 --- a/src/pages/blog/html-intro.md +++ b/src/pages/blog/html-intro.md @@ -7,4 +7,12 @@ time: 4 featured: true timestamp: 2024-12-18T02:39:03+00:00 filename: html-intro ---- \ No newline at end of file +--- + +
+ {tags.map((tag) => ( + + {tag} + + ))} +
\ No newline at end of file diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 6162ce5..e756b23 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -4,6 +4,9 @@ import Layout from "../../layouts/Layout.astro"; import ArticleSnippet from "../../components/ArticleSnippet.astro"; import Section from "../../components/common/Section.astro"; import { articles } from "../../lib/list"; +import { countTags } from "../../lib/utils"; + +const tagCounts = countTags(articles.map((article) => article.tags).flat()); --- @@ -32,6 +35,15 @@ import { articles } from "../../lib/list"; +
+
+ {Object.entries(tagCounts).map(([tag, count]) => ( + + {tag}: {count} + + ))} +
+

{GLOBAL.articlesName}