Migrate content from markdown to Appwrite database
Remove static markdown file dependencies and update all pages/components to fetch data directly from Appwrite collections, while maintaining existing service functions for data retrieval and adding new CRUD operations for projects.
This commit is contained in:
1 parent
7e3b5b7a55
commit
03a79e2f79
18 files changed
+1990
-5876
No files matched your search
@@ -2,7 +2,7 @@ import { formatDate } from "@lib/utils"
|
||||
import type { BlogPost, Project } from "@lib/appwrite-service"
|
||||
|
||||
type Props = {
|
||||
entry: BlogPost | Project
|
||||
entry: BlogPost | Project | any
|
||||
pill?: boolean
|
||||
}
|
||||
|
||||
|
||||
+63
-20
@@ -5,21 +5,32 @@ import { cn } from "@lib/utils"
|
||||
|
||||
type Props = {
|
||||
tags: string[]
|
||||
data: CollectionEntry<"blog">[]
|
||||
data: CollectionEntry<"blog">[] | any[] // Allow both content and appwrite data types
|
||||
templates?: string[] // Add template prop
|
||||
}
|
||||
|
||||
export default function Blog({ data, tags }: Props) {
|
||||
export default function Blog({ data, tags, templates = ["default"] }: Props) {
|
||||
const [filter, setFilter] = createSignal(new Set<string>())
|
||||
const [selectedTemplate, setSelectedTemplate] = createSignal<string>("all") // Add template selection
|
||||
const [posts, setPosts] = createSignal<CollectionEntry<"blog">[]>([])
|
||||
|
||||
createEffect(() => {
|
||||
setPosts(data.filter((entry) =>
|
||||
Array.from(filter()).every((value) =>
|
||||
setPosts(data.filter((entry) => {
|
||||
// Filter by tags
|
||||
const tagMatch = Array.from(filter()).every((value) =>
|
||||
entry.data.tags.some((tag:string) =>
|
||||
tag.toLowerCase() === String(value).toLowerCase()
|
||||
)
|
||||
)
|
||||
))
|
||||
|
||||
// Filter by template if a specific template is selected
|
||||
// Handle both content collections and Appwrite data (which have different structures)
|
||||
const templateMatch = selectedTemplate() === "all" ||
|
||||
(entry.data.template && entry.data.template === selectedTemplate()) ||
|
||||
(entry.template && entry.template === selectedTemplate())
|
||||
|
||||
return tagMatch && templateMatch
|
||||
}))
|
||||
})
|
||||
|
||||
function toggleTag(tag: string) {
|
||||
@@ -36,21 +47,53 @@ export default function Blog({ data, tags }: Props) {
|
||||
<div class="col-span-3 sm:col-span-1">
|
||||
<div class="sticky top-24">
|
||||
<div class="text-sm font-semibold uppercase mb-2 text-spaghetti-brown">Filter</div>
|
||||
<ul class="flex flex-wrap sm:flex-col gap-1.5">
|
||||
<For each={tags}>
|
||||
{(tag) => (
|
||||
<li>
|
||||
<button onClick={() => toggleTag(tag)} class={cn("w-full px-2 py-1 rounded", "whitespace-nowrap overflow-hidden overflow-ellipsis", "flex gap-2 items-center", "bg-spaghetti-yellow/20 dark:bg-spaghetti-yellow/20", "hover:bg-spaghetti-yellow/30 hover:dark:bg-spaghetti-yellow/30", "transition-colors duration-300 ease-in-out", filter().has(tag) && "text-spaghetti-brown dark:text-spaghetti-brown")}>
|
||||
<svg class={cn("size-5 fill-spaghetti-brown/50 dark:fill-spaghetti-brown/50", "transition-colors duration-300 ease-in-out", filter().has(tag) && "fill-spaghetti-brown dark:fill-spaghetti-brown")}>
|
||||
<use href={`/ui.svg#square`} class={cn(!filter().has(tag) ? "block" : "hidden")} />
|
||||
<use href={`/ui.svg#square-check`} class={cn(filter().has(tag) ? "block" : "hidden")} />
|
||||
</svg>
|
||||
{tag}
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
|
||||
{/* Template Filter */}
|
||||
<div class="mb-4">
|
||||
<div class="text-xs uppercase mb-1 text-spaghetti-brown/70">Template</div>
|
||||
<ul class="flex flex-wrap sm:flex-col gap-1.5">
|
||||
<li>
|
||||
<button
|
||||
onClick={() => setSelectedTemplate("all")}
|
||||
class={cn("w-full px-2 py-1 rounded", "whitespace-nowrap overflow-hidden overflow-ellipsis", "flex gap-2 items-center", "bg-spaghetti-yellow/20 dark:bg-spaghetti-yellow/20", "hover:bg-spaghetti-yellow/30 hover:dark:bg-spaghetti-yellow/30", "transition-colors duration-300 ease-in-out", selectedTemplate() === "all" && "text-spaghetti-brown dark:text-spaghetti-brown")}
|
||||
>
|
||||
All Templates
|
||||
</button>
|
||||
</li>
|
||||
<For each={templates}>
|
||||
{(template) => (
|
||||
<li>
|
||||
<button
|
||||
onClick={() => setSelectedTemplate(template)}
|
||||
class={cn("w-full px-2 py-1 rounded", "whitespace-nowrap overflow-hidden overflow-ellipsis", "flex gap-2 items-center", "bg-spaghetti-yellow/20 dark:bg-spaghetti-yellow/20", "hover:bg-spaghetti-yellow/30 hover:dark:bg-spaghetti-yellow/30", "transition-colors duration-300 ease-in-out", selectedTemplate() === template && "text-spaghetti-brown dark:text-spaghetti-brown")}
|
||||
>
|
||||
{template.charAt(0).toUpperCase() + template.slice(1)}
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
{/* Tag Filter */}
|
||||
<div class="mb-2">
|
||||
<div class="text-xs uppercase mb-1 text-spaghetti-brown/70">Tags</div>
|
||||
<ul class="flex flex-wrap sm:flex-col gap-1.5">
|
||||
<For each={tags}>
|
||||
{(tag) => (
|
||||
<li>
|
||||
<button onClick={() => toggleTag(tag)} class={cn("w-full px-2 py-1 rounded", "whitespace-nowrap overflow-hidden overflow-ellipsis", "flex gap-2 items-center", "bg-spaghetti-yellow/20 dark:bg-spaghetti-yellow/20", "hover:bg-spaghetti-yellow/30 hover:dark:bg-spaghetti-yellow/30", "transition-colors duration-300 ease-in-out", filter().has(tag) && "text-spaghetti-brown dark:text-spaghetti-brown")}>
|
||||
<svg class={cn("size-5 fill-spaghetti-brown/50 dark:fill-spaghetti-brown/50", "transition-colors duration-300 ease-in-out", filter().has(tag) && "fill-spaghetti-brown dark:fill-spaghetti-brown")}>
|
||||
<use href={`/ui.svg#square`} class={cn(!filter().has(tag) ? "block" : "hidden")} />
|
||||
<use href={`/ui.svg#square-check`} class={cn(filter().has(tag) ? "block" : "hidden")} />
|
||||
</svg>
|
||||
{tag}
|
||||
</button>
|
||||
</li>
|
||||
)}
|
||||
</For>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-span-3 sm:col-span-2">
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import type { CollectionEntry } from "astro:content"
|
||||
import type { BlogPost, Project } from "@lib/appwrite-service"
|
||||
import { createEffect, createSignal } from "solid-js"
|
||||
import Fuse from "fuse.js"
|
||||
import ArrowCard from "@components/ArrowCard"
|
||||
|
||||
// Define a unified type for search results
|
||||
type SearchEntry = BlogPost | Project
|
||||
|
||||
type Props = {
|
||||
data: CollectionEntry<"blog">[]
|
||||
data: SearchEntry[]
|
||||
}
|
||||
|
||||
export default function Search({data}: Props) {
|
||||
const [query, setQuery] = createSignal("")
|
||||
const [results, setResults] = createSignal<CollectionEntry<"blog">[]>([])
|
||||
const [results, setResults] = createSignal<SearchEntry[]>([])
|
||||
|
||||
const fuse = new Fuse(data, {
|
||||
keys: ["slug", "data.title", "data.summary", "data.tags"],
|
||||
keys: ["$id", "title", "summary", "tags"],
|
||||
includeMatches: true,
|
||||
minMatchCharLength: 2,
|
||||
threshold: 0.4,
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { render } from '@solidjs/testing-library';
|
||||
import Blog from '../Blog';
|
||||
|
||||
// Mock data for testing
|
||||
const mockTags = ['technology', 'web development', 'astro'];
|
||||
const mockData = [
|
||||
{
|
||||
id: '1',
|
||||
slug: 'test-post',
|
||||
body: 'Test post content',
|
||||
collection: 'blog',
|
||||
data: {
|
||||
title: 'Test Post',
|
||||
summary: 'A test post',
|
||||
date: new Date(),
|
||||
tags: ['technology'],
|
||||
draft: false,
|
||||
template: 'default',
|
||||
featured: false
|
||||
},
|
||||
render: async () => ({
|
||||
Content: () => null,
|
||||
headings: [],
|
||||
remarkPluginFrontmatter: {}
|
||||
})
|
||||
}
|
||||
];
|
||||
|
||||
describe('Blog Component', () => {
|
||||
it('should render without crashing', () => {
|
||||
const { container } = render(() => (
|
||||
<Blog tags={mockTags} data={mockData} />
|
||||
));
|
||||
|
||||
expect(container).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should display the correct number of posts', () => {
|
||||
const { container } = render(() => (
|
||||
<Blog tags={mockTags} data={mockData} />
|
||||
));
|
||||
|
||||
// Should have at least one post displayed
|
||||
const postElements = container.querySelectorAll('li');
|
||||
expect(postElements.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user