@yysng/astro-boilerplate 1.1.10 → 1.1.12
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,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { CONTENT_REGISTRY } from "./registry.js";
|
|
2
|
+
import { readLocal } from "./storage.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
);
|
|
4
|
+
export async function loadContent(key, env = {}) {
|
|
5
|
+
const entry = CONTENT_REGISTRY[key];
|
|
6
|
+
if (!entry) throw new Error(`Unknown content key: ${key}`);
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!mod || !mod.default) {
|
|
13
|
-
throw new Error(`Content not found: ${path}`);
|
|
8
|
+
// Cloudflare production
|
|
9
|
+
if (env.CONTENT_KV) {
|
|
10
|
+
const stored = await env.CONTENT_KV.get(entry.file, "json");
|
|
11
|
+
if (stored) return stored;
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// Local development fallback
|
|
15
|
+
return await readLocal(entry.file);
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import fs from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { getContentRoot } from "./config.js";
|
|
4
|
+
|
|
5
|
+
export async function readLocal(file) {
|
|
6
|
+
const filePath = path.join(getContentRoot(), file);
|
|
7
|
+
const raw = await fs.readFile(filePath, "utf-8");
|
|
8
|
+
return JSON.parse(raw);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function writeLocal(file, data) {
|
|
12
|
+
const filePath = path.join(getContentRoot(), file);
|
|
13
|
+
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
|
|
14
|
+
}
|
|
@@ -1,41 +1,16 @@
|
|
|
1
|
-
import fs from "fs/promises";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { CONTENT_REGISTRY } from "./registry.js";
|
|
4
1
|
import { schemas } from "./schemas.js";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function logAuditEvent({ section, incoming, merged }) {
|
|
9
|
-
const timestamp = new Date().toISOString();
|
|
10
|
-
|
|
11
|
-
console.log("[AI-EDIT]", {
|
|
12
|
-
section,
|
|
13
|
-
timestamp,
|
|
14
|
-
incoming, // what AI attempted to change
|
|
15
|
-
result: merged // final persisted state
|
|
16
|
-
});
|
|
17
|
-
}
|
|
2
|
+
import { loadContent } from "./loader.js";
|
|
3
|
+
import { writeLocal } from "./storage.js";
|
|
4
|
+
import { CONTENT_REGISTRY } from "./registry.js";
|
|
18
5
|
|
|
19
|
-
/**
|
|
20
|
-
* Merge only defined values from `incoming` into `existing`.
|
|
21
|
-
* - Undefined fields do NOT overwrite existing values
|
|
22
|
-
* - Nested objects (e.g. CTA) are merged recursively
|
|
23
|
-
*/
|
|
24
6
|
function mergeDefined(existing, incoming) {
|
|
25
7
|
const result = { ...existing };
|
|
26
8
|
|
|
27
9
|
for (const key of Object.keys(incoming)) {
|
|
28
10
|
const value = incoming[key];
|
|
29
|
-
|
|
30
|
-
// Skip undefined (true partial update behavior)
|
|
31
11
|
if (value === undefined) continue;
|
|
32
12
|
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
typeof value === "object" &&
|
|
36
|
-
value !== null &&
|
|
37
|
-
!Array.isArray(value)
|
|
38
|
-
) {
|
|
13
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
39
14
|
result[key] = mergeDefined(existing[key] || {}, value);
|
|
40
15
|
} else {
|
|
41
16
|
result[key] = value;
|
|
@@ -45,42 +20,24 @@ function mergeDefined(existing, incoming) {
|
|
|
45
20
|
return result;
|
|
46
21
|
}
|
|
47
22
|
|
|
48
|
-
export async function updateContent(key, incoming) {
|
|
49
|
-
if (!incoming || typeof incoming !== "object") {
|
|
50
|
-
throw new Error("Incoming content must be an object");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const entry = CONTENT_REGISTRY[key];
|
|
54
|
-
if (!entry) {
|
|
55
|
-
throw new Error(`Unknown content key: ${key}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
23
|
+
export async function updateContent(key, incoming, env = {}) {
|
|
58
24
|
const schema = schemas[key];
|
|
59
|
-
if (!schema) {
|
|
60
|
-
throw new Error(`No schema defined for content key: ${key}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const filePath = path.join(getContentRoot(), entry.file);
|
|
25
|
+
if (!schema) throw new Error(`No schema for ${key}`);
|
|
64
26
|
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const raw = await fs.readFile(filePath, "utf-8");
|
|
68
|
-
existing = JSON.parse(raw);
|
|
69
|
-
} catch {}
|
|
27
|
+
const entry = CONTENT_REGISTRY[key];
|
|
70
28
|
|
|
29
|
+
const existing = await loadContent(key, env);
|
|
71
30
|
const merged = mergeDefined(existing, incoming);
|
|
72
31
|
|
|
73
32
|
schema.validate(merged);
|
|
74
33
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
merged
|
|
79
|
-
}
|
|
34
|
+
// Cloudflare
|
|
35
|
+
if (env.CONTENT_KV) {
|
|
36
|
+
await env.CONTENT_KV.put(entry.file, JSON.stringify(merged));
|
|
37
|
+
return merged;
|
|
38
|
+
}
|
|
80
39
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"utf-8"
|
|
85
|
-
);
|
|
40
|
+
// Local dev
|
|
41
|
+
await writeLocal(entry.file, merged);
|
|
42
|
+
return merged;
|
|
86
43
|
}
|