create-astroid 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-astroid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "Scaffold a new Astroid site — an editable, multi-editor Astro app on Cloudflare Workers — in one command.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@better-auth/passkey": "^1.7.2",
|
|
36
36
|
"@louise-toolkit/astro": "^0.6.0",
|
|
37
|
-
"astroidjs": "0.
|
|
37
|
+
"astroidjs": "0.21.0",
|
|
38
38
|
"better-auth": "^1.7.2",
|
|
39
39
|
"louise-toolkit": "^0.37.0"
|
|
40
40
|
},
|
|
@@ -2,7 +2,12 @@
|
|
|
2
2
|
// both call this, so every page renders the same way: a visitor sees the live
|
|
3
3
|
// row, and an editor in edit mode sees the latest pending draft laid over it, so
|
|
4
4
|
// in-progress edits resume across reloads.
|
|
5
|
+
import { astroidPageDraft } from "astroidjs/pages";
|
|
5
6
|
import { isPageLive } from "louise-toolkit/content";
|
|
7
|
+
import astroidConfig from "../../astroid.config.js";
|
|
8
|
+
|
|
9
|
+
/** The bindings a page read uses: the database, and the draft buffer. */
|
|
10
|
+
type PageEnv = Pick<CloudflareEnv, "DB" | "DRAFTS">;
|
|
6
11
|
|
|
7
12
|
/** The columns a page render reads. */
|
|
8
13
|
export interface PageRow {
|
|
@@ -58,13 +63,13 @@ function parseSections(raw: unknown): unknown[] {
|
|
|
58
63
|
* `redirectFor` then answers a renamed page's old URL with a redirect.
|
|
59
64
|
*/
|
|
60
65
|
export async function readPage(
|
|
61
|
-
|
|
66
|
+
env: PageEnv,
|
|
62
67
|
slug: string,
|
|
63
68
|
{ editMode, requireLive = true }: ReadPageOptions,
|
|
64
69
|
): Promise<RenderedPage | null> {
|
|
65
70
|
let row: PageRow | null = null;
|
|
66
71
|
try {
|
|
67
|
-
row = await
|
|
72
|
+
row = await env.DB
|
|
68
73
|
.prepare(
|
|
69
74
|
"SELECT id, slug, title, body, sections, status, seo_title, seo_description, og_image, noindex FROM pages WHERE slug = ?",
|
|
70
75
|
)
|
|
@@ -86,30 +91,19 @@ export async function readPage(
|
|
|
86
91
|
};
|
|
87
92
|
if (!editMode) return page;
|
|
88
93
|
|
|
89
|
-
// The
|
|
90
|
-
//
|
|
91
|
-
//
|
|
94
|
+
// The editor's work-in-progress: the DRAFTS buffer first, since every save
|
|
95
|
+
// writes through it and reaches D1 only when it flushes, then the newest
|
|
96
|
+
// pending draft in D1. Reading D1 alone showed an editor who reloaded before
|
|
97
|
+
// the flush an older page than the one they had just saved.
|
|
92
98
|
try {
|
|
93
|
-
const draft = await
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
" ORDER BY id DESC LIMIT 1",
|
|
98
|
-
)
|
|
99
|
-
.bind(row.id)
|
|
100
|
-
.first<{ version_data: string }>();
|
|
101
|
-
if (draft?.version_data) {
|
|
102
|
-
const d = JSON.parse(draft.version_data) as {
|
|
103
|
-
title?: unknown;
|
|
104
|
-
body?: unknown;
|
|
105
|
-
sections?: unknown;
|
|
106
|
-
};
|
|
107
|
-
if (typeof d.title === "string") page.title = d.title;
|
|
108
|
-
if (typeof d.body === "string") page.body = d.body;
|
|
99
|
+
const draft = await astroidPageDraft(astroidConfig, env, row.id);
|
|
100
|
+
if (draft) {
|
|
101
|
+
if (typeof draft.title === "string") page.title = draft.title;
|
|
102
|
+
if (typeof draft.body === "string") page.body = draft.body;
|
|
109
103
|
// Sections stage as drafts like any other field, so edit mode renders the
|
|
110
104
|
// draft's array; otherwise section edits would vanish on reload while
|
|
111
105
|
// title edits survive.
|
|
112
|
-
if (
|
|
106
|
+
if (draft.sections !== undefined) page.sections = parseSections(draft.sections);
|
|
113
107
|
}
|
|
114
108
|
} catch {
|
|
115
109
|
// Non-fatal: fall back to the live row.
|
|
@@ -25,7 +25,7 @@ const slug = Astro.params.slug ?? "";
|
|
|
25
25
|
// `home` is served at "/", never at "/home".
|
|
26
26
|
if (slug === "home") return Astro.redirect("/", 301);
|
|
27
27
|
|
|
28
|
-
const page = slug ? await readPage(env
|
|
28
|
+
const page = slug ? await readPage(env, slug, { editMode }) : null;
|
|
29
29
|
|
|
30
30
|
// Edge caching (ADR 0004), gated exactly as on the home page: never in edit
|
|
31
31
|
// mode, only when ASTROID_EDGE_CACHE is "true", and never for a 404, so a page
|
|
@@ -42,7 +42,7 @@ if (editMode || env.ASTROID_EDGE_CACHE !== "true") {
|
|
|
42
42
|
// `requireLive: false`: an unpublished home keeps rendering rather than turning
|
|
43
43
|
// the site's front door into a 404. Every other page is visitor-visible only
|
|
44
44
|
// while it's live (src/pages/[...slug].astro).
|
|
45
|
-
const page = await readPage(env
|
|
45
|
+
const page = await readPage(env, "home", { editMode, requireLive: false });
|
|
46
46
|
const title = page?.title ?? "__BRAND_NAME__";
|
|
47
47
|
const sections = page?.sections ?? [];
|
|
48
48
|
---
|