Tags and Filtering

Yeet projects, as they're identical to posts in every way but name
Add OpenGraph for SEO
Add Plugin prop to Layout to avoid loading unnecessary JS and CSS
This commit is contained in:
Michał Gdula 2024-05-28 19:01:57 +01:00
parent 745ac58045
commit 291552c340
21 changed files with 336 additions and 212 deletions

View file

@ -0,0 +1,36 @@
---
import { getCollection} from "astro:content";
import { getPosts } from "../../utils";
import Layout from "../../layouts/Layout.astro";
import HomeButton from "../../components/HomeButton.astro";
const tags = await getCollection("tags");
const posts = await getPosts("posts");
tags.forEach((tag) => {
tag.data.postCount = posts.filter((project) => {
return project.data.tags.includes(tag.slug);
}).length;
})
---
<Layout title="Leggy Land - All Projects">
<HomeButton />
<div class="header">
<h1>Search</h1>
<p>Filter posts by tags</p>
</div>
<hr>
<ul role="list" class="pill-list">
{tags.map(tag => (
<li>
<a class="button" href=`/search/${tag.slug}`>
{tag.data.name} {tag.data.postCount}
</a>
</li>
))}
</ul>
</Layout>