Skip to content

Commit

Permalink
feat: display post tags
Browse files Browse the repository at this point in the history
  • Loading branch information
SidonieBouthors committed Aug 17, 2024
1 parent c55dc43 commit 128b53d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
16 changes: 13 additions & 3 deletions components/ArticleBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from "react";
import { format } from "date-fns";
import Link from "next/link";
import { CalendarIcon } from "./icons/CalendarIcon";
import { Tag } from "@components/Tag";

interface ArticleBlockProps {
slug: string;
title: string;
description?: string;
date: string;
tags?: string[];
tags: string[];
}

export default function ArticleBlock({
Expand All @@ -25,8 +26,17 @@ export default function ArticleBlock({
<h2>{title}</h2>
</Link>
<p>{description}</p>
<span className="art-date"><CalendarIcon/>{formattedDate}</span>

{tags.length != 0 ? (
<div className="tags">
{tags?.map((tag) => (
<Tag>{tag}</Tag>
))}
</div>
) : null}
<span className="art-date">
<CalendarIcon />
{formattedDate}
</span>
</article>
);
}
9 changes: 9 additions & 0 deletions components/Tag.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from "next/link";
import { slug } from "github-slugger";

interface TagProps {
children: string;
}
export function Tag({ children }: TagProps) {
return <span className="tag">{children}</span>;
}
3 changes: 2 additions & 1 deletion styles/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
@forward "toc-links";
@forward "info-box";
@forward "recipe-info";
@forward "article-block";
@forward "article-block";
@forward "tag";
21 changes: 21 additions & 0 deletions styles/components/_tag.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@use "../abstracts" as *;

.tags {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
}

.tag {
cursor: pointer;
font-family: $font-bold;
font-size: 0.8rem;
display: inline-block;
padding: 0.25em 0.8em;
border-radius: 0.7em;
background-color: var(--collapsible-bg);

&:hover {
background-color: var(--collapsible-summary-bg);
}
}
2 changes: 1 addition & 1 deletion velite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const posts = defineCollection({
description: s.string().max(200).optional(),
date: s.isodate(),
published: s.boolean().default(true),
tags: s.array(s.string()).optional(),
tags: s.array(s.string()).default([]),
body: s.mdx(),
})
.transform(postComputedFields),
Expand Down

0 comments on commit 128b53d

Please sign in to comment.