@tnotesjs/core 0.5.0 → 0.6.0

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 (36) hide show
  1. package/dist/chunk-3R7QSABB.cjs +502 -0
  2. package/dist/chunk-CZXRQPFJ.js +11 -0
  3. package/dist/{chunk-XCWFZLER.js → chunk-DUTS75WQ.js} +27 -493
  4. package/dist/chunk-HXED7KVT.cjs +11 -0
  5. package/dist/chunk-IHFUHB4J.cjs +176 -0
  6. package/dist/chunk-MZIXIY2Y.cjs +216 -0
  7. package/dist/chunk-TJ4527KA.cjs +5264 -0
  8. package/dist/chunk-U6IBLREL.js +502 -0
  9. package/dist/chunk-UNFSW5C2.js +176 -0
  10. package/dist/cli/index.cjs +936 -0
  11. package/dist/cli/index.d.cts +2 -0
  12. package/dist/cli/index.d.ts +2 -0
  13. package/dist/cli/index.js +9 -6
  14. package/dist/index.cjs +8 -0
  15. package/dist/index.d.cts +56 -0
  16. package/dist/index.d.ts +56 -0
  17. package/dist/markdown/index.cjs +82 -0
  18. package/dist/markdown/index.d.cts +36 -0
  19. package/dist/markdown/index.d.ts +36 -0
  20. package/dist/markdown/index.js +82 -0
  21. package/dist/note-oGm44Rw8.d.cts +84 -0
  22. package/dist/note-oGm44Rw8.d.ts +84 -0
  23. package/dist/types-CpsEy8lA.d.cts +221 -0
  24. package/dist/types-CwBWwNVv.d.ts +221 -0
  25. package/dist/vitepress/config/index.cjs +1669 -0
  26. package/dist/vitepress/config/index.d.cts +12 -0
  27. package/dist/vitepress/config/index.d.ts +12 -0
  28. package/dist/vitepress/config/index.js +10 -4
  29. package/dist/workspace/index.cjs +1207 -0
  30. package/dist/workspace/index.d.cts +14 -0
  31. package/dist/workspace/index.d.ts +14 -0
  32. package/dist/workspace/index.js +1207 -0
  33. package/package.json +14 -1
  34. package/vitepress/components/Settings/Settings.vue +3 -3
  35. package/vitepress/components/SidebarCard/SidebarCard.vue +3 -3
  36. package/vitepress/plugins/localSearchReindexLogic.ts +11 -3
@@ -0,0 +1,176 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkHXED7KVTcjs = require('./chunk-HXED7KVT.cjs');
4
+
5
+ // markdown/noteFormatter.ts
6
+ var _prettier = require('prettier');
7
+ var NOTE_TOC_START_TAG = "<!-- region:toc -->";
8
+ var NOTE_TOC_END_TAG = "<!-- endregion:toc -->";
9
+ function generatedNoteTitle(input) {
10
+ const dirName = `${input.noteIndex}. ${input.title}`;
11
+ const encodedDirName = encodeURIComponent(dirName);
12
+ const repositoryUrl = `https://github.com/${input.repoOwner}/${input.repoName}/tree/main/notes`;
13
+ return `# [${dirName}](${repositoryUrl}/${encodedDirName})`;
14
+ }
15
+ function ensureGeneratedTitle(lines, generatedTitle) {
16
+ if (lines.length === 0) {
17
+ lines.push(generatedTitle);
18
+ return;
19
+ }
20
+ lines[0] = lines[0].replace(/^\uFEFF/, "");
21
+ if (lines[0].trimStart().startsWith("# ")) {
22
+ lines[0] = generatedTitle;
23
+ return;
24
+ }
25
+ lines.unshift(generatedTitle, "");
26
+ }
27
+ function ensureTocRegion(lines) {
28
+ let start = lines.findIndex((line) => line.trim() === NOTE_TOC_START_TAG);
29
+ let end = lines.findIndex(
30
+ (line, index) => index > start && line.trim() === NOTE_TOC_END_TAG
31
+ );
32
+ if (start >= 0 && end > start) return { start, end };
33
+ if (start >= 0) lines.splice(start, 1);
34
+ if (end >= 0) lines.splice(end > start ? end - 1 : end, 1);
35
+ let insertAt = 1;
36
+ while (insertAt < lines.length && lines[insertAt].trim() === "") insertAt++;
37
+ lines.splice(
38
+ insertAt,
39
+ 0,
40
+ "",
41
+ NOTE_TOC_START_TAG,
42
+ "",
43
+ NOTE_TOC_END_TAG,
44
+ ""
45
+ );
46
+ start = insertAt + 1;
47
+ end = insertAt + 3;
48
+ return { start, end };
49
+ }
50
+ function normalizeHeadings(lines) {
51
+ const headings = [];
52
+ const counters = { h2: 0, h3: 0 };
53
+ let fence = null;
54
+ let inHtmlComment = false;
55
+ for (let index = 0; index < lines.length; index++) {
56
+ const line = lines[index];
57
+ const fenceMatch = line.match(/^\s{0,3}(`{3,}|~{3,})/);
58
+ if (fenceMatch) {
59
+ const marker = fenceMatch[1][0];
60
+ if (!fence) {
61
+ fence = { marker, length: fenceMatch[1].length };
62
+ } else if (fence.marker === marker && fenceMatch[1].length >= fence.length) {
63
+ fence = null;
64
+ }
65
+ continue;
66
+ }
67
+ if (fence) continue;
68
+ if (inHtmlComment) {
69
+ if (line.includes("-->")) inHtmlComment = false;
70
+ continue;
71
+ }
72
+ const commentStart = line.indexOf("<!--");
73
+ if (commentStart >= 0) {
74
+ const commentEnd = line.indexOf("-->", commentStart + 4);
75
+ if (commentEnd < 0) inHtmlComment = true;
76
+ if (line.trimStart().startsWith("<!--")) continue;
77
+ }
78
+ const match = line.match(/^(#{2,6})\s+(.+?)\s*#*\s*$/);
79
+ if (!match) continue;
80
+ const level = match[1].length;
81
+ const plainText = match[2].replace(/^\d+(?:\.\d+)*\.\s+/, "").trim();
82
+ let text = plainText;
83
+ if (level === 2) {
84
+ counters.h2 += 1;
85
+ counters.h3 = 0;
86
+ text = `${counters.h2}. ${plainText}`;
87
+ } else if (level === 3) {
88
+ counters.h3 += 1;
89
+ text = `${counters.h2}.${counters.h3}. ${plainText}`;
90
+ }
91
+ lines[index] = `${"#".repeat(level)} ${text}`;
92
+ headings.push({ level, text });
93
+ }
94
+ return headings;
95
+ }
96
+ function buildHeadingToc(headings) {
97
+ return headings.map((heading) => {
98
+ const indent = " ".repeat(Math.max(0, heading.level - 2) * 2);
99
+ return `${indent}- [${heading.text}](#${_chunkHXED7KVTcjs.generateAnchor.call(void 0, heading.text)})`;
100
+ });
101
+ }
102
+ function stringArray(value) {
103
+ return Array.isArray(value) ? value.filter((item) => typeof item === "string") : [];
104
+ }
105
+ function buildResourceToc(input) {
106
+ const bilibili = stringArray(input.noteConfig.bilibili);
107
+ const relatedTNotes = stringArray(input.noteConfig.tnotes);
108
+ const yuque = stringArray(input.noteConfig.yuque);
109
+ if (bilibili.length + relatedTNotes.length + yuque.length === 0) return [];
110
+ const lines = ["::: details \u{1F4DA} \u76F8\u5173\u8D44\u6E90", ""];
111
+ if (bilibili.length > 0) {
112
+ lines.push(
113
+ "- [\u{1F4FA} bilibili\uFF08\u7B14\u8BB0\u89C6\u9891\u8D44\u6E90\uFF09](https://space.bilibili.com/407241004)",
114
+ ...bilibili.map(
115
+ (bvid, index) => ` - [bilibili.${input.repoName}.${input.noteIndex}.${index + 1}](https://www.bilibili.com/video/${bvid})`
116
+ )
117
+ );
118
+ }
119
+ if (relatedTNotes.length > 0) {
120
+ lines.push(
121
+ "- [\u{1F4D2} TNotes\uFF08\u76F8\u5173\u77E5\u8BC6\u5E93\uFF09](https://tnotesjs.github.io/TNotes/)",
122
+ ...relatedTNotes.map(
123
+ (repoName) => ` - [TNotes.${repoName}](https://tnotesjs.github.io/TNotes.${repoName}/)`
124
+ )
125
+ );
126
+ }
127
+ if (yuque.length > 0) {
128
+ const base = "https://www.yuque.com/tdahuyou/tnotes.yuque/";
129
+ lines.push(
130
+ `- [\u{1F4C2} TNotes.yuque\uFF08\u7B14\u8BB0\u9644\u4EF6\u8D44\u6E90\uFF09](${base})`,
131
+ ...yuque.map(
132
+ (slug) => ` - [TNotes.yuque.${input.repoName.replace("TNotes.", "")}.${input.noteIndex}](${base}${slug})`
133
+ )
134
+ );
135
+ }
136
+ lines.push("", ":::", "");
137
+ return lines;
138
+ }
139
+ async function formatTNotesNote(input) {
140
+ let content = input.content.replace(/\r\n?/g, "\n");
141
+ if (input.prettier !== false) {
142
+ content = await _prettier.format.call(void 0, content, {
143
+ parser: "markdown",
144
+ proseWrap: "never",
145
+ endOfLine: "lf"
146
+ });
147
+ }
148
+ const lines = content.replace(/\n$/, "").split("\n");
149
+ const title = generatedNoteTitle(input);
150
+ ensureGeneratedTitle(lines, title);
151
+ let region = ensureTocRegion(lines);
152
+ const headings = normalizeHeadings(lines);
153
+ region = ensureTocRegion(lines);
154
+ const toc = buildHeadingToc(headings);
155
+ const resources = buildResourceToc(input);
156
+ lines.splice(
157
+ region.start + 1,
158
+ region.end - region.start - 1,
159
+ "",
160
+ ...resources,
161
+ ...toc,
162
+ ""
163
+ );
164
+ return {
165
+ content: `${lines.join("\n").replace(/\n{3,}$/g, "\n\n")}
166
+ `,
167
+ generatedTitle: title,
168
+ generatedToc: toc
169
+ };
170
+ }
171
+
172
+
173
+
174
+
175
+
176
+ exports.NOTE_TOC_START_TAG = NOTE_TOC_START_TAG; exports.NOTE_TOC_END_TAG = NOTE_TOC_END_TAG; exports.formatTNotesNote = formatTNotesNote;
@@ -0,0 +1,216 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// config/ConfigManager.ts
2
+ var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
3
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
4
+
5
+ // config/defaultConfig.ts
6
+ function getDefaultConfig(repoName) {
7
+ const name = repoName || "TNotes.default";
8
+ const cleanName = name.replace("TNotes.", "");
9
+ return {
10
+ // 基础信息
11
+ author: "tnotesjs",
12
+ repoName: name,
13
+ keywords: [name],
14
+ id: "",
15
+ // 由外部生成的 UUID
16
+ // Sidebar 配置
17
+ sidebarShowNoteId: true,
18
+ // 忽略目录
19
+ ignore_dirs: [
20
+ ".vscode",
21
+ "0000",
22
+ "assets",
23
+ "node_modules",
24
+ "hidden",
25
+ "demos"
26
+ ],
27
+ // 根目录项配置
28
+ root_item: {
29
+ icon: {
30
+ src: `https://cdn.jsdelivr.net/gh/tnotesjs/imgs@main/assets/icon--${cleanName}.svg`
31
+ },
32
+ title: cleanName,
33
+ completed_notes_count: {},
34
+ details: `${name} \u77E5\u8BC6\u5E93`,
35
+ link: `https://tnotesjs.github.io/${name}/`
36
+ },
37
+ // 端口配置(根据仓库名生成)
38
+ port: 8e3,
39
+ // 菜单项
40
+ menuItems: [
41
+ {
42
+ text: "\u{1F3E0} Home",
43
+ link: "/"
44
+ },
45
+ {
46
+ text: "\u{1F4D2} TNotes",
47
+ link: "https://tnotesjs.github.io/notes"
48
+ },
49
+ {
50
+ text: "\u{1F4C2} TNotes.yuque",
51
+ link: "https://www.yuque.com/tdahuyou/tnotes.yuque"
52
+ }
53
+ ],
54
+ // 社交链接
55
+ socialLinks: [
56
+ {
57
+ link: "https://www.yuque.com/tdahuyou",
58
+ icon: {
59
+ svg: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="M17.28 2.955c2.97.203 3.756 2.342 3.84 2.597l1.297.096c.13 0 .169.18.054.236c-1.323.716-1.727 2.17-1.49 3.118c.09.358.254.69.412 1.02c.307.642.651 1.418.707 2.981c.117 3.24-2.51 6.175-5.789 6.593c1.17-1.187 1.815-2.444 2.12-3.375c.606-1.846.508-3.316.055-4.44a4.46 4.46 0 0 0-1.782-2.141c-1.683-1.02-3.22-1.09-4.444-.762c.465-.594.876-1.201 1.2-1.864c.584-1.65-.102-2.848-.704-3.519c-.192-.246-.061-.655.305-.655c1.41 0 2.813.02 4.22.115M3.32 19.107c1.924-2.202 4.712-5.394 7.162-8.15c.559-.63 2.769-2.338 5.748-.533c.878.532 2.43 2.165 1.332 5.51c-.803 2.446-4.408 7.796-15.76 5.844c-.227-.039-.511-.354-.218-.687z"/></svg>'
60
+ }
61
+ },
62
+ {
63
+ link: "https://space.bilibili.com/407241004",
64
+ icon: {
65
+ svg: '<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024"><g fill="currentColor"><path d="M310.134 596.45c-7.999-4.463-16.498-8.43-24.997-11.9a274 274 0 0 0-26.996-7.438c-2.5-.992-2.5.991-2.5 1.487c0 7.934.5 18.843 1.5 27.768c1 7.438 2 15.372 4 22.81c0 .496 0 .991.5 1.487c.999.992 1.999 1.488 2.999.496c7.999-4.463 15.998-8.43 22.997-13.388c7.499-5.454 15.498-11.9 21.997-18.347c1.5-1.487 0-2.479.5-2.975m323.96-11.9a274 274 0 0 0-26.997-7.438c-2.5-.992-2.5.991-2.5 1.487c0 7.934.5 18.843 1.5 27.768c1 7.438 2 15.372 4 22.81c0 .496 0 .991.5 1.487c1 .992 2 1.488 3 .496c7.999-4.463 15.998-8.43 22.997-13.388c7.499-5.454 15.498-11.9 21.997-18.347c2-1.487.5-2.479.5-2.975c-7.5-4.463-16.498-8.43-24.997-11.9"/><path d="M741.496 112H283c-94.501 0-171 76.5-171 171.5v458c.5 94 77 170.5 170.999 170.5h457.997c94.5 0 171.002-76.5 171.002-170.5v-458c.497-95-76.002-171.5-170.502-171.5m95 343.5h15.5v48h-15.5zm-95.5-1.5l2 43l-13.5 1.5l-5-44.5zm-23.5 0l4 45.5l-14.5 1.5l-6.5-47.5h17zm-230.498 1.5h15v48h-15zm-96-1.5l2 43l-13.5 1.5l-5-44.5zm-23.5 0l4 45.5l-14.5 2l-6-47.5zm-3.5 149C343.498 668.5 216 662.5 204.5 660.5C195.5 499 181.5 464 170 385l54.5-22.5c1 71.5 9 185 9 185s108.5-15.5 132 47c.5 3 0 6-1.5 8.5m20.5 35.5l-23.5-124h35.5l13 123zm44.5-8l-27-235l33.5-1.5l21 236H429zm34-175h17.5v48H467zm41 190h-26.5l-9.5-126h36zm209.998-43C693.496 668 565.997 662 554.497 660c-9-161-23-196-34.5-275l54.5-22.5c1 71.5 9 185 9 185s108.5-15.5 132 46.5c.5 3 0 6-1.5 8.5m19.5 36l-23-124h35.5l13 123zm45.5-8l-27.5-235l33.5-1.5l21 236h-27zm33.5-175h17.5v48h-13zm41 190h-26.5l-9.5-126h36z"/></g></svg>'
66
+ }
67
+ },
68
+ {
69
+ link: `https://github.com/tnotesjs/${name}`,
70
+ icon: "github"
71
+ }
72
+ ]
73
+ };
74
+ }
75
+ function mergeConfig(target, source) {
76
+ const result = { ...target };
77
+ for (const key in source) {
78
+ if (!(key in result)) {
79
+ result[key] = source[key];
80
+ } else if (typeof source[key] === "object" && source[key] !== null && !Array.isArray(source[key])) {
81
+ result[key] = mergeConfig(result[key] || {}, source[key]);
82
+ }
83
+ }
84
+ return result;
85
+ }
86
+ var DEPRECATED_ROOT_ITEM_FIELDS = [
87
+ "created_at",
88
+ "updated_at",
89
+ "days_since_birth"
90
+ ];
91
+ function stripDeprecatedRootItemFields(rootItem) {
92
+ let stripped = false;
93
+ for (const key of DEPRECATED_ROOT_ITEM_FIELDS) {
94
+ if (key in rootItem) {
95
+ delete rootItem[key];
96
+ stripped = true;
97
+ }
98
+ }
99
+ return stripped;
100
+ }
101
+ function validateAndCompleteConfig(config) {
102
+ const repoName = config.repoName || "TNotes.default";
103
+ const defaultConfig = getDefaultConfig(repoName);
104
+ const mergedConfig = mergeConfig(config, defaultConfig);
105
+ const rootItem = mergedConfig.root_item || {};
106
+ const stripped = stripDeprecatedRootItemFields(rootItem);
107
+ mergedConfig.root_item = rootItem;
108
+ const modified = stripped || JSON.stringify(config) !== JSON.stringify(mergedConfig);
109
+ return {
110
+ config: mergedConfig,
111
+ modified
112
+ };
113
+ }
114
+
115
+ // config/ConfigManager.ts
116
+ var ConfigManager = class _ConfigManager {
117
+ constructor(rootPath) {
118
+ this.config = null;
119
+ if (rootPath) {
120
+ this.rootPath = rootPath;
121
+ } else {
122
+ this.rootPath = process.cwd();
123
+ }
124
+ this.configPath = _path2.default.normalize(
125
+ _path2.default.resolve(this.rootPath, ".tnotes.json")
126
+ );
127
+ }
128
+ /**
129
+ * 使用指定的根路径初始化配置管理器
130
+ *
131
+ * 必须在 getInstance() 之前调用(如果需要指定 rootPath)。
132
+ * 如果已经初始化,则忽略重复调用。
133
+ */
134
+ static init({ rootPath }) {
135
+ if (!_ConfigManager.instance) {
136
+ _ConfigManager.instance = new _ConfigManager(rootPath);
137
+ }
138
+ return _ConfigManager.instance;
139
+ }
140
+ /**
141
+ * 获取单例实例
142
+ */
143
+ static getInstance() {
144
+ if (!_ConfigManager.instance) {
145
+ _ConfigManager.instance = new _ConfigManager();
146
+ }
147
+ return _ConfigManager.instance;
148
+ }
149
+ /**
150
+ * 加载配置文件
151
+ */
152
+ loadConfig(configPath) {
153
+ if (this.config) return this.config;
154
+ const path2 = configPath || this.configPath;
155
+ if (!_fs2.default.existsSync(path2)) {
156
+ throw new Error(`\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728: ${path2}`);
157
+ }
158
+ const configContent = _fs2.default.readFileSync(path2, "utf-8");
159
+ const rawConfig = JSON.parse(configContent);
160
+ const { config: validatedConfig, modified } = validateAndCompleteConfig(rawConfig);
161
+ if (modified) {
162
+ console.warn(`[ConfigManager] \u68C0\u6D4B\u5230\u77E5\u8BC6\u5E93\u914D\u7F6E\u7F3A\u5931\u5B57\u6BB5\uFF0C\u5DF2\u81EA\u52A8\u8865\u5168`);
163
+ _fs2.default.writeFileSync(path2, JSON.stringify(validatedConfig, null, 2), "utf-8");
164
+ console.log(`[ConfigManager] \u77E5\u8BC6\u5E93\u914D\u7F6E\u6587\u4EF6\u5DF2\u66F4\u65B0`);
165
+ console.log(`[ConfigManager] \u77E5\u8BC6\u5E93\u914D\u7F6E\u6587\u4EF6\u8DEF\u5F84: ${path2}`);
166
+ }
167
+ this.config = validatedConfig;
168
+ return this.config;
169
+ }
170
+ /**
171
+ * 清除内存中的配置缓存,下次 get/getAll 时重新从磁盘加载
172
+ */
173
+ clearCache() {
174
+ this.config = null;
175
+ }
176
+ /**
177
+ * 获取配置项
178
+ */
179
+ get(key) {
180
+ if (!this.config) {
181
+ this.loadConfig();
182
+ }
183
+ return this.config[key];
184
+ }
185
+ /**
186
+ * 获取所有配置
187
+ */
188
+ getAll() {
189
+ if (!this.config) {
190
+ this.loadConfig();
191
+ }
192
+ return this.config;
193
+ }
194
+ /**
195
+ * 获取项目根路径
196
+ */
197
+ getRootPath() {
198
+ return this.rootPath;
199
+ }
200
+ /**
201
+ * @deprecated 使用 getRootPath() 替代
202
+ */
203
+ getDirname() {
204
+ return _path2.default.resolve(this.rootPath, ".vitepress", "tnotes", "config");
205
+ }
206
+ };
207
+ function getConfigManager() {
208
+ return ConfigManager.getInstance();
209
+ }
210
+
211
+
212
+
213
+
214
+
215
+
216
+ exports.getDefaultConfig = getDefaultConfig; exports.stripDeprecatedRootItemFields = stripDeprecatedRootItemFields; exports.ConfigManager = ConfigManager; exports.getConfigManager = getConfigManager;