@yysng/astro-boilerplate 1.1.34 → 1.1.35

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.34",
3
+ "version": "1.1.35",
4
4
  "description": "Astro + Sanity Boilerplate with AEO Layers 1–5",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,7 +11,8 @@
11
11
  "./lib/*": "./src/lib/*",
12
12
  "./utils/*": "./src/utils/*",
13
13
  "./content-loader": "./src/content-system/loader.js",
14
- "./content-storage": "./src/content-system/storage.js"
14
+ "./content-storage/node": "./src/content-system/storage.node.js",
15
+ "./content-storage/edge": "./src/content-system/storage.edge.js"
15
16
  },
16
17
  "main": "./src/index.js",
17
18
  "files": [
@@ -1,19 +1,27 @@
1
1
  import { schemas } from "./schemas.js";
2
2
  import { loadContent } from "./loader.js";
3
- import { writeLocal }from "@yysng/astro-boilerplate/content-storage";
4
3
  import { CONTENT_REGISTRY } from "./registry.js";
5
4
 
5
+ const isEdge = typeof process === "undefined";
6
+
7
+ const { writeLocal } = isEdge
8
+ ? await import("@yysng/astro-boilerplate/content-storage/edge")
9
+ : await import("@yysng/astro-boilerplate/content-storage/node");
10
+
6
11
  function mergeDefined(existing, incoming) {
7
12
  const result = { ...existing };
13
+
8
14
  for (const k in incoming) {
9
15
  const v = incoming[k];
10
16
  if (v === undefined) continue;
17
+
11
18
  if (typeof v === "object" && v && !Array.isArray(v)) {
12
19
  result[k] = mergeDefined(existing[k] || {}, v);
13
20
  } else {
14
21
  result[k] = v;
15
22
  }
16
23
  }
24
+
17
25
  return result;
18
26
  }
19
27
 
@@ -27,11 +35,13 @@ export async function updateContent(key, incoming, env = {}) {
27
35
 
28
36
  schema.validate(merged);
29
37
 
38
+ // Cloudflare
30
39
  if (env?.CONTENT_KV) {
31
40
  await env.CONTENT_KV.put(entry.file, JSON.stringify(merged));
32
41
  return merged;
33
42
  }
34
43
 
35
- await writeLocal(entry.file, merged, env);
44
+ // Local dev
45
+ await writeLocal(entry.file, merged);
36
46
  return merged;
37
47
  }