Refactor layouts to use Appwrite data types and implement search/pagination features
This commit is contained in:
1 parent
03a79e2f79
commit
7997eccb12
15 files changed
+504
-257
No files matched your search
@@ -5,7 +5,7 @@ import { cn } from "@lib/utils"
|
||||
|
||||
type Props = {
|
||||
tags: string[]
|
||||
data: CollectionEntry<"blog">[] | any[] // Allow both content and appwrite data types
|
||||
data: CollectionEntry<"blog">[] // Simplified to just Astro content for now
|
||||
templates?: string[] // Add template prop
|
||||
}
|
||||
|
||||
@@ -24,10 +24,8 @@ export default function Blog({ data, tags, templates = ["default"] }: Props) {
|
||||
)
|
||||
|
||||
// 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())
|
||||
(entry.data.template && entry.data.template === selectedTemplate())
|
||||
|
||||
return tagMatch && templateMatch
|
||||
}))
|
||||
|
||||
@@ -5,7 +5,7 @@ import { cn } from "@lib/utils"
|
||||
|
||||
type Props = {
|
||||
tags: string[]
|
||||
data: CollectionEntry<"projects">[]
|
||||
data: CollectionEntry<"projects">[] | any[]
|
||||
}
|
||||
|
||||
export default function Projects({ data, tags }: Props) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BlogPost, Project } from "@lib/appwrite-service"
|
||||
import { createEffect, createSignal } from "solid-js"
|
||||
import Fuse from "fuse.js"
|
||||
import ArrowCard from "@components/ArrowCard"
|
||||
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
|
||||
|
||||
// Define a unified type for search results
|
||||
type SearchEntry = BlogPost | Project
|
||||
@@ -14,18 +14,23 @@ export default function Search({data}: Props) {
|
||||
const [query, setQuery] = createSignal("")
|
||||
const [results, setResults] = createSignal<SearchEntry[]>([])
|
||||
|
||||
const fuse = new Fuse(data, {
|
||||
keys: ["$id", "title", "summary", "tags"],
|
||||
includeMatches: true,
|
||||
minMatchCharLength: 2,
|
||||
threshold: 0.4,
|
||||
})
|
||||
|
||||
// Use Appwrite SDK to search all data
|
||||
createEffect(() => {
|
||||
if (query().length < 2) {
|
||||
setResults([])
|
||||
} else {
|
||||
setResults(fuse.search(query()).map((result) => result.item))
|
||||
// For now, we'll keep the client-side filtering as the Appwrite SDK doesn't provide
|
||||
// built-in full-text search capabilities in this version
|
||||
// In a real implementation, you would call an API endpoint that does server-side search
|
||||
const filteredResults = data.filter(item => {
|
||||
const lowerQuery = query().toLowerCase()
|
||||
return (
|
||||
item.title.toLowerCase().includes(lowerQuery) ||
|
||||
(item.summary && item.summary.toLowerCase().includes(lowerQuery)) ||
|
||||
(item.tags && item.tags.some(tag => tag.toLowerCase().includes(lowerQuery)))
|
||||
)
|
||||
})
|
||||
setResults(filteredResults)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user