Replace astro:content getCollection() reads in all 9 content pages with src/lib/content-source.ts: Appwrite TablesDB (spaghet-home database on appwrite.spaghet.io) first, bundled src/content/*.md fallback on a cold-cache outage. Blog/project/legal detail pages flip from prerender to SSR (content now arrives at request time); sitemap keeps every detail URL via customPages computed from the bundled .md copies. - src/lib/appwrite.ts: TablesDB service (node-appwrite), markdown rendered through Astro's own satteri+shiki pipeline (dual-theme, same config as astro.config.mjs) — article HTML verified byte-identical to production. Public reads: tables grant read(any), no secret required. 60s in-process cache, stale-serving on refresh failure. - src/lib/__tests__/appwrite.test.ts: 11 tests mocking the SDK boundary (the SDK binds its own fetch, so global stubs do not intercept it). - Draft posts now 302 to /blog and drop off listings/RSS/search at request time instead of at build time. - astro check: 0 errors; vitest: 94 pass; build clean; end-to-end verified against live Appwrite and against a forced outage.
47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
// src/lib/content.ts
|
|
import type { CollectionEntry } from "astro:content"
|
|
import type { SearchEntry } from "@lib/types"
|
|
|
|
/**
|
|
* Structural shape of anything the glob loader hands back for a dated
|
|
* collection. Deliberately narrower than CollectionEntry<"blog"> so the
|
|
* comparator can be unit tested without Astro's virtual module.
|
|
*/
|
|
interface DatedEntry {
|
|
id: string
|
|
data: { date: Date }
|
|
}
|
|
|
|
/**
|
|
* The glob loader returns entries in filename order, never by frontmatter
|
|
* date, so every listing page must opt into date ordering explicitly.
|
|
* Equal dates fall back to id to keep the order deterministic across builds
|
|
* (two projects share 2025-08-01).
|
|
*/
|
|
export function byDateDesc(a: DatedEntry, b: DatedEntry): number {
|
|
const diff = b.data.date.getTime() - a.data.date.getTime()
|
|
return diff !== 0 ? diff : a.id.localeCompare(b.id)
|
|
}
|
|
|
|
/**
|
|
* Map a blog or project content entry down to the slim, serializable shape
|
|
* used by ArrowCard and the search index. Centralising this keeps every page
|
|
* (home, blog, projects, search) emitting identical card props.
|
|
*/
|
|
export function toSearchEntry(
|
|
entry:
|
|
| CollectionEntry<"blog">
|
|
| CollectionEntry<"projects">
|
|
| { id: string; collection: "blog" | "projects"; data: { title: string; summary: string; date: Date; tags: string[] } }
|
|
): SearchEntry {
|
|
return {
|
|
id: entry.id,
|
|
slug: entry.id,
|
|
collection: entry.collection as "blog" | "projects",
|
|
title: entry.data.title,
|
|
summary: entry.data.summary,
|
|
tags: entry.data.tags,
|
|
date: entry.data.date.toISOString(),
|
|
}
|
|
}
|