@ubean/content 0.6.0-beta.2 → 0.6.0-beta.4

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/dist/vite.d.ts CHANGED
@@ -29,5 +29,18 @@ export interface UbeanContentOptions {
29
29
  search?: ContentSearchOptions | false;
30
30
  }
31
31
  export declare function ubeanContentPlugin(userOptions?: UbeanContentOptions): Plugin;
32
+ /**
33
+ * 判断一次 watcher 事件是否落在内容源目录里(dev watch 用)。
34
+ *
35
+ * 目录解析刻意与 `scanContentSources` 对齐(`join(rootDir, source.dir || defaultDir)`):
36
+ * 两边不一致会出现「扫到了却不算内容」或「不是内容却重载」两种偏差。
37
+ */
38
+ export declare function createContentChangeFilter(options: {
39
+ rootDir: string;
40
+ sources?: Record<string, {
41
+ dir: string;
42
+ }>;
43
+ defaultDir: string;
44
+ }): (file: string) => boolean;
32
45
  //#endregion
33
46
  export { ubeanContentPlugin as default };
package/dist/vite.js CHANGED
@@ -70,21 +70,37 @@ export default collections;
70
70
  return join(s.dir || options.defaultDir, "**/*.{md,mdx,json,yaml,yml}");
71
71
  });
72
72
  server.watcher.add(watchPatterns);
73
- server.watcher.on("change", () => {
74
- scanContent();
75
- server.ws.send({ type: "full-reload" });
76
- });
77
- server.watcher.on("add", () => {
78
- scanContent();
79
- server.ws.send({ type: "full-reload" });
73
+ const isContentFile = createContentChangeFilter({
74
+ rootDir,
75
+ sources: options.sources,
76
+ defaultDir: options.defaultDir
80
77
  });
81
- server.watcher.on("unlink", () => {
78
+ const onWatch = (file) => {
79
+ if (!isContentFile(file)) return;
82
80
  scanContent();
83
81
  server.ws.send({ type: "full-reload" });
84
- });
82
+ };
83
+ server.watcher.on("change", onWatch);
84
+ server.watcher.on("add", onWatch);
85
+ server.watcher.on("unlink", onWatch);
85
86
  }
86
87
  }
87
88
  };
88
89
  }
90
+ /** 内容源目录里的内容文件扩展名(与上面的 watch glob 同一套)。 */
91
+ const CONTENT_WATCH_EXTENSIONS = /\.(md|mdx|json|yaml|yml)$/;
92
+ /**
93
+ * 判断一次 watcher 事件是否落在内容源目录里(dev watch 用)。
94
+ *
95
+ * 目录解析刻意与 `scanContentSources` 对齐(`join(rootDir, source.dir || defaultDir)`):
96
+ * 两边不一致会出现「扫到了却不算内容」或「不是内容却重载」两种偏差。
97
+ */
98
+ function createContentChangeFilter(options) {
99
+ const dirs = Object.values(options.sources ?? { content: { dir: options.defaultDir } }).map((source) => join(options.rootDir, source.dir || options.defaultDir));
100
+ return (file) => {
101
+ if (!CONTENT_WATCH_EXTENSIONS.test(file)) return false;
102
+ return dirs.some((dir) => file === dir || file.startsWith(`${dir}/`));
103
+ };
104
+ }
89
105
  //#endregion
90
- export { ubeanContentPlugin as default, ubeanContentPlugin };
106
+ export { createContentChangeFilter, ubeanContentPlugin as default, ubeanContentPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/content",
3
- "version": "0.6.0-beta.2",
3
+ "version": "0.6.0-beta.4",
4
4
  "description": "File-based content module for ubean (markdown/MDX/YAML/JSON)",
5
5
  "files": [
6
6
  "dist"
@@ -28,16 +28,16 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@ubean/shared": "0.6.0-beta.2",
31
+ "@ubean/shared": "0.6.0-beta.4",
32
32
  "defu": "6.1.7",
33
33
  "pathe": "^2.0.3",
34
34
  "scule": "^1.3.0"
35
35
  },
36
36
  "devDependencies": {
37
- "@types/node": "^26.6.1",
37
+ "@types/node": "^26.6.3",
38
38
  "typescript": "npm:typescript-native-bridge@latest",
39
- "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
40
- "vite-plus": "0.3.3",
39
+ "vite": "npm:@voidzero-dev/vite-plus-core@latest",
40
+ "vite-plus": "latest",
41
41
  "vue": "^3.5.43"
42
42
  },
43
43
  "peerDependencies": {