@yysng/astro-boilerplate 1.1.11 → 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,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysng/astro-boilerplate",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1–5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,17 +1,16 @@
1
- // src/content-system/loader.js
1
+ import { CONTENT_REGISTRY } from "./registry.js";
2
+ import { readLocal } from "./storage.js";
2
3
 
3
- const contentModules = import.meta.glob(
4
- '/src/content/*.json',
5
- { eager: true }
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
- export function loadContent(key) {
9
- const path = `/src/content/${key}.json`;
10
- const mod = contentModules[path];
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
- return mod.default;
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,18 +1,7 @@
1
- // src/content-system/updater.js
2
-
3
1
  import { schemas } from "./schemas.js";
4
2
  import { loadContent } from "./loader.js";
5
-
6
- function logAuditEvent({ section, incoming, merged }) {
7
- const timestamp = new Date().toISOString();
8
-
9
- console.log("[AI-EDIT]", {
10
- section,
11
- timestamp,
12
- incoming,
13
- result: merged
14
- });
15
- }
3
+ import { writeLocal } from "./storage.js";
4
+ import { CONTENT_REGISTRY } from "./registry.js";
16
5
 
17
6
  function mergeDefined(existing, incoming) {
18
7
  const result = { ...existing };
@@ -21,11 +10,7 @@ function mergeDefined(existing, incoming) {
21
10
  const value = incoming[key];
22
11
  if (value === undefined) continue;
23
12
 
24
- if (
25
- typeof value === "object" &&
26
- value !== null &&
27
- !Array.isArray(value)
28
- ) {
13
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) {
29
14
  result[key] = mergeDefined(existing[key] || {}, value);
30
15
  } else {
31
16
  result[key] = value;
@@ -35,29 +20,24 @@ function mergeDefined(existing, incoming) {
35
20
  return result;
36
21
  }
37
22
 
38
- export async function updateContent(key, incoming) {
39
- if (!incoming || typeof incoming !== "object") {
40
- throw new Error("Incoming content must be an object");
41
- }
42
-
23
+ export async function updateContent(key, incoming, env = {}) {
43
24
  const schema = schemas[key];
44
- if (!schema) {
45
- throw new Error(`No schema defined for content key: ${key}`);
46
- }
25
+ if (!schema) throw new Error(`No schema for ${key}`);
47
26
 
48
- // Load existing content (edge-safe)
49
- const existing = loadContent(key);
27
+ const entry = CONTENT_REGISTRY[key];
50
28
 
29
+ const existing = await loadContent(key, env);
51
30
  const merged = mergeDefined(existing, incoming);
52
31
 
53
32
  schema.validate(merged);
54
33
 
55
- logAuditEvent({
56
- section: key,
57
- incoming,
58
- merged
59
- });
34
+ // Cloudflare
35
+ if (env.CONTENT_KV) {
36
+ await env.CONTENT_KV.put(entry.file, JSON.stringify(merged));
37
+ return merged;
38
+ }
60
39
 
61
- // EDGE MODE: return merged result only
40
+ // Local dev
41
+ await writeLocal(entry.file, merged);
62
42
  return merged;
63
- }
43
+ }