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,46 +5,14 @@ import BottomLayout from "@layouts/BottomLayout.astro"
|
||||
import ArticleTopLayout from "@layouts/ArticleTopLayout.astro"
|
||||
import ArticleBottomLayout from "@layouts/ArticleBottomLayout.astro"
|
||||
import { getBlogPostById } from "@lib/appwrite-service"
|
||||
import type { BlogCollectionEntry } from "@types/appwrite"
|
||||
|
||||
// Create the static blog pages
|
||||
export async function getStaticPaths() {
|
||||
// This will be replaced with Appwrite data in the future
|
||||
return []
|
||||
}
|
||||
|
||||
// Helper function to map Appwrite document to CollectionEntry format
|
||||
function mapAppwriteBlogToCollectionEntry(post: any): BlogCollectionEntry {
|
||||
return {
|
||||
id: post.$id,
|
||||
slug: post.$id, // Using ID as slug since we don't have a proper slug field
|
||||
body: post.contentHtml || post.content, // Use converted HTML content
|
||||
collection: "blog",
|
||||
data: {
|
||||
title: post.title,
|
||||
summary: post.summary,
|
||||
date: new Date(post.date),
|
||||
tags: JSON.parse(post.tags),
|
||||
draft: post.draft,
|
||||
content: post.contentHtml || post.content // Use converted HTML content
|
||||
},
|
||||
render: async () => {
|
||||
// This is a minimal implementation for the render function that matches the expected structure
|
||||
return {
|
||||
Content: () => {},
|
||||
headings: [],
|
||||
remarkPluginFrontmatter: {}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Get the requested post
|
||||
const slug = Astro.params.slug
|
||||
const slug = Astro.params.slug || ''
|
||||
const post = await getBlogPostById(slug)
|
||||
.then(blogPost => {
|
||||
if (blogPost) {
|
||||
return mapAppwriteBlogToCollectionEntry(blogPost);
|
||||
return blogPost;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
@@ -53,7 +21,7 @@ const post = await getBlogPostById(slug)
|
||||
return null;
|
||||
})
|
||||
|
||||
const { title, summary } = post?.data || { title: "Post not found", summary: "" }
|
||||
const { title, summary } = post || { title: "Post not found", summary: "" }
|
||||
---
|
||||
|
||||
<PageLayout title={title} description={summary}>
|
||||
|
||||
@@ -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))
|
||||
---
|
||||
|
||||
@@ -5,48 +5,13 @@ import BottomLayout from "@layouts/BottomLayout.astro"
|
||||
import ArticleTopLayout from "@layouts/ArticleTopLayout.astro"
|
||||
import ArticleBottomLayout from "@layouts/ArticleBottomLayout.astro"
|
||||
import { getProjectById } from "@lib/appwrite-service"
|
||||
import type { ProjectCollectionEntry } from "@types/appwrite"
|
||||
|
||||
// Create the static projects pages
|
||||
export async function getStaticPaths() {
|
||||
// This will be replaced with Appwrite data in the future
|
||||
return []
|
||||
}
|
||||
|
||||
// Helper function to map Appwrite document to CollectionEntry format
|
||||
function mapAppwriteProjectToCollectionEntry(project: any): ProjectCollectionEntry {
|
||||
return {
|
||||
id: project.$id,
|
||||
slug: project.$id, // Using ID as slug since we don't have a proper slug field
|
||||
body: project.contentHtml || project.content, // Use converted HTML content
|
||||
collection: "projects",
|
||||
data: {
|
||||
title: project.title,
|
||||
summary: project.summary,
|
||||
date: new Date(project.date),
|
||||
tags: project.tags,
|
||||
draft: project.draft,
|
||||
demoUrl: project.demoUrl,
|
||||
repoUrl: project.repoUrl,
|
||||
content: project.contentHtml || project.content // Use converted HTML content
|
||||
},
|
||||
render: async () => {
|
||||
// This is a minimal implementation for the render function that matches the expected structure
|
||||
return {
|
||||
Content: () => {},
|
||||
headings: [],
|
||||
remarkPluginFrontmatter: {}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Get the requested project
|
||||
const slug = Astro.params.slug
|
||||
const project = await getProjectById(slug)
|
||||
.then(projectData => {
|
||||
if (projectData) {
|
||||
return mapAppwriteProjectToCollectionEntry(projectData);
|
||||
return projectData
|
||||
}
|
||||
return null;
|
||||
})
|
||||
@@ -55,7 +20,7 @@ const project = await getProjectById(slug)
|
||||
return null;
|
||||
})
|
||||
|
||||
const { title, summary } = project?.data || { title: "Project not found", summary: "" }
|
||||
const { title, summary } = project || { title: "Project not found", summary: "" }
|
||||
---
|
||||
|
||||
<PageLayout title={title} description={summary}>
|
||||
|
||||
@@ -4,38 +4,28 @@ import TopLayout from "@layouts/TopLayout.astro"
|
||||
import BottomLayout from "@layouts/BottomLayout.astro"
|
||||
import Projects from "@components/Projects"
|
||||
import { PROJECTS } from "@consts"
|
||||
import { getProjects } from "@lib/appwrite-service"
|
||||
import type { Project } from "@types/appwrite"
|
||||
import { getProjectsPaginated } from "@lib/appwrite-service"
|
||||
|
||||
// Helper function to map Appwrite project document to CollectionEntry format
|
||||
function mapAppwriteProjectToCollectionEntry(project: Project) {
|
||||
return {
|
||||
$id: project.$id,
|
||||
$collectionId: "projects",
|
||||
data: {
|
||||
title: project.title,
|
||||
summary: project.summary,
|
||||
date: new Date(project.date),
|
||||
tags: project.tags,
|
||||
draft: project.draft,
|
||||
demoUrl: project.demoUrl,
|
||||
repoUrl: project.repoUrl,
|
||||
content: project.content,
|
||||
image: project.image
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const projects = await getProjects()
|
||||
.then(projectList => {
|
||||
return projectList.map(project => mapAppwriteProjectToCollectionEntry(project));
|
||||
// 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 projects
|
||||
const { posts, total } = await getProjectsPaginated(page, limit)
|
||||
.then(result => {
|
||||
return result;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Error fetching projects:", error);
|
||||
return [];
|
||||
return { posts: [], total: 0 };
|
||||
})
|
||||
|
||||
const tags = [...new Set(projects.flatMap(project => project.data.tags))]
|
||||
// Get all tags for filtering
|
||||
const tags = [...new Set(posts.flatMap(project => project.tags))]
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
---
|
||||
|
||||
@@ -47,7 +37,7 @@ const tags = [...new Set(projects.flatMap(project => project.data.tags))]
|
||||
</TopLayout>
|
||||
<BottomLayout>
|
||||
<div class="animate">
|
||||
<Projects client:load tags={tags} data={projects} />
|
||||
<Projects client:load tags={tags} data={posts} />
|
||||
</div>
|
||||
</BottomLayout>
|
||||
</PageLayout>
|
||||
Reference in new issue
Block a user