@natilon/astro-cms 0.9.0 → 0.9.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/loader.mjs +10 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@natilon/astro-cms",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "Astro integration that mounts the Natilon CMS admin under /admin during `astro dev` and exposes content helpers.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/src/loader.mjs CHANGED
@@ -35,7 +35,7 @@ export function jsonContentLoader(collection, { pagesDir = "src/pages-data" } =
35
35
  return;
36
36
  }
37
37
 
38
- const files = fs.readdirSync(dir).filter((f) => f.endsWith(".json"));
38
+ const files = fs.readdirSync(dir).filter(isEntryFile);
39
39
  store.clear();
40
40
 
41
41
  for (const file of files) {
@@ -46,15 +46,15 @@ export function jsonContentLoader(collection, { pagesDir = "src/pages-data" } =
46
46
 
47
47
  watcher.add(dir);
48
48
  watcher.on("add", async (fp) => {
49
- if (fp.startsWith(dir) && fp.endsWith(".json"))
49
+ if (fp.startsWith(dir) && isEntryFile(path.basename(fp)))
50
50
  await loadFile(fp, store, parseData, logger, collection);
51
51
  });
52
52
  watcher.on("change", async (fp) => {
53
- if (fp.startsWith(dir) && fp.endsWith(".json"))
53
+ if (fp.startsWith(dir) && isEntryFile(path.basename(fp)))
54
54
  await loadFile(fp, store, parseData, logger, collection);
55
55
  });
56
56
  watcher.on("unlink", (fp) => {
57
- if (fp.startsWith(dir) && fp.endsWith(".json")) {
57
+ if (fp.startsWith(dir) && isEntryFile(path.basename(fp))) {
58
58
  try {
59
59
  const raw = JSON.parse(fs.readFileSync(fp, "utf-8"));
60
60
  store.delete(raw.id || raw.slug);
@@ -65,6 +65,12 @@ export function jsonContentLoader(collection, { pagesDir = "src/pages-data" } =
65
65
  };
66
66
  }
67
67
 
68
+ // Manifest/index files (e.g. _index.json) are generated list projections,
69
+ // not content entries, so they must be excluded from the entry loader.
70
+ function isEntryFile(file) {
71
+ return file.endsWith(".json") && !file.startsWith("_");
72
+ }
73
+
68
74
  async function loadFile(filePath, store, parseData, logger, collection) {
69
75
  const file = path.basename(filePath);
70
76
  try {