Refactor content handling to use Appwrite service instead of Astro collections, remove ViewTransitions import, update test files accordingly

This commit is contained in:
Spaghet committed 2025-08-23 20:10:43 -04:00
1 parent 9cc9768121
commit c9948befaf
13 files changed
+111 -256

No files matched your search

-1
View File
@@ -1,5 +1,4 @@
---
import { ViewTransitions } from "astro:transitions"
interface Props {
title: string
+3 -3
View File
@@ -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 ArrowCard from "@components/ArrowCard"
import { cn } from "@lib/utils"
type Props = {
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) {
const [filter, setFilter] = createSignal(new Set<string>())
const [posts, setPosts] = createSignal<CollectionEntry<"blog">[]>([])
const [posts, setPosts] = createSignal<BlogPost[]>([])
createEffect(() => {
setPosts(data.filter((entry) => {
+3 -3
View File
@@ -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 ArrowCard from "@components/ArrowCard"
import { cn } from "@lib/utils"
type Props = {
tags: string[]
data: CollectionEntry<"projects">[] | any[]
data: Project[] | any[]
}
export default function Projects({ data, tags }: Props) {
const [filter, setFilter] = createSignal(new Set<string>())
const [projects, setProjects] = createSignal<CollectionEntry<"projects">[]>([])
const [projects, setProjects] = createSignal<Project[]>([])
createEffect(() => {
setProjects(data.filter((entry) =>
+1 -1
View File
@@ -114,7 +114,7 @@ export default function Search(props: Props) {
<div class="border-t border-spaghetti-yellow/30 pt-4">
<div class="text-sm font-bold mb-2">Projects</div>
<ul class="flex flex-col gap-3">
{results().projects.map((result, index) => (
{results().projects.map(result => (
<li>
<ArrowCard entry={result} pill={true} collection={'projects'} />
</li>
-48
View File
@@ -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);
});
});
+3 -4
View File
@@ -1,6 +1,5 @@
---
import type { BlogPost, Project } from "@lib/appwrite-service"
import { formatDate, readingTime } from "@lib/utils"
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
type Props = {
@@ -72,7 +71,7 @@ if (collection === "blog") {
</a>
)}
{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="text-sm uppercase">
Next
@@ -81,14 +80,14 @@ if (collection === "blog") {
{nextEntry.title}
</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" />
<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>
</a>
)}
{!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
</div>
)}
+62 -157
View File
@@ -1,175 +1,80 @@
import { describe, it, expect, vi } from 'vitest';
import { getBlogTemplates, createBlogPost, updateBlogPost, deleteBlogPost, createProject, updateProject, deleteProject, createWorkExperience, updateWorkExperience, deleteWorkExperience, createLegalDocument, updateLegalDocument, deleteLegalDocument } from '../appwrite-service';
import { describe, it, expect } from 'vitest';
import { getBlogPosts, getProjects, getWorkExperiences, getLegalDocuments } from '../appwrite-service';
describe('AppWrite Service', () => {
describe('getBlogTemplates', () => {
it('should return an array of blog templates', async () => {
const templates = await getBlogTemplates();
describe('getBlogPosts', () => {
it('should return an array of blog posts', async () => {
const posts = await getBlogPosts();
expect(Array.isArray(templates)).toBe(true);
expect(templates.length).toBeGreaterThan(0);
expect(Array.isArray(posts)).toBe(true);
expect(posts.length).toBeGreaterThan(0);
// Check that each template has the expected properties
templates.forEach(template => {
expect(template).toHaveProperty('id');
expect(template).toHaveProperty('name');
expect(template).toHaveProperty('slug');
// Check that each post has the expected properties
posts.forEach((post) => {
expect(post).toHaveProperty('title');
expect(post).toHaveProperty('summary');
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 () => {
const templates = await getBlogTemplates();
describe('getProjects', () => {
it('should return an array of projects', async () => {
const projects = await getProjects();
// Should contain default, feature and news templates
const templateIds = templates.map(t => t.id);
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
};
expect(Array.isArray(projects)).toBe(true);
expect(projects.length).toBeGreaterThan(0);
// This test would require mocking the databases.createDocument call
expect(typeof createBlogPost).toBe('function');
// Check that each project has the expected properties
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', () => {
it('should update an existing blog post', async () => {
const postData = {
title: "Updated Blog Post",
content: "Updated content"
};
// Mock the database call
expect(typeof updateBlogPost).toBe('function');
describe('getWorkExperiences', () => {
it('should return an array of work experiences', async () => {
const workExperiences = await getWorkExperiences();
expect(Array.isArray(workExperiences)).toBe(true);
expect(workExperiences.length).toBeGreaterThan(0);
// Check that each work experience has the expected properties
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', () => {
it('should delete a blog post by ID', async () => {
// Mock the database call
expect(typeof deleteBlogPost).toBe('function');
});
});
describe('createProject', () => {
it('should create a new project with valid data', async () => {
const projectData = {
title: "Test Project",
summary: "Test summary",
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');
describe('getLegalDocuments', () => {
it('should return an array of legal documents', async () => {
const legalDocuments = await getLegalDocuments();
expect(Array.isArray(legalDocuments)).toBe(true);
expect(legalDocuments.length).toBeGreaterThan(0);
// Check that each legal document has the expected properties
legalDocuments.forEach((doc) => {
expect(doc).toHaveProperty('title');
expect(doc).toHaveProperty('date');
expect(doc).toHaveProperty('content');
});
});
});
});
+2 -2
View File
@@ -93,7 +93,7 @@ if (typeof window === 'undefined') {
} else {
blogCollection = import.meta.env.PUBLIC_APPWRITE_BLOG_COLLECTION_ID || 'blog';
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";
databaseID = import.meta.env.PUBLIC_APPWRITE_DATABASE_ID || "main";
}
@@ -295,7 +295,7 @@ export async function getLegalDocuments(): Promise<LegalDocument[]> {
try {
const response = await databases.listDocuments<LegalDocument>(
databaseID,
workCollection
legalCollection
);
return response.documents;
+1 -1
View File
@@ -1,5 +1,5 @@
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 }) => {
const { fileID } = params;
+2 -2
View File
@@ -4,7 +4,7 @@ import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import Blog from "@components/Blog"
import { BLOG } from "@consts"
import { getBlogPosts, getBlogPostsPaginated } from "@lib/appwrite-service"
import { getBlogPostsPaginated } from "@lib/appwrite-service"
// Get page and limit from URL parameters
const url = new URL(typeof window !== 'undefined' ? window.location.href : 'http://localhost')
@@ -14,7 +14,7 @@ const page = parseInt(pageParam)
const limit = parseInt(limitParam)
// Fetch paginated blog posts
const { posts, total } = await getBlogPostsPaginated(page, limit)
const { posts } = await getBlogPostsPaginated(page, limit)
.then(result => {
return result;
})
+15 -20
View File
@@ -1,42 +1,37 @@
---
import { type CollectionEntry, getCollection } from "astro:content"
import PageLayout from "@layouts/PageLayout.astro"
import TopLayout from "@layouts/TopLayout.astro"
import BottomLayout from "@layouts/BottomLayout.astro"
import { formatDate } from "@lib/utils"
import { SITE } from "@consts"
import { getLegalDocuments } from "@lib/appwrite-service"
// Create the static pages for legal docs
export async function getStaticPaths() {
const docs = await getCollection("legal")
return docs.map((doc) => ({
params: { slug: doc.slug },
props: doc,
}))
// Get the requested legal doc (simplified approach)
const legalDocs = await getLegalDocuments()
const doc = legalDocs.find(d => d.$id === Astro.params.slug) || null
if (!doc) {
// Handle case where document is not found
return new Response("Not Found", { status: 404 })
}
// Get the requested legal doc
type Props = CollectionEntry<"legal">;
const doc = Astro.props
const { title, date } = doc.data
const { Content } = await doc.render();
// Skip render() call since we're using Appwrite data directly
// const { Content } = await doc.render();
---
<PageLayout title={title} description={`${title} for ${SITE.TITLE}`}>
<PageLayout title={doc.title} description={`${doc.title} for ${SITE.TITLE}`}>
<TopLayout>
<div class="animate">
<div class="page-heading">
{title}
{doc.title}
</div>
<p class="font-normal opacity-75">
Last updated: {formatDate(date)}
Last updated: {formatDate(doc.date)}
</p>
</div>
</TopLayout>
<BottomLayout>
<article class="animate">
<Content/>
</article>
<article class="animate prose dark:prose-invert text-spaghetti-brown/100 dark:text-spaghetti-cream" set:html={doc.contentHtml}></article>
</BottomLayout>
</PageLayout>
</PageLayout>
+1 -1
View File
@@ -15,7 +15,7 @@ const page = parseInt(pageParam)
const limit = parseInt(limitParam)
// Fetch paginated projects
const { posts, total } = await getProjectsPaginated(page, limit)
const { posts } = await getProjectsPaginated(page, limit)
.then(result => {
console.log(result)
return result;
+18 -13
View File
@@ -1,30 +1,35 @@
import rss from "@astrojs/rss"
import { getCollection } from "astro:content"
import { SITE } from "@consts"
import { getBlogPosts, getProjects } from "@lib/appwrite-service"
type Context = {
site: string
}
export async function GET(context: Context) {
const posts = await getCollection("blog")
const projects = await getCollection("projects")
const items = [...posts, ...projects]
items.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime())
// Get data from Appwrite instead of Astro content collections
const blogPosts = await getBlogPosts()
const projects = await getProjects()
// Combine and sort items by date (most recent first)
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({
title: SITE.TITLE,
description: SITE.DESCRIPTION,
site: context.site,
items: items.map((item) => ({
title: item.data.title,
description: item.data.summary,
pubDate: item.data.date,
link: item.slug.startsWith("blog")
? `/blog/${item.slug}/`
: `/projects/${item.slug}/`,
title: item.title,
description: item.description,
pubDate: item.pubDate,
link: item.link,
})),
})
}