the editable demo site: astro + vendored sveltia CMS + actions pipeline
deploy / build-and-publish (push) Successful in 1m31s

This commit is contained in:
Keith
2026-11-20 21:47:35 +01:00
commit c83c3b528d
16 changed files with 6471 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
# The editable-site pipeline: every push to main builds the astro site
# and swaps it into the publish directory Caddy serves (astro.<base> +
# the apex + www). The runner binds /var/lib/astro-site into the job
# container at /srv/site (see the app-seed extras nix module).
name: deploy
on:
push:
branches: [main]
jobs:
build-and-publish:
runs-on: node
steps:
- uses: actions/checkout@v4
- name: Build the site
run: |
npm --prefix site ci
npm --prefix site run build
- name: Publish (atomic dir swap)
run: |
set -euo pipefail
rm -rf /srv/site/current.new
cp -r site/dist /srv/site/current.new
rm -rf /srv/site/current.old
if [ -d /srv/site/current ]; then mv /srv/site/current /srv/site/current.old; fi
mv /srv/site/current.new /srv/site/current
rm -rf /srv/site/current.old
+12
View File
@@ -0,0 +1,12 @@
node_modules/
site/node_modules/
site/dist/
.env
# The vendored CMS bundle is build output (site/copy-cms.mjs copies it
# from node_modules on every build); only the admin page + config are
# tracked.
site/public/admin/sveltia-cms.js
site/public/admin/sveltia-cms.mjs
site/public/admin/sveltia-cms.mjs.map
site/public/admin/sveltia-cms.js.map
site/public/admin/chunks/
+10
View File
@@ -0,0 +1,10 @@
{
"name": "demo-site",
"private": true,
"type": "module",
"description": "The appz-toolkit demo: a static astro site whose content non-technical people edit in the browser via Sveltia CMS (PKCE against the box's Gitea). Saves commit to this repo; Gitea Actions rebuilds and republishes the site.",
"scripts": {
"build:site": "npm --prefix site ci && npm --prefix site run build",
"build": "npm run build:site"
}
}
+1
View File
@@ -0,0 +1 @@
export default new Map();
+1
View File
@@ -0,0 +1 @@
export default new Map();
+199
View File
@@ -0,0 +1,199 @@
declare module 'astro:content' {
export interface RenderResult {
Content: import('astro/runtime/server/index.js').AstroComponentFactory;
headings: import('astro').MarkdownHeading[];
remarkPluginFrontmatter: Record<string, any>;
}
interface Render {
'.md': Promise<RenderResult>;
}
export interface RenderedContent {
html: string;
metadata?: {
imagePaths: Array<string>;
[key: string]: unknown;
};
}
}
declare module 'astro:content' {
type Flatten<T> = T extends { [K: string]: infer U } ? U : never;
export type CollectionKey = keyof AnyEntryMap;
export type CollectionEntry<C extends CollectionKey> = Flatten<AnyEntryMap[C]>;
export type ContentCollectionKey = keyof ContentEntryMap;
export type DataCollectionKey = keyof DataEntryMap;
type AllValuesOf<T> = T extends any ? T[keyof T] : never;
type ValidContentEntrySlug<C extends keyof ContentEntryMap> = AllValuesOf<
ContentEntryMap[C]
>['slug'];
export type ReferenceDataEntry<
C extends CollectionKey,
E extends keyof DataEntryMap[C] = string,
> = {
collection: C;
id: E;
};
export type ReferenceContentEntry<
C extends keyof ContentEntryMap,
E extends ValidContentEntrySlug<C> | (string & {}) = string,
> = {
collection: C;
slug: E;
};
export type ReferenceLiveEntry<C extends keyof LiveContentConfig['collections']> = {
collection: C;
id: string;
};
/** @deprecated Use `getEntry` instead. */
export function getEntryBySlug<
C extends keyof ContentEntryMap,
E extends ValidContentEntrySlug<C> | (string & {}),
>(
collection: C,
// Note that this has to accept a regular string too, for SSR
entrySlug: E,
): E extends ValidContentEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
/** @deprecated Use `getEntry` instead. */
export function getDataEntryById<C extends keyof DataEntryMap, E extends keyof DataEntryMap[C]>(
collection: C,
entryId: E,
): Promise<CollectionEntry<C>>;
export function getCollection<C extends keyof AnyEntryMap, E extends CollectionEntry<C>>(
collection: C,
filter?: (entry: CollectionEntry<C>) => entry is E,
): Promise<E[]>;
export function getCollection<C extends keyof AnyEntryMap>(
collection: C,
filter?: (entry: CollectionEntry<C>) => unknown,
): Promise<CollectionEntry<C>[]>;
export function getLiveCollection<C extends keyof LiveContentConfig['collections']>(
collection: C,
filter?: LiveLoaderCollectionFilterType<C>,
): Promise<
import('astro').LiveDataCollectionResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>
>;
export function getEntry<
C extends keyof ContentEntryMap,
E extends ValidContentEntrySlug<C> | (string & {}),
>(
entry: ReferenceContentEntry<C, E>,
): E extends ValidContentEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
export function getEntry<
C extends keyof DataEntryMap,
E extends keyof DataEntryMap[C] | (string & {}),
>(
entry: ReferenceDataEntry<C, E>,
): E extends keyof DataEntryMap[C]
? Promise<DataEntryMap[C][E]>
: Promise<CollectionEntry<C> | undefined>;
export function getEntry<
C extends keyof ContentEntryMap,
E extends ValidContentEntrySlug<C> | (string & {}),
>(
collection: C,
slug: E,
): E extends ValidContentEntrySlug<C>
? Promise<CollectionEntry<C>>
: Promise<CollectionEntry<C> | undefined>;
export function getEntry<
C extends keyof DataEntryMap,
E extends keyof DataEntryMap[C] | (string & {}),
>(
collection: C,
id: E,
): E extends keyof DataEntryMap[C]
? string extends keyof DataEntryMap[C]
? Promise<DataEntryMap[C][E]> | undefined
: Promise<DataEntryMap[C][E]>
: Promise<CollectionEntry<C> | undefined>;
export function getLiveEntry<C extends keyof LiveContentConfig['collections']>(
collection: C,
filter: string | LiveLoaderEntryFilterType<C>,
): Promise<import('astro').LiveDataEntryResult<LiveLoaderDataType<C>, LiveLoaderErrorType<C>>>;
/** Resolve an array of entry references from the same collection */
export function getEntries<C extends keyof ContentEntryMap>(
entries: ReferenceContentEntry<C, ValidContentEntrySlug<C>>[],
): Promise<CollectionEntry<C>[]>;
export function getEntries<C extends keyof DataEntryMap>(
entries: ReferenceDataEntry<C, keyof DataEntryMap[C]>[],
): Promise<CollectionEntry<C>[]>;
export function render<C extends keyof AnyEntryMap>(
entry: AnyEntryMap[C][string],
): Promise<RenderResult>;
export function reference<C extends keyof AnyEntryMap>(
collection: C,
): import('astro/zod').ZodEffects<
import('astro/zod').ZodString,
C extends keyof ContentEntryMap
? ReferenceContentEntry<C, ValidContentEntrySlug<C>>
: ReferenceDataEntry<C, keyof DataEntryMap[C]>
>;
// Allow generic `string` to avoid excessive type errors in the config
// if `dev` is not running to update as you edit.
// Invalid collection names will be caught at build time.
export function reference<C extends string>(
collection: C,
): import('astro/zod').ZodEffects<import('astro/zod').ZodString, never>;
type ReturnTypeOrOriginal<T> = T extends (...args: any[]) => infer R ? R : T;
type InferEntrySchema<C extends keyof AnyEntryMap> = import('astro/zod').infer<
ReturnTypeOrOriginal<Required<ContentConfig['collections'][C]>['schema']>
>;
type ContentEntryMap = {
};
type DataEntryMap = {
};
type AnyEntryMap = ContentEntryMap & DataEntryMap;
type ExtractLoaderTypes<T> = T extends import('astro/loaders').LiveLoader<
infer TData,
infer TEntryFilter,
infer TCollectionFilter,
infer TError
>
? { data: TData; entryFilter: TEntryFilter; collectionFilter: TCollectionFilter; error: TError }
: { data: never; entryFilter: never; collectionFilter: never; error: never };
type ExtractDataType<T> = ExtractLoaderTypes<T>['data'];
type ExtractEntryFilterType<T> = ExtractLoaderTypes<T>['entryFilter'];
type ExtractCollectionFilterType<T> = ExtractLoaderTypes<T>['collectionFilter'];
type ExtractErrorType<T> = ExtractLoaderTypes<T>['error'];
type LiveLoaderDataType<C extends keyof LiveContentConfig['collections']> =
LiveContentConfig['collections'][C]['schema'] extends undefined
? ExtractDataType<LiveContentConfig['collections'][C]['loader']>
: import('astro/zod').infer<
Exclude<LiveContentConfig['collections'][C]['schema'], undefined>
>;
type LiveLoaderEntryFilterType<C extends keyof LiveContentConfig['collections']> =
ExtractEntryFilterType<LiveContentConfig['collections'][C]['loader']>;
type LiveLoaderCollectionFilterType<C extends keyof LiveContentConfig['collections']> =
ExtractCollectionFilterType<LiveContentConfig['collections'][C]['loader']>;
type LiveLoaderErrorType<C extends keyof LiveContentConfig['collections']> = ExtractErrorType<
LiveContentConfig['collections'][C]['loader']
>;
export type ContentConfig = typeof import("../src/content.config.mjs");
export type LiveContentConfig = never;
}
+2
View File
@@ -0,0 +1,2 @@
/// <reference types="astro/client" />
/// <reference path="content.d.ts" />
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from "astro/config";
// The canonical public origin (Caddy serves the pipeline's output at
// astro.<base> + the apex + www).
export default defineConfig({
site: "https://astro.iwrote.it",
});
+32
View File
@@ -0,0 +1,32 @@
// Copies the locally installed @sveltia/cms bundle into public/admin so
// the CMS page is fully self-hosted: the site bakes the bundle into its
// static output and nothing loads from a CDN at runtime. The bundle
// references its per-backend chunks relative to itself, so the chunks
// tree rides along. Source maps and the ESM wrapper stay out — the
// admin page loads sveltia-cms.js with a plain script tag.
//
// NOTE: the package's "." export is the bundler API wrapper
// (npm/index.js), NOT the standalone browser bundle — the script tag
// always loads dist/sveltia-cms.js.
import { cpSync, rmSync, readdirSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
const distDir = join(process.cwd(), "node_modules", "@sveltia/cms", "dist");
const destDir = join(fileURLToPath(new URL(".", import.meta.url)), "public", "admin");
// Only the build outputs are removed — index.html and config.yml live in
// this directory and are tracked in git.
for (const stale of ["sveltia-cms.js", "sveltia-cms.mjs", "chunks"]) {
rmSync(join(destDir, stale), { recursive: true, force: true });
}
for (const entry of readdirSync(distDir)) {
if (entry === "sveltia-cms.mjs" || entry.endsWith(".map")) continue;
cpSync(join(distDir, entry), join(destDir, entry), {
recursive: true,
filter: (src) => !src.endsWith(".map"),
});
}
console.log(`copied @sveltia/cms dist -> ${destDir}`);
+6001
View File
File diff suppressed because it is too large Load Diff
+16
View File
@@ -0,0 +1,16 @@
{
"name": "demo-site",
"type": "module",
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "npm run copy:cms && astro dev",
"build": "npm run copy:cms && astro build",
"preview": "astro preview",
"copy:cms": "node copy-cms.mjs"
},
"dependencies": {
"@sveltia/cms": "^0.266.0",
"astro": "^5.0.0"
}
}
+44
View File
@@ -0,0 +1,44 @@
# yaml-language-server: $schema=https://unpkg.com/@sveltia/cms/schema/sveltia-cms.json
# The CMS for the editable-site flow: the admin page is served from the
# site itself (/admin/), sign-in is a browser-only PKCE OAuth2 flow
# against the box's Gitea — no token-exchange server, no client secret,
# the editor person never sees git. Every save commits straight to the
# site repository, and the Gitea Actions pipeline rebuilds + republishes
# the site.
#
# BOOTSTRAP NOTE: `app_id` (and, if the repo owner differs, `repo`) is
# filled by the deploy bootstrap — the OAuth2 application only exists
# once the Gitea instance is up. See the deploy-selfhosted skill's
# "Server-level extras (Gitea + Astro)" section.
backend:
name: gitea
repo: editor/site
base_url: https://gitea.iwrote.it
api_root: https://gitea.iwrote.it/api/v1
app_id: 3bec47fe-e7c9-4b8f-9ca6-200b78c480fa
# Uploaded images live in the site's static tree (Astro copies public/
# to the build root), so editors can drop images into pages and they
# resolve on the published site.
media_folder: /site/public/uploads
public_folder: /uploads
collections:
- name: pages
label: Pages
label_singular: Page
folder: /site/src/pages
extension: md
format: yaml-frontmatter
create: false # v1: the fixed page set; the site nav is static
delete: false # removing a page would break the nav mid-build
slug: "{{slug}}"
identifier_field: title
summary: "{{title}}"
fields:
- { label: Title, name: title, widget: string }
- { label: Layout, name: layout, widget: hidden, default: ../layouts/Site.astro }
- label: Body
name: body
widget: richtext
hint: The page content, edited visually. Everything here is published as the page's main content.
+11
View File
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex" />
<title>Sveltia CMS</title>
</head>
<body>
<script src="sveltia-cms.js"></script>
</body>
</html>
+78
View File
@@ -0,0 +1,78 @@
---
const pages = [
{ href: "/", label: "Home" },
{ href: "/about", label: "About" },
];
// Markdown pages hand their frontmatter to the layout as `frontmatter`.
const { title } = Astro.props.frontmatter ?? Astro.props;
---
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>{title}</title>
<style is:global>
:root {
--ink: #1f2937;
--muted: #6b7280;
--accent: #4f46e5;
--line: #e5e7eb;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
color: var(--ink);
line-height: 1.65;
}
nav {
display: flex;
gap: 1.25rem;
align-items: center;
padding: 0.9rem 2rem;
border-bottom: 1px solid var(--line);
}
nav .brand { font-weight: 700; margin-right: auto; }
nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
nav a:hover, nav a[aria-current="page"] { color: var(--accent); }
main { max-width: 44rem; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
/* Rendered ancient-user content: readable prose defaults. */
main :is(h1, h2, h3) { line-height: 1.25; }
main h1 { font-size: 2.1rem; margin: 0 0 1.25rem; }
main h2 { font-size: 1.45rem; margin-top: 2.25rem; }
main img { max-width: 100%; height: auto; border-radius: 0.5rem; }
main blockquote {
margin: 1.5rem 0;
padding: 0.5rem 1.25rem;
border-left: 3px solid var(--accent);
color: var(--muted);
}
main ul, main ol { padding-inline-start: 1.5rem; }
footer {
border-top: 1px solid var(--line);
color: var(--muted);
font-size: 0.85rem;
padding: 1.25rem 2rem;
text-align: center;
}
</style>
</head>
<body>
<nav>
<span class="brand">I Wrote It — demo</span>
{pages.map((p) => (
<a href={p.href} aria-current={Astro.url.pathname === p.href ? "page" : undefined}>
{p.label}
</a>
))}
</nav>
<main>
<slot />
</main>
<footer>
This page is editable in the browser at
<a href="/admin/">/admin/</a> — no git knowledge required.
</footer>
</body>
</html>
+15
View File
@@ -0,0 +1,15 @@
---
layout: ../layouts/Site.astro
title: About
---
<h1>About this demo</h1>
<p>This site is the proof of the appz-toolkit self-hosted platform: an ordinary marketing-style front page whose content is edited by a <a href="/admin/">browser-based visual editor</a>, with <strong>no git knowledge needed</strong>.</p>
<blockquote>
Behind every save is a normal git commit in an auditable Gitea repository on this server — editors never see that part.
</blockquote>
<h2>The stack on this box</h2>
<ul>
<li>The site: static <a href="https://astro.build">Astro</a>, rebuilt by Gitea Actions on every save.</li>
<li>The editor: <a href="https://sveltiacms.app">Sveltia CMS</a>, served from the site itself at <a href="/admin/">/admin/</a> and signing in against Gitea.</li>
<li>The app: the app-factory demo application, running on the Convex backend also hosted here.</li>
</ul>
+12
View File
@@ -0,0 +1,12 @@
---
layout: ../layouts/Site.astro
title: Home
---
<h1>I Wrote It</h1>
<p><strong>A demo of the editable-site flow.</strong> This page is a plain static astro page — but everything below this line was written by a <em>non-technical person in a browser</em>, committed through the <a href="/admin/">site editor</a> and rebuilt by Gitea Actions on this server.</p>
<h2>How it works</h2>
<ol>
<li>Sign in at <a href="/admin/">iwrote.it/admin/</a>.</li>
<li>Edit the page in the visual editor and press Save.</li>
<li>The editor commits your change to the site's git repository behind the scenes — the rebuild runs, and about a minute later the change is live here.</li>
</ol>