diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index b182682..4b3fef0 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -1,5 +1,4 @@ --- -import { ViewTransitions } from "astro:transitions" interface Props { title: string diff --git a/src/components/Blog.tsx b/src/components/Blog.tsx index 8e90c37..2927deb 100644 --- a/src/components/Blog.tsx +++ b/src/components/Blog.tsx @@ -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()) - const [posts, setPosts] = createSignal[]>([]) + const [posts, setPosts] = createSignal([]) createEffect(() => { setPosts(data.filter((entry) => { diff --git a/src/components/Projects.tsx b/src/components/Projects.tsx index c1701b2..84cd387 100644 --- a/src/components/Projects.tsx +++ b/src/components/Projects.tsx @@ -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()) - const [projects, setProjects] = createSignal[]>([]) + const [projects, setProjects] = createSignal([]) createEffect(() => { setProjects(data.filter((entry) => diff --git a/src/components/Search.tsx b/src/components/Search.tsx index 5ce4f3c..dde9178 100644 --- a/src/components/Search.tsx +++ b/src/components/Search.tsx @@ -114,7 +114,7 @@ export default function Search(props: Props) {
Projects
    - {results().projects.map((result, index) => ( + {results().projects.map(result => (
  • diff --git a/src/components/__tests__/Blog.test.tsx b/src/components/__tests__/Blog.test.tsx deleted file mode 100644 index 68ef735..0000000 --- a/src/components/__tests__/Blog.test.tsx +++ /dev/null @@ -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(() => ( - - )); - - expect(container).toBeInTheDocument(); - }); - - it('should display the correct number of posts', () => { - const { container } = render(() => ( - - )); - - // Should have at least one post displayed - const postElements = container.querySelectorAll('li'); - expect(postElements.length).toBeGreaterThan(0); - }); -}); diff --git a/src/layouts/ArticleBottomLayout.astro b/src/layouts/ArticleBottomLayout.astro index bbf90e4..1b26918 100644 --- a/src/layouts/ArticleBottomLayout.astro +++ b/src/layouts/ArticleBottomLayout.astro @@ -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") { )} {nextEntry && ( - +
    Next @@ -81,14 +80,14 @@ if (collection === "blog") { {nextEntry.title}
    - +
    )} {!prevEntry && !nextEntry && ( -
    +
    No adjacent articles available
    )} diff --git a/src/lib/__tests__/appwrite-service.test.ts b/src/lib/__tests__/appwrite-service.test.ts index c691e8d..479ceaa 100644 --- a/src/lib/__tests__/appwrite-service.test.ts +++ b/src/lib/__tests__/appwrite-service.test.ts @@ -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'); + }); }); }); }); diff --git a/src/lib/appwrite-service.ts b/src/lib/appwrite-service.ts index 860f9b9..ed60706 100644 --- a/src/lib/appwrite-service.ts +++ b/src/lib/appwrite-service.ts @@ -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 { try { const response = await databases.listDocuments( databaseID, - workCollection + legalCollection ); return response.documents; diff --git a/src/pages/api/assets/[fileID].ts b/src/pages/api/assets/[fileID].ts index 685080c..9503cb0 100644 --- a/src/pages/api/assets/[fileID].ts +++ b/src/pages/api/assets/[fileID].ts @@ -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; diff --git a/src/pages/blog/index.astro b/src/pages/blog/index.astro index 8737eb4..b9be979 100644 --- a/src/pages/blog/index.astro +++ b/src/pages/blog/index.astro @@ -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; }) diff --git a/src/pages/legal/[...slug].astro b/src/pages/legal/[...slug].astro index afd4c06..2f5bdc1 100644 --- a/src/pages/legal/[...slug].astro +++ b/src/pages/legal/[...slug].astro @@ -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(); --- - +
    - {title} + {doc.title}

    - Last updated: {formatDate(date)} + Last updated: {formatDate(doc.date)}

    -
    - -
    +
    -
    \ No newline at end of file +
    diff --git a/src/pages/projects/index.astro b/src/pages/projects/index.astro index 8ed5283..70cbe47 100644 --- a/src/pages/projects/index.astro +++ b/src/pages/projects/index.astro @@ -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; diff --git a/src/pages/rss.xml.ts b/src/pages/rss.xml.ts index 93a2683..f9a886e 100644 --- a/src/pages/rss.xml.ts +++ b/src/pages/rss.xml.ts @@ -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, })), }) }