Compare commits

...

3 Commits

Author SHA1 Message Date
75a9ea5fce Move tags to correct place 2025-04-27 00:28:34 -07:00
8111bdd318 Add tags at top of blog pages 2025-04-27 00:18:02 -07:00
a57b48af3a Update Blog Articles with tags 2025-04-27 00:13:55 -07:00
6 changed files with 55 additions and 8 deletions

View File

@ -8,22 +8,30 @@ export type Props = {
url: string; url: string;
duration?: string; duration?: string;
timestamp?: string; timestamp?: string;
tags?: string[];
}; };
const { title, description, url, duration, timestamp } = Astro.props; const { title, description, url, duration, timestamp, tags } = Astro.props;
--- ---
<div class="zag-text zag-transition flex flex-col gap-3 pb-8"> <div class="zag-text zag-transition flex flex-col gap-3 pb-8">
<Anchor url={url} class="text-xl"> <Anchor url={url} class="text-xl">
{title} {title}
</Anchor> </Anchor>
<div
class="zag-muted zag-transition flex justify-between items-center"
>
{timestamp ? <p>{processArticleDate(timestamp)}</p> : null}
{duration ? <p>{duration}</p> : null}
</div>
<p class=""> <p class="">
{description} {description}
</p> </p>
<div <div class="flex flex-wrap gap-2">
class="zag-muted zag-transition flex justify-between items-center" {tags?.map((tag: string) => (
> <span class="-zag-text -zag-bg zag-transition px-2 py-1 text-sm font-semibold">
{timestamp ? <p>{processArticleDate(timestamp)}</p> : null} {tag}
{duration ? <p>{duration}</p> : null} </span>
))}
</div> </div>
</div> </div>

View File

@ -26,6 +26,7 @@ const { featuredArticles } = Astro.props;
url={article.filename} url={article.filename}
timestamp={article.timestamp} timestamp={article.timestamp}
duration={`${article.time} min`} duration={`${article.time} min`}
tags={article.tags}
/> />
</li> </li>
)) ))

View File

@ -50,6 +50,13 @@ const sourceUrl = generateSourceUrl(frontmatter.filename, "blog");
<Prose> <Prose>
<slot /> <slot />
</Prose> </Prose>
<div class="flex flex-wrap gap-2 mt-4">
{frontmatter.tags?.map((tag) => (
<span class="-zag-text -zag-bg zag-transition px-2 py-1 text-sm font-semibold">
{tag}
</span>
))}
</div>
<p class="pt-8">~{GLOBAL.username}</p> <p class="pt-8">~{GLOBAL.username}</p>
</Section> </Section>
</Layout> </Layout>

View File

@ -90,3 +90,15 @@ export const generateSourceUrl = (
) => { ) => {
return `${GLOBAL.rootUrl}/${contentType}/${sourceUrl}`; return `${GLOBAL.rootUrl}/${contentType}/${sourceUrl}`;
}; };
export const countTags = (tags: string[]) => {
const tagCount: Record<string, number> = {};
tags.forEach((tag) => {
if (tagCount[tag]) {
tagCount[tag]++;
} else {
tagCount[tag] = 1;
}
});
return tagCount;
}

View File

@ -7,4 +7,12 @@ time: 4
featured: true featured: true
timestamp: 2024-12-18T02:39:03+00:00 timestamp: 2024-12-18T02:39:03+00:00
filename: html-intro filename: html-intro
--- ---
<div class="flex flex-wrap gap-2">
{tags.map((tag) => (
<span class="-zag-text -zag-bg zag-transition px-2 py-1 text-sm font-semibold">
{tag}
</span>
))}
</div>

View File

@ -4,6 +4,9 @@ import Layout from "../../layouts/Layout.astro";
import ArticleSnippet from "../../components/ArticleSnippet.astro"; import ArticleSnippet from "../../components/ArticleSnippet.astro";
import Section from "../../components/common/Section.astro"; import Section from "../../components/common/Section.astro";
import { articles } from "../../lib/list"; import { articles } from "../../lib/list";
import { countTags } from "../../lib/utils";
const tagCounts = countTags(articles.map((article) => article.tags).flat().filter((tag): tag is string => tag !== undefined));
--- ---
@ -33,9 +36,16 @@ import { articles } from "../../lib/list";
<link rel="canonical" href={`${GLOBAL.rootUrl}/blog`} /> <link rel="canonical" href={`${GLOBAL.rootUrl}/blog`} />
</Fragment> </Fragment>
<Section class="my-8"> <Section class="my-8">
<div class="flex items-center gap-4 pt-8 pb-16"> <div class="flex items-center gap-4 pt-8 pb-4">
<h1 class="font-display text-3xl sm:text-4xl leading-loose">{GLOBAL.articlesName}</h1> <h1 class="font-display text-3xl sm:text-4xl leading-loose">{GLOBAL.articlesName}</h1>
</div> </div>
<div class="flex flex-wrap gap-2 pb-16">
{Object.entries(tagCounts).map(([tag, count]) => (
<span class="-zag-text -zag-bg zag-transition px-2 py-1 text-sm font-semibold">
{tag}: {count}
</span>
))}
</div>
<ul> <ul>
{ {
articles.map((project) => ( articles.map((project) => (
@ -46,6 +56,7 @@ import { articles } from "../../lib/list";
duration={`${project.time} min`} duration={`${project.time} min`}
url={project.filename} url={project.filename}
timestamp={project.timestamp} timestamp={project.timestamp}
tags={project.tags}
/> />
</li> </li>
)) ))