filters now filter blog posts correctly

This commit is contained in:
2026-03-31 15:28:37 +02:00
parent 9dcb9823a8
commit 4ea6d168a6
2 changed files with 20 additions and 24 deletions

View File

@@ -1,31 +1,26 @@
<script lang="ts">
import Banner2 from "$lib/banner2.svelte";
import Content from "$lib/viewport/content.svelte";
// import Gallery, { type GalleryEntry } from "$lib/lists/gallery.svelte";
import { BlogPostTag, posts, type BlogPostLink } from "./posts";
import { BlogPostTag, posts, type BlogPostDetails, type BlogPostLink } from "./posts";
import BlogGallery from "$lib/lists/blog-gallery.svelte";
function selectFilter(tag: string) {
console.log(tag);
let filter = $state(BlogPostTag.NULL);
let filteredPosts = filterPosts();
function setFilter(tag: BlogPostTag) {
filter = tag;
console.log(filter);
}
// let entries: GalleryEntry[] = posts.map(mapEntries);
// function mapEntries(entry: BlogPostLink, index: number): GalleryEntry {
// let banner = "";
// if (entry.post.banner && entry.post.banner !== "") {
// banner = `/blog/${entry.key}/${entry.post.banner}`;
// }
function filterPosts(): BlogPostLink[] {
if (filter == BlogPostTag.NULL) {
return posts;
}
// return {
// title: `${entry.post.title}`,
// subtitle: `#${(posts.length - index).toString().padStart(2, '0')} // ${entry.post.date}, ${entry.post.time}`,
// img: banner,
// link: `/blog/${entry.key}/`,
// imgAlt: `Preview image for ${entry.post.title}`,
// description: entry.post.description,
// };
// }
let a: BlogPostLink[] = posts.filter((post) => post.post.tags.includes(filter))
console.log(a);
return a;
}
</script>
<svelte:head>
@@ -41,13 +36,13 @@
<!-- TODO descriptions on filter click -->
<div class="tag-filter-container">
{#each Object.values(BlogPostTag) as tag}
<button onclick={() => {
selectFilter(tag)
}} class="post-tag tag-filter">{tag}</button>
<button class="post-tag tag-filter" onclick={() => {
setFilter(tag)
}}>{tag}</button>
{/each}
</div>
<BlogGallery {posts} />
<BlogGallery posts={filterPosts()} />
</Content>
<style>

View File

@@ -24,6 +24,7 @@ export interface BlogPostLink {
}
export enum BlogPostTag {
NULL = "X", // placeholder when a 'no tag' is needed. if in doubt, do not use this
ART = "art-stuff", // ramblings to do with art
DRAWING = "drawing", // self-explanatory
META = "natconf-meta", // about the website itself