@yysng/astro-boilerplate 1.1.21 → 1.1.22

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.21",
3
+ "version": "1.1.22",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1–5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -5,13 +5,11 @@ export async function loadContent(key, env = {}) {
5
5
  const entry = CONTENT_REGISTRY[key];
6
6
  if (!entry) throw new Error(`Unknown content key: ${key}`);
7
7
 
8
- // Production: Cloudflare KV
9
8
  if (env?.CONTENT_KV) {
10
9
  const stored = await env.CONTENT_KV.get(entry.file, "json");
11
10
  if (stored) return stored;
12
- throw new Error(`KV missing content for key "${key}" (${entry.file})`);
11
+ throw new Error(`KV missing content for ${entry.file}`);
13
12
  }
14
13
 
15
- // Local dev: filesystem
16
14
  return await readLocal(entry.file);
17
15
  }
@@ -2,28 +2,18 @@ import fs from "fs/promises";
2
2
  import path from "path";
3
3
  import { getContentRoot } from "./config.js";
4
4
 
5
- /**
6
- * Local filesystem read (Node only)
7
- */
8
5
  export async function readLocal(file) {
9
6
  const root = getContentRoot();
10
- if (!root) {
11
- throw new Error("Content root not configured in local environment");
12
- }
7
+ if (!root) throw new Error("Content root not configured");
13
8
 
14
9
  const filePath = path.join(root, file);
15
10
  const raw = await fs.readFile(filePath, "utf-8");
16
11
  return JSON.parse(raw);
17
12
  }
18
13
 
19
- /**
20
- * Local filesystem write (Node only)
21
- */
22
14
  export async function writeLocal(file, data) {
23
15
  const root = getContentRoot();
24
- if (!root) {
25
- throw new Error("Content root not configured in local environment");
26
- }
16
+ if (!root) throw new Error("Content root not configured");
27
17
 
28
18
  const filePath = path.join(root, file);
29
19
  await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
@@ -5,7 +5,6 @@ import { CONTENT_REGISTRY } from "./registry.js";
5
5
 
6
6
  function mergeDefined(existing, incoming) {
7
7
  const result = { ...existing };
8
-
9
8
  for (const key of Object.keys(incoming)) {
10
9
  const value = incoming[key];
11
10
  if (value === undefined) continue;
@@ -16,7 +15,6 @@ function mergeDefined(existing, incoming) {
16
15
  result[key] = value;
17
16
  }
18
17
  }
19
-
20
18
  return result;
21
19
  }
22
20
 
@@ -25,19 +23,16 @@ export async function updateContent(key, incoming, env = {}) {
25
23
  if (!schema) throw new Error(`No schema for ${key}`);
26
24
 
27
25
  const entry = CONTENT_REGISTRY[key];
28
-
29
26
  const existing = await loadContent(key, env);
30
27
  const merged = mergeDefined(existing, incoming);
31
28
 
32
29
  schema.validate(merged);
33
30
 
34
- // Production: Cloudflare KV
35
31
  if (env?.CONTENT_KV) {
36
32
  await env.CONTENT_KV.put(entry.file, JSON.stringify(merged));
37
33
  return merged;
38
34
  }
39
35
 
40
- // Local dev: filesystem
41
36
  await writeLocal(entry.file, merged);
42
37
  return merged;
43
38
  }