Refactor content handling to use Appwrite service instead of Astro collections, remove ViewTransitions import, update test files accordingly
This commit is contained in:
1 parent
9cc9768121
commit
c9948befaf
13 files changed
+111
-256
No files matched your search
@@ -1,5 +1,4 @@
|
|||||||
---
|
---
|
||||||
import { ViewTransitions } from "astro:transitions"
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
title: string
|
title: string
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import type { CollectionEntry } from "astro:content"
|
import type { BlogPost } from "@lib/appwrite-service"
|
||||||
import { createEffect, createSignal, For } from "solid-js"
|
import { createEffect, createSignal, For } from "solid-js"
|
||||||
import ArrowCard from "@components/ArrowCard"
|
import ArrowCard from "@components/ArrowCard"
|
||||||
import { cn } from "@lib/utils"
|
import { cn } from "@lib/utils"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
tags: string[]
|
tags: string[]
|
||||||
data: CollectionEntry<"blog">[] // Simplified to just Astro content for now
|
data: BlogPost[] // Using Appwrite data instead of Astro content collections
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Blog({ data, tags }: Props) {
|
export default function Blog({ data, tags }: Props) {
|
||||||
const [filter, setFilter] = createSignal(new Set<string>())
|
const [filter, setFilter] = createSignal(new Set<string>())
|
||||||
const [posts, setPosts] = createSignal<CollectionEntry<"blog">[]>([])
|
const [posts, setPosts] = createSignal<BlogPost[]>([])
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
setPosts(data.filter((entry) => {
|
setPosts(data.filter((entry) => {
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import type { CollectionEntry } from "astro:content"
|
import type { Project } from "@lib/appwrite-service"
|
||||||
import { createEffect, createSignal, For } from "solid-js"
|
import { createEffect, createSignal, For } from "solid-js"
|
||||||
import ArrowCard from "@components/ArrowCard"
|
import ArrowCard from "@components/ArrowCard"
|
||||||
import { cn } from "@lib/utils"
|
import { cn } from "@lib/utils"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
tags: string[]
|
tags: string[]
|
||||||
data: CollectionEntry<"projects">[] | any[]
|
data: Project[] | any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Projects({ data, tags }: Props) {
|
export default function Projects({ data, tags }: Props) {
|
||||||
const [filter, setFilter] = createSignal(new Set<string>())
|
const [filter, setFilter] = createSignal(new Set<string>())
|
||||||
const [projects, setProjects] = createSignal<CollectionEntry<"projects">[]>([])
|
const [projects, setProjects] = createSignal<Project[]>([])
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
setProjects(data.filter((entry) =>
|
setProjects(data.filter((entry) =>
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ export default function Search(props: Props) {
|
|||||||
<div class="border-t border-spaghetti-yellow/30 pt-4">
|
<div class="border-t border-spaghetti-yellow/30 pt-4">
|
||||||
<div class="text-sm font-bold mb-2">Projects</div>
|
<div class="text-sm font-bold mb-2">Projects</div>
|
||||||
<ul class="flex flex-col gap-3">
|
<ul class="flex flex-col gap-3">
|
||||||
{results().projects.map((result, index) => (
|
{results().projects.map(result => (
|
||||||
<li>
|
<li>
|
||||||
<ArrowCard entry={result} pill={true} collection={'projects'} />
|
<ArrowCard entry={result} pill={true} collection={'projects'} />
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
---
|
---
|
||||||
import type { BlogPost, Project } from "@lib/appwrite-service"
|
import type { BlogPost, Project } from "@lib/appwrite-service"
|
||||||
import { formatDate, readingTime } from "@lib/utils"
|
|
||||||
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
|
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -72,7 +71,7 @@ if (collection === "blog") {
|
|||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{nextEntry && (
|
{nextEntry && (
|
||||||
<a href={`/${collection}/${nextEntry.$id}`} class="group p-4 gap-3 flex items-center border rounded-lg hover:bg-black/5 hover:dark:bg-spaghetti-cream/10 border-black/15 dark:border-spaghetti-cream/20 transition-colors duration-300 ease-in-out">
|
<a href={`/${collection}/${nextEntry.$id}`} class="group p-4 gap-3 flex items-center border rounded-lg hover:bg-black/5 hover:dark:bg-spaghetti-cream/10 border-black/15 dark:border-spaghetti-cream/20 transition-colors duration-300 ease-in-out blend dark:text-spaghetti-cream">
|
||||||
<div class="w-full h-full text-right group-hover:text-spaghetti-brown/80 group-hover:dark:text-spaghetti-cream blend">
|
<div class="w-full h-full text-right group-hover:text-spaghetti-brown/80 group-hover:dark:text-spaghetti-cream blend">
|
||||||
<div class="text-sm uppercase">
|
<div class="text-sm uppercase">
|
||||||
Next
|
Next
|
||||||
@@ -81,14 +80,14 @@ if (collection === "blog") {
|
|||||||
{nextEntry.title}
|
{nextEntry.title}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="stroke-current group-hover:stroke-black group-hover:dark:stroke-white">
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="stroke-current group-hover:stroke-black group-hover:dark:stroke-white blend">
|
||||||
<line x1="5" y1="12" x2="19" y2="12" class="scale-x-0 group-hover:scale-x-100 translate-x-4 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
<line x1="5" y1="12" x2="19" y2="12" class="scale-x-0 group-hover:scale-x-100 translate-x-4 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
||||||
<polyline points="12 5 19 12 12 19" class="translate-x-0 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
<polyline points="12 5 19 12 12 19" class="translate-x-0 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
||||||
</svg>
|
</svg>
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
{!prevEntry && !nextEntry && (
|
{!prevEntry && !nextEntry && (
|
||||||
<div class="col-span-2 text-center py-8 text-gray-500">
|
<div class="col-span-2 text-center py-8 text-gray-500 blend">
|
||||||
No adjacent articles available
|
No adjacent articles available
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,175 +1,80 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { getBlogTemplates, createBlogPost, updateBlogPost, deleteBlogPost, createProject, updateProject, deleteProject, createWorkExperience, updateWorkExperience, deleteWorkExperience, createLegalDocument, updateLegalDocument, deleteLegalDocument } from '../appwrite-service';
|
import { getBlogPosts, getProjects, getWorkExperiences, getLegalDocuments } from '../appwrite-service';
|
||||||
|
|
||||||
describe('AppWrite Service', () => {
|
describe('AppWrite Service', () => {
|
||||||
describe('getBlogTemplates', () => {
|
describe('getBlogPosts', () => {
|
||||||
it('should return an array of blog templates', async () => {
|
it('should return an array of blog posts', async () => {
|
||||||
const templates = await getBlogTemplates();
|
const posts = await getBlogPosts();
|
||||||
|
|
||||||
expect(Array.isArray(templates)).toBe(true);
|
expect(Array.isArray(posts)).toBe(true);
|
||||||
expect(templates.length).toBeGreaterThan(0);
|
expect(posts.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
// Check that each template has the expected properties
|
// Check that each post has the expected properties
|
||||||
templates.forEach(template => {
|
posts.forEach((post) => {
|
||||||
expect(template).toHaveProperty('id');
|
expect(post).toHaveProperty('title');
|
||||||
expect(template).toHaveProperty('name');
|
expect(post).toHaveProperty('summary');
|
||||||
expect(template).toHaveProperty('slug');
|
expect(post).toHaveProperty('date');
|
||||||
|
expect(post).toHaveProperty('tags');
|
||||||
|
expect(post).toHaveProperty('draft');
|
||||||
|
expect(post).toHaveProperty('content');
|
||||||
|
expect(post).toHaveProperty('template');
|
||||||
|
expect(post).toHaveProperty('featured');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the correct default templates', async () => {
|
describe('getProjects', () => {
|
||||||
const templates = await getBlogTemplates();
|
it('should return an array of projects', async () => {
|
||||||
|
const projects = await getProjects();
|
||||||
|
|
||||||
// Should contain default, feature and news templates
|
expect(Array.isArray(projects)).toBe(true);
|
||||||
const templateIds = templates.map(t => t.id);
|
expect(projects.length).toBeGreaterThan(0);
|
||||||
expect(templateIds).toContain('default');
|
|
||||||
expect(templateIds).toContain('feature');
|
|
||||||
expect(templateIds).toContain('news');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('createBlogPost', () => {
|
|
||||||
it('should create a new blog post with valid data', async () => {
|
|
||||||
const postData = {
|
|
||||||
title: "Test Blog Post",
|
|
||||||
summary: "Test summary",
|
|
||||||
date: new Date(),
|
|
||||||
tags: ["test", "blog"],
|
|
||||||
draft: false,
|
|
||||||
content: "Test content",
|
|
||||||
template: "default",
|
|
||||||
featured: false
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
const mockResponse = {
|
|
||||||
$id: "test-id",
|
|
||||||
...postData
|
|
||||||
};
|
|
||||||
|
|
||||||
// This test would require mocking the databases.createDocument call
|
// Check that each project has the expected properties
|
||||||
expect(typeof createBlogPost).toBe('function');
|
projects.forEach((project) => {
|
||||||
|
expect(project).toHaveProperty('title');
|
||||||
|
expect(project).toHaveProperty('summary');
|
||||||
|
expect(project).toHaveProperty('date');
|
||||||
|
expect(project).toHaveProperty('tags');
|
||||||
|
expect(project).toHaveProperty('draft');
|
||||||
|
expect(project).toHaveProperty('content');
|
||||||
|
expect(project).toHaveProperty('demoUrl');
|
||||||
|
expect(project).toHaveProperty('repoUrl');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateBlogPost', () => {
|
describe('getWorkExperiences', () => {
|
||||||
it('should update an existing blog post', async () => {
|
it('should return an array of work experiences', async () => {
|
||||||
const postData = {
|
const workExperiences = await getWorkExperiences();
|
||||||
title: "Updated Blog Post",
|
|
||||||
content: "Updated content"
|
expect(Array.isArray(workExperiences)).toBe(true);
|
||||||
};
|
expect(workExperiences.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
// Mock the database call
|
// Check that each work experience has the expected properties
|
||||||
expect(typeof updateBlogPost).toBe('function');
|
workExperiences.forEach((work) => {
|
||||||
|
expect(work).toHaveProperty('company');
|
||||||
|
expect(work).toHaveProperty('role');
|
||||||
|
expect(work).toHaveProperty('dateStart');
|
||||||
|
expect(work).toHaveProperty('content');
|
||||||
|
expect(work).toHaveProperty('dateEnd');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteBlogPost', () => {
|
describe('getLegalDocuments', () => {
|
||||||
it('should delete a blog post by ID', async () => {
|
it('should return an array of legal documents', async () => {
|
||||||
// Mock the database call
|
const legalDocuments = await getLegalDocuments();
|
||||||
expect(typeof deleteBlogPost).toBe('function');
|
|
||||||
});
|
expect(Array.isArray(legalDocuments)).toBe(true);
|
||||||
});
|
expect(legalDocuments.length).toBeGreaterThan(0);
|
||||||
|
|
||||||
describe('createProject', () => {
|
// Check that each legal document has the expected properties
|
||||||
it('should create a new project with valid data', async () => {
|
legalDocuments.forEach((doc) => {
|
||||||
const projectData = {
|
expect(doc).toHaveProperty('title');
|
||||||
title: "Test Project",
|
expect(doc).toHaveProperty('date');
|
||||||
summary: "Test summary",
|
expect(doc).toHaveProperty('content');
|
||||||
date: new Date(),
|
});
|
||||||
tags: ["test", "project"],
|
|
||||||
draft: false,
|
|
||||||
content: "Test content",
|
|
||||||
demoUrl: "https://example.com/demo",
|
|
||||||
repoUrl: "https://example.com/repo"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof createProject).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('updateProject', () => {
|
|
||||||
it('should update an existing project', async () => {
|
|
||||||
const projectData = {
|
|
||||||
title: "Updated Project",
|
|
||||||
content: "Updated content"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof updateProject).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('deleteProject', () => {
|
|
||||||
it('should delete a project by ID', async () => {
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof deleteProject).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('createWorkExperience', () => {
|
|
||||||
it('should create a new work experience with valid data', async () => {
|
|
||||||
const workData = {
|
|
||||||
company: "Test Company",
|
|
||||||
role: "Test Role",
|
|
||||||
dateStart: new Date(),
|
|
||||||
dateEnd: new Date()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof createWorkExperience).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('updateWorkExperience', () => {
|
|
||||||
it('should update an existing work experience', async () => {
|
|
||||||
const workData = {
|
|
||||||
company: "Updated Company",
|
|
||||||
role: "Updated Role"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof updateWorkExperience).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('deleteWorkExperience', () => {
|
|
||||||
it('should delete a work experience by ID', async () => {
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof deleteWorkExperience).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('createLegalDocument', () => {
|
|
||||||
it('should create a new legal document with valid data', async () => {
|
|
||||||
const docData = {
|
|
||||||
title: "Test Legal Document",
|
|
||||||
date: new Date(),
|
|
||||||
content: "Test content"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof createLegalDocument).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('updateLegalDocument', () => {
|
|
||||||
it('should update an existing legal document', async () => {
|
|
||||||
const docData = {
|
|
||||||
title: "Updated Legal Document",
|
|
||||||
content: "Updated content"
|
|
||||||
};
|
|
||||||
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof updateLegalDocument).toBe('function');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('deleteLegalDocument', () => {
|
|
||||||
it('should delete a legal document by ID', async () => {
|
|
||||||
// Mock the database call
|
|
||||||
expect(typeof deleteLegalDocument).toBe('function');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -93,7 +93,7 @@ if (typeof window === 'undefined') {
|
|||||||
} else {
|
} else {
|
||||||
blogCollection = import.meta.env.PUBLIC_APPWRITE_BLOG_COLLECTION_ID || 'blog';
|
blogCollection = import.meta.env.PUBLIC_APPWRITE_BLOG_COLLECTION_ID || 'blog';
|
||||||
projectsCollection = import.meta.env.PUBLIC_APPWRITE_PROJECTS_COLLECTION_ID || "projects";
|
projectsCollection = import.meta.env.PUBLIC_APPWRITE_PROJECTS_COLLECTION_ID || "projects";
|
||||||
workCollection = import.meta.env.PUBLIC_APPWRITE_WORK_COLLECTION_ID || "work";
|
workCollection = import.meta.env.PUBLIC_APPwrite_WORK_COLLECTION_ID || "work";
|
||||||
legalCollection = import.meta.env.PUBLIC_APPWRITE_LEGAL_COLLECTION_ID || "legal";
|
legalCollection = import.meta.env.PUBLIC_APPWRITE_LEGAL_COLLECTION_ID || "legal";
|
||||||
databaseID = import.meta.env.PUBLIC_APPWRITE_DATABASE_ID || "main";
|
databaseID = import.meta.env.PUBLIC_APPWRITE_DATABASE_ID || "main";
|
||||||
}
|
}
|
||||||
@@ -295,7 +295,7 @@ export async function getLegalDocuments(): Promise<LegalDocument[]> {
|
|||||||
try {
|
try {
|
||||||
const response = await databases.listDocuments<LegalDocument>(
|
const response = await databases.listDocuments<LegalDocument>(
|
||||||
databaseID,
|
databaseID,
|
||||||
workCollection
|
legalCollection
|
||||||
);
|
);
|
||||||
|
|
||||||
return response.documents;
|
return response.documents;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { type APIRoute } from 'astro';
|
import { type APIRoute } from 'astro';
|
||||||
import { getFileUrl, getFilePreviewUrl, getFileDownloadUrl } from '../../../lib/appwrite-service.ts';
|
import { getFileUrl, getFilePreviewUrl } from '../../../lib/appwrite-service.ts';
|
||||||
|
|
||||||
export const GET: APIRoute = async ({ params, request }) => {
|
export const GET: APIRoute = async ({ params, request }) => {
|
||||||
const { fileID } = params;
|
const { fileID } = params;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import TopLayout from "@layouts/TopLayout.astro"
|
|||||||
import BottomLayout from "@layouts/BottomLayout.astro"
|
import BottomLayout from "@layouts/BottomLayout.astro"
|
||||||
import Blog from "@components/Blog"
|
import Blog from "@components/Blog"
|
||||||
import { BLOG } from "@consts"
|
import { BLOG } from "@consts"
|
||||||
import { getBlogPosts, getBlogPostsPaginated } from "@lib/appwrite-service"
|
import { getBlogPostsPaginated } from "@lib/appwrite-service"
|
||||||
|
|
||||||
// Get page and limit from URL parameters
|
// Get page and limit from URL parameters
|
||||||
const url = new URL(typeof window !== 'undefined' ? window.location.href : 'http://localhost')
|
const url = new URL(typeof window !== 'undefined' ? window.location.href : 'http://localhost')
|
||||||
@@ -14,7 +14,7 @@ const page = parseInt(pageParam)
|
|||||||
const limit = parseInt(limitParam)
|
const limit = parseInt(limitParam)
|
||||||
|
|
||||||
// Fetch paginated blog posts
|
// Fetch paginated blog posts
|
||||||
const { posts, total } = await getBlogPostsPaginated(page, limit)
|
const { posts } = await getBlogPostsPaginated(page, limit)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
return result;
|
return result;
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,42 +1,37 @@
|
|||||||
---
|
---
|
||||||
import { type CollectionEntry, getCollection } from "astro:content"
|
|
||||||
import PageLayout from "@layouts/PageLayout.astro"
|
import PageLayout from "@layouts/PageLayout.astro"
|
||||||
import TopLayout from "@layouts/TopLayout.astro"
|
import TopLayout from "@layouts/TopLayout.astro"
|
||||||
import BottomLayout from "@layouts/BottomLayout.astro"
|
import BottomLayout from "@layouts/BottomLayout.astro"
|
||||||
import { formatDate } from "@lib/utils"
|
import { formatDate } from "@lib/utils"
|
||||||
import { SITE } from "@consts"
|
import { SITE } from "@consts"
|
||||||
|
import { getLegalDocuments } from "@lib/appwrite-service"
|
||||||
|
|
||||||
// Create the static pages for legal docs
|
// Get the requested legal doc (simplified approach)
|
||||||
export async function getStaticPaths() {
|
const legalDocs = await getLegalDocuments()
|
||||||
const docs = await getCollection("legal")
|
const doc = legalDocs.find(d => d.$id === Astro.params.slug) || null
|
||||||
return docs.map((doc) => ({
|
|
||||||
params: { slug: doc.slug },
|
if (!doc) {
|
||||||
props: doc,
|
// Handle case where document is not found
|
||||||
}))
|
return new Response("Not Found", { status: 404 })
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the requested legal doc
|
// Skip render() call since we're using Appwrite data directly
|
||||||
type Props = CollectionEntry<"legal">;
|
// const { Content } = await doc.render();
|
||||||
const doc = Astro.props
|
|
||||||
const { title, date } = doc.data
|
|
||||||
const { Content } = await doc.render();
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<PageLayout title={title} description={`${title} for ${SITE.TITLE}`}>
|
<PageLayout title={doc.title} description={`${doc.title} for ${SITE.TITLE}`}>
|
||||||
<TopLayout>
|
<TopLayout>
|
||||||
<div class="animate">
|
<div class="animate">
|
||||||
<div class="page-heading">
|
<div class="page-heading">
|
||||||
{title}
|
{doc.title}
|
||||||
</div>
|
</div>
|
||||||
<p class="font-normal opacity-75">
|
<p class="font-normal opacity-75">
|
||||||
Last updated: {formatDate(date)}
|
Last updated: {formatDate(doc.date)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</TopLayout>
|
</TopLayout>
|
||||||
<BottomLayout>
|
<BottomLayout>
|
||||||
<article class="animate">
|
<article class="animate prose dark:prose-invert text-spaghetti-brown/100 dark:text-spaghetti-cream" set:html={doc.contentHtml}></article>
|
||||||
<Content/>
|
|
||||||
</article>
|
|
||||||
</BottomLayout>
|
</BottomLayout>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
@@ -15,7 +15,7 @@ const page = parseInt(pageParam)
|
|||||||
const limit = parseInt(limitParam)
|
const limit = parseInt(limitParam)
|
||||||
|
|
||||||
// Fetch paginated projects
|
// Fetch paginated projects
|
||||||
const { posts, total } = await getProjectsPaginated(page, limit)
|
const { posts } = await getProjectsPaginated(page, limit)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
console.log(result)
|
console.log(result)
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
+18
-13
@@ -1,30 +1,35 @@
|
|||||||
import rss from "@astrojs/rss"
|
import rss from "@astrojs/rss"
|
||||||
import { getCollection } from "astro:content"
|
|
||||||
import { SITE } from "@consts"
|
import { SITE } from "@consts"
|
||||||
|
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
|
||||||
|
|
||||||
type Context = {
|
type Context = {
|
||||||
site: string
|
site: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET(context: Context) {
|
export async function GET(context: Context) {
|
||||||
const posts = await getCollection("blog")
|
// Get data from Appwrite instead of Astro content collections
|
||||||
const projects = await getCollection("projects")
|
const blogPosts = await getBlogPosts()
|
||||||
|
const projects = await getProjects()
|
||||||
const items = [...posts, ...projects]
|
|
||||||
|
// Combine and sort items by date (most recent first)
|
||||||
items.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime())
|
const items = [...blogPosts, ...projects]
|
||||||
|
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
|
||||||
|
.map((item) => ({
|
||||||
|
title: item.title,
|
||||||
|
description: item.summary,
|
||||||
|
pubDate: item.date,
|
||||||
|
link: item.$collectionId === process.env.VITE_APPWRITE_BLOG_COLLECTION_ID ? `/blog/${item.$id}/` : `/projects/${item.$id}/`,
|
||||||
|
}))
|
||||||
|
|
||||||
return rss({
|
return rss({
|
||||||
title: SITE.TITLE,
|
title: SITE.TITLE,
|
||||||
description: SITE.DESCRIPTION,
|
description: SITE.DESCRIPTION,
|
||||||
site: context.site,
|
site: context.site,
|
||||||
items: items.map((item) => ({
|
items: items.map((item) => ({
|
||||||
title: item.data.title,
|
title: item.title,
|
||||||
description: item.data.summary,
|
description: item.description,
|
||||||
pubDate: item.data.date,
|
pubDate: item.pubDate,
|
||||||
link: item.slug.startsWith("blog")
|
link: item.link,
|
||||||
? `/blog/${item.slug}/`
|
|
||||||
: `/projects/${item.slug}/`,
|
|
||||||
})),
|
})),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user