Files
Spaghet.io/astro.config.mjs
T
spaghet 80577d6404 feat: serve site content from Appwrite TablesDB with .md fallback
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.
2026-11-26 19:29:31 -05:00

68 lines
3.0 KiB
JavaScript

import { defineConfig } from "astro/config"
import mdx from "@astrojs/mdx"
import sitemap from "@astrojs/sitemap"
import solidJs from "@astrojs/solid-js"
import node from "@astrojs/node"
import tailwindcss from "@tailwindcss/vite"
import { readdirSync } from "node:fs"
// The blog/projects/legal detail pages are served from Appwrite at request
// time (prerender = false), so they no longer appear in the build-time route
// list the sitemap integration collects. Compute their URLs from the bundled
// markdown copies — the same files scripts/appwrite-migrate.mjs imports, and
// the fallback source — so the sitemap stays complete without a build-time
// network call.
function contentPages() {
const site = "https://spaghet.io"
const slugs = (dir) =>
readdirSync(new URL(`./src/content/${dir}/`, import.meta.url))
.filter((f) => f.endsWith(".md"))
.map((f) => f.replace(/\.md$/, ""))
return [
...slugs("blog").map((s) => `${site}/blog/${s}/`),
...slugs("projects").map((s) => `${site}/projects/${s}/`),
...slugs("legal").map((s) => `${site}/legal/${s}/`),
]
}
// https://astro.build/config
export default defineConfig({
site: "https://spaghet.io",
integrations: [mdx(), sitemap({ customPages: contentPages() }), solidJs()],
output: "server",
adapter: node({ mode: "ssr" }),
markdown: {
shikiConfig: {
// Two themes plus `defaultColor: false` makes Shiki emit every token as a
// `--shiki-light` / `--shiki-dark` pair instead of a hard-coded `color:`.
// global.css then picks one per mode, so a light-mode reader no longer
// gets a dark gray code block (the old `.prose pre { #1f2937 !important }`
// hack) and a dark-mode reader no longer gets cream-on-cream.
//
// Chosen by measuring every bundled theme's token colours against the
// site's own `code-bg` surfaces, not by eye: the previous vitesse pair
// bottomed out at 1.04:1 (light) and 1.28:1 (dark) — punctuation was
// effectively invisible. `light-plus` reaches ~3.5:1 on white and
// `everforest-dark` ~5.6:1 on the espresso block, and everforest's warm
// red/green/amber palette sits inside the pasta colours rather than
// fighting them.
themes: { light: "light-plus", dark: "everforest-dark" },
defaultColor: false,
},
},
vite: {
plugins: [tailwindcss()],
optimizeDeps: {
// Client-island deps that are not reachable from the SSR entry graph are
// discovered mid-session, which makes Vite re-optimize and bump the browserHash.
// Every already-served island module then 504s with "Outdated Optimize Dep",
// hydration aborts, and the Solid lists on /blog, /projects and /search stay
// empty. Pre-declaring them bundles them at startup so the hash never changes
// underneath a page. Keep this list in sync with the imports of every
// src/components/*.tsx island (solid-js, @lib/utils -> clsx + tailwind-merge,
// @lib/search -> fuse.js).
include: ["solid-js", "solid-js/web", "clsx", "tailwind-merge", "fuse.js"],
},
}
})