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
+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">
|
||||
|
||||
Reference in new issue
Block a user