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
@@ -4,18 +4,26 @@ import TopLayout from "@layouts/TopLayout.astro"
|
||||
import BottomLayout from "@layouts/BottomLayout.astro"
|
||||
import Blog from "@components/Blog"
|
||||
import { BLOG } from "@consts"
|
||||
import { getBlogPosts } from "@lib/appwrite-service"
|
||||
import type { BlogPost } from "@types/appwrite"
|
||||
import { getBlogPosts, getBlogPostsPaginated } from "@lib/appwrite-service"
|
||||
|
||||
const posts = await getBlogPosts()
|
||||
.then(blogPosts => {
|
||||
return blogPosts;
|
||||
// Get page and limit from URL parameters
|
||||
const url = new URL(typeof window !== 'undefined' ? window.location.href : 'http://localhost')
|
||||
const pageParam = url.searchParams.get('page') || '1'
|
||||
const limitParam = url.searchParams.get('limit') || '10'
|
||||
const page = parseInt(pageParam)
|
||||
const limit = parseInt(limitParam)
|
||||
|
||||
// Fetch paginated blog posts
|
||||
const { posts, total } = await getBlogPostsPaginated(page, limit)
|
||||
.then(result => {
|
||||
return result;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error fetching blog posts:", error);
|
||||
return [];
|
||||
return { posts: [], total: 0 };
|
||||
})
|
||||
|
||||
// Get all tags for filtering
|
||||
const tags = [...new Set(posts.flatMap(post => post.tags))]
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
---
|
||||
|
||||
Reference in new issue
Block a user