@tnotesjs/core 0.0.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.
- package/README.md +84 -0
- package/dist/chunk-CSSIRO3I.js +4288 -0
- package/dist/chunk-NASIL5FY.js +203 -0
- package/dist/cli/index.js +694 -0
- package/dist/index.js +8 -0
- package/dist/vitepress/config/index.js +904 -0
- package/package.json +77 -0
- package/types/config.ts +61 -0
- package/types/index.ts +11 -0
- package/types/note.ts +33 -0
- package/types/shims.d.ts +10 -0
- package/vitepress/assets/icons/icon__check.svg +3 -0
- package/vitepress/assets/icons/icon__clipboard.svg +8 -0
- package/vitepress/assets/icons/icon__close.svg +1 -0
- package/vitepress/assets/icons/icon__collapse.svg +1 -0
- package/vitepress/assets/icons/icon__confirm.svg +1 -0
- package/vitepress/assets/icons/icon__copy.svg +4 -0
- package/vitepress/assets/icons/icon__focus.svg +1 -0
- package/vitepress/assets/icons/icon__fold.svg +3 -0
- package/vitepress/assets/icons/icon__folder.svg +1 -0
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -0
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -0
- package/vitepress/assets/icons/icon__github.svg +4 -0
- package/vitepress/assets/icons/icon__mindmap.svg +1 -0
- package/vitepress/assets/icons/icon__next.svg +1 -0
- package/vitepress/assets/icons/icon__number_gray.svg +1 -0
- package/vitepress/assets/icons/icon__number_purple.svg +1 -0
- package/vitepress/assets/icons/icon__prev.svg +1 -0
- package/vitepress/assets/icons/icon__restore.svg +1 -0
- package/vitepress/assets/icons/icon__rotate.svg +4 -0
- package/vitepress/assets/icons/icon__search.svg +1 -0
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -0
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -0
- package/vitepress/assets/icons/icon__totop.svg +6 -0
- package/vitepress/assets/icons/icon__vscode.svg +6 -0
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -0
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -0
- package/vitepress/assets/icons/index.ts +38 -0
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -0
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -0
- package/vitepress/components/CodeBlockFullscreen/index.ts +115 -0
- package/vitepress/components/CodeBlockFullscreen/styles.css +64 -0
- package/vitepress/components/Discussions/Discussions.module.scss +32 -0
- package/vitepress/components/Discussions/Discussions.vue +211 -0
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -0
- package/vitepress/components/EnWordList/EnWordList.vue +543 -0
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -0
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -0
- package/vitepress/components/Footprints/Footprints.module.scss +93 -0
- package/vitepress/components/Footprints/Footprints.vue +377 -0
- package/vitepress/components/Layout/AboutModal.module.scss +233 -0
- package/vitepress/components/Layout/AboutModal.vue +105 -0
- package/vitepress/components/Layout/AboutPanel.vue +266 -0
- package/vitepress/components/Layout/ContentCollapse.vue +603 -0
- package/vitepress/components/Layout/CustomSidebar.vue +605 -0
- package/vitepress/components/Layout/DocBeforeControls.vue +139 -0
- package/vitepress/components/Layout/DocFooter.vue +225 -0
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -0
- package/vitepress/components/Layout/ImagePreview.vue +281 -0
- package/vitepress/components/Layout/Layout.module.scss +661 -0
- package/vitepress/components/Layout/Layout.vue +542 -0
- package/vitepress/components/Layout/NoteStatus.vue +140 -0
- package/vitepress/components/Layout/SidebarItems.vue +263 -0
- package/vitepress/components/Layout/SidebarNavBefore.vue +92 -0
- package/vitepress/components/Layout/Swiper.vue +167 -0
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -0
- package/vitepress/components/Layout/ToggleFullContent.vue +34 -0
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -0
- package/vitepress/components/Layout/ToggleSidebar.vue +35 -0
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -0
- package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -0
- package/vitepress/components/Layout/composables/useNoteSave.ts +173 -0
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -0
- package/vitepress/components/Layout/composables/useRedirect.ts +110 -0
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -0
- package/vitepress/components/Layout/homeReadme.data.ts +124 -0
- package/vitepress/components/LoadingPage/LoadingPage.vue +192 -0
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -0
- package/vitepress/components/MarkMap/MarkMap.vue +404 -0
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -0
- package/vitepress/components/Mermaid/Mermaid.vue +364 -0
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -0
- package/vitepress/components/NotesTable/NotesTable.vue +98 -0
- package/vitepress/components/NotesTable/README.md +67 -0
- package/vitepress/components/Settings/Settings.module.scss +433 -0
- package/vitepress/components/Settings/Settings.vue +306 -0
- package/vitepress/components/SidebarCard/MindMapView.vue +483 -0
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -0
- package/vitepress/components/SidebarCard/SidebarCard.vue +948 -0
- package/vitepress/components/Tooltip/Tooltip.vue +70 -0
- package/vitepress/components/constants.ts +91 -0
- package/vitepress/components/notesConfig.data.ts +73 -0
- package/vitepress/components/sidebar.data.ts +59 -0
- package/vitepress/components/tnotes-config.data.ts +21 -0
- package/vitepress/components/utils.ts +26 -0
- package/vitepress/config/index.ts +141 -0
- package/vitepress/configs/constants.ts +26 -0
- package/vitepress/configs/head.config.ts +25 -0
- package/vitepress/configs/index.ts +9 -0
- package/vitepress/configs/markdown-it.d.ts +23 -0
- package/vitepress/configs/markdown.config.ts +366 -0
- package/vitepress/configs/theme.config.ts +108 -0
- package/vitepress/plugins/buildProgressPlugin.ts +390 -0
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -0
- package/vitepress/plugins/renameNotePlugin.ts +60 -0
- package/vitepress/plugins/updateConfigPlugin.ts +63 -0
- package/vitepress/theme/index.ts +95 -0
- package/vitepress/theme/styles/base.scss +50 -0
- package/vitepress/theme/styles/components/404.scss +31 -0
- package/vitepress/theme/styles/components/collapse.scss +175 -0
- package/vitepress/theme/styles/components/markmap.scss +101 -0
- package/vitepress/theme/styles/components/swiper.scss +255 -0
- package/vitepress/theme/styles/index.scss +25 -0
- package/vitepress/theme/styles/layout.scss +62 -0
- package/vitepress/theme/styles/utilities.scss +39 -0
- package/vitepress/theme/styles/vitepress-override.scss +25 -0
|
@@ -0,0 +1,904 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoteIndexCache,
|
|
3
|
+
RenameNoteCommand,
|
|
4
|
+
UpdateNoteConfigCommand,
|
|
5
|
+
generateAnchor,
|
|
6
|
+
logger
|
|
7
|
+
} from "../../chunk-CSSIRO3I.js";
|
|
8
|
+
import "../../chunk-NASIL5FY.js";
|
|
9
|
+
|
|
10
|
+
// vitepress/config/index.ts
|
|
11
|
+
import fs2 from "fs";
|
|
12
|
+
import path2 from "path";
|
|
13
|
+
import { defineConfig } from "vitepress";
|
|
14
|
+
|
|
15
|
+
// vitepress/configs/constants.ts
|
|
16
|
+
function getIgnoreList(config) {
|
|
17
|
+
return [...config.ignore_dirs.map((dir) => `**/${dir}/**`)];
|
|
18
|
+
}
|
|
19
|
+
function getGithubPageUrl(config) {
|
|
20
|
+
return "https://" + config.author.toLowerCase() + ".github.io/" + config.repoName + "/";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// vitepress/configs/head.config.ts
|
|
24
|
+
function getHeadConfig(config, githubPageUrl) {
|
|
25
|
+
const head = [
|
|
26
|
+
[
|
|
27
|
+
"meta",
|
|
28
|
+
{
|
|
29
|
+
name: "keywords",
|
|
30
|
+
content: config.keywords.join(", ")
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
["meta", { name: "author", content: config.author }],
|
|
34
|
+
["link", { rel: "canonical", href: githubPageUrl }],
|
|
35
|
+
["link", { rel: "icon", href: githubPageUrl + "favicon.ico" }],
|
|
36
|
+
["link", { rel: "preconnect", href: "https://fonts.googleapis.com" }]
|
|
37
|
+
];
|
|
38
|
+
return head;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// vitepress/configs/markdown.config.ts
|
|
42
|
+
import markdownItContainer from "markdown-it-container";
|
|
43
|
+
import mila from "markdown-it-link-attributes";
|
|
44
|
+
import markdownItTaskLists from "markdown-it-task-lists";
|
|
45
|
+
import fs from "fs";
|
|
46
|
+
import path from "path";
|
|
47
|
+
function esc(s = "") {
|
|
48
|
+
return s.replace(
|
|
49
|
+
/[&<>"']/g,
|
|
50
|
+
(ch) => ({
|
|
51
|
+
"&": "&",
|
|
52
|
+
"<": "<",
|
|
53
|
+
">": ">",
|
|
54
|
+
'"': """,
|
|
55
|
+
"'": "'"
|
|
56
|
+
})[ch]
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
var simpleMermaidMarkdown = (md) => {
|
|
60
|
+
const fence = md.renderer.rules.fence ? md.renderer.rules.fence.bind(md.renderer.rules) : () => "";
|
|
61
|
+
md.renderer.rules.fence = (tokens, index, options, env, slf) => {
|
|
62
|
+
const token = tokens[index];
|
|
63
|
+
if (token.info.trim() === "mermaid") {
|
|
64
|
+
try {
|
|
65
|
+
const key = `mermaid-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
66
|
+
const content = token.content;
|
|
67
|
+
return `<Mermaid id="${key}" graph="${encodeURIComponent(content)}" />`;
|
|
68
|
+
} catch (err) {
|
|
69
|
+
return `<pre>${err}</pre>`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (token.info.trim() === "mmd") {
|
|
73
|
+
tokens[index].info = "mermaid";
|
|
74
|
+
}
|
|
75
|
+
return fence(tokens, index, options, env, slf);
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
function configureMarkMapContainer(md) {
|
|
79
|
+
md.use(markdownItContainer, "markmap", {
|
|
80
|
+
marker: "`",
|
|
81
|
+
validate(params) {
|
|
82
|
+
const p = (params || "").trim();
|
|
83
|
+
return p.startsWith("markmap");
|
|
84
|
+
},
|
|
85
|
+
render() {
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
md.core.ruler.after("block", "tn_replace_markmap_container", (state) => {
|
|
90
|
+
const src = state.env.source || "";
|
|
91
|
+
const lines = src.split("\n");
|
|
92
|
+
const tokens = state.tokens;
|
|
93
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
94
|
+
const t = tokens[i];
|
|
95
|
+
if (t.type === "container_markmap_open") {
|
|
96
|
+
let j = i + 1;
|
|
97
|
+
while (j < tokens.length && tokens[j].type !== "container_markmap_close")
|
|
98
|
+
j++;
|
|
99
|
+
if (j >= tokens.length) continue;
|
|
100
|
+
const open = t;
|
|
101
|
+
const startLine = open.map ? open.map[0] + 1 : null;
|
|
102
|
+
const endLine = open.map ? open.map[1] - 1 : null;
|
|
103
|
+
let params = {};
|
|
104
|
+
if (open.map && typeof open.map[0] === "number") {
|
|
105
|
+
const openLine = (lines[open.map[0]] || "").trim();
|
|
106
|
+
let paramPart = "";
|
|
107
|
+
const braceMatch = openLine.match(/\{([^}]*)\}/);
|
|
108
|
+
if (braceMatch) {
|
|
109
|
+
paramPart = braceMatch[1].trim();
|
|
110
|
+
} else {
|
|
111
|
+
const after = openLine.replace(/^`+\s*/, "");
|
|
112
|
+
if (after.startsWith("markmap")) {
|
|
113
|
+
paramPart = after.slice("markmap".length).trim();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (paramPart) {
|
|
117
|
+
const tokenArr = paramPart.match(/"[^"]*"|'[^']*'|\S+/g) || [];
|
|
118
|
+
let startIdx = 0;
|
|
119
|
+
if (tokenArr.length > 0 && /^\d+$/.test(tokenArr[0])) {
|
|
120
|
+
params.initialExpandLevel = Number(tokenArr[0]);
|
|
121
|
+
startIdx = 1;
|
|
122
|
+
}
|
|
123
|
+
for (let k = startIdx; k < tokenArr.length; k++) {
|
|
124
|
+
const pair = tokenArr[k];
|
|
125
|
+
if (!pair) continue;
|
|
126
|
+
const m = pair.match(/^([^=:\s]+)\s*(=|:)\s*(.+)$/);
|
|
127
|
+
if (m) {
|
|
128
|
+
const key = m[1];
|
|
129
|
+
let val = m[3];
|
|
130
|
+
if (/^".*"$/.test(val) && val.length >= 2 || /^'.*'$/.test(val) && val.length >= 2) {
|
|
131
|
+
val = val.slice(1, -1);
|
|
132
|
+
} else if (/^\d+$/.test(val)) {
|
|
133
|
+
val = String(Number(val));
|
|
134
|
+
}
|
|
135
|
+
params[key] = val;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
let content = "";
|
|
141
|
+
if (startLine !== null && endLine !== null) {
|
|
142
|
+
for (let k = startLine; k <= endLine && k < lines.length; k++) {
|
|
143
|
+
content += lines[k] + "\n";
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
for (let k = i + 1; k < j; k++) {
|
|
147
|
+
content += tokens[k].content || "";
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const firstNonEmptyLine = (content || "").split("\n").find((ln) => ln.trim() !== "") || "";
|
|
151
|
+
const refMatch = firstNonEmptyLine.trim().match(/^<<<\s*(.+)$/);
|
|
152
|
+
if (refMatch) {
|
|
153
|
+
let refRaw = refMatch[1].trim().replace(/^['"]|['"]$/g, "");
|
|
154
|
+
try {
|
|
155
|
+
const env = state.env || {};
|
|
156
|
+
const possibleRel = env.relativePath || env.path || env.filePath || env.file || "";
|
|
157
|
+
let refFullPath = refRaw;
|
|
158
|
+
if (!path.isAbsolute(refRaw)) {
|
|
159
|
+
if (possibleRel) {
|
|
160
|
+
const currentDir = path.dirname(possibleRel);
|
|
161
|
+
refFullPath = path.resolve(process.cwd(), currentDir, refRaw);
|
|
162
|
+
} else {
|
|
163
|
+
refFullPath = path.resolve(process.cwd(), refRaw);
|
|
164
|
+
}
|
|
165
|
+
} else {
|
|
166
|
+
refFullPath = refRaw;
|
|
167
|
+
}
|
|
168
|
+
const fileContent = fs.readFileSync(refFullPath, "utf-8");
|
|
169
|
+
content = fileContent;
|
|
170
|
+
} catch (err) {
|
|
171
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
172
|
+
content = `Failed to load referenced file: ${esc(
|
|
173
|
+
String(refRaw)
|
|
174
|
+
)}
|
|
175
|
+
|
|
176
|
+
Error: ${esc(errorMsg)}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const encodedContent = encodeURIComponent(content.trim());
|
|
180
|
+
let propsStr = `content="${encodedContent}"`;
|
|
181
|
+
for (const [k, v] of Object.entries(params)) {
|
|
182
|
+
if (typeof v === "number" || /^\d+$/.test(String(v))) {
|
|
183
|
+
propsStr += ` :${k}="${v}"`;
|
|
184
|
+
} else {
|
|
185
|
+
const safe = String(v).replace(/"/g, """);
|
|
186
|
+
propsStr += ` ${k}="${safe}"`;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const html = `<MarkMap ${propsStr}></MarkMap>
|
|
190
|
+
`;
|
|
191
|
+
const htmlToken = new state.Token("html_block", "", 0);
|
|
192
|
+
htmlToken.content = html;
|
|
193
|
+
tokens.splice(i, j - i + 1, htmlToken);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
function configureSwiperContainer(md) {
|
|
200
|
+
let __tn_swiper_uid = 0;
|
|
201
|
+
let __tn_rules_stack = [];
|
|
202
|
+
md.core.ruler.before("block", "tn_swiper_reset_uid", () => {
|
|
203
|
+
__tn_swiper_uid = 0;
|
|
204
|
+
__tn_rules_stack = [];
|
|
205
|
+
return true;
|
|
206
|
+
});
|
|
207
|
+
md.use(markdownItContainer, "swiper", {
|
|
208
|
+
render: (tokens, idx) => {
|
|
209
|
+
if (tokens[idx].nesting === 1) {
|
|
210
|
+
__tn_rules_stack.push({
|
|
211
|
+
image: md.renderer.rules.image,
|
|
212
|
+
pOpen: md.renderer.rules.paragraph_open,
|
|
213
|
+
pClose: md.renderer.rules.paragraph_close
|
|
214
|
+
});
|
|
215
|
+
md.renderer.rules.paragraph_open = () => "";
|
|
216
|
+
md.renderer.rules.paragraph_close = () => "";
|
|
217
|
+
md.renderer.rules.image = (tokens2, i) => {
|
|
218
|
+
const token = tokens2[i];
|
|
219
|
+
const src = token.attrGet("src") || "";
|
|
220
|
+
const alt = token.content || "";
|
|
221
|
+
const title = alt && alt.trim() ? alt : "img";
|
|
222
|
+
return `<div class="swiper-slide" data-title="${esc(
|
|
223
|
+
title
|
|
224
|
+
)}"><img src="${esc(src)}" alt="${esc(alt)}"></div>`;
|
|
225
|
+
};
|
|
226
|
+
const id = `tn-swiper-${++__tn_swiper_uid}`;
|
|
227
|
+
return `
|
|
228
|
+
<div class="tn-swiper" data-swiper-id="${id}">
|
|
229
|
+
<div class="tn-swiper-tabs"></div>
|
|
230
|
+
<div class="swiper-container">
|
|
231
|
+
<div class="swiper-wrapper">
|
|
232
|
+
`;
|
|
233
|
+
} else {
|
|
234
|
+
const prev = __tn_rules_stack.pop() || {
|
|
235
|
+
image: null,
|
|
236
|
+
pOpen: null,
|
|
237
|
+
pClose: null
|
|
238
|
+
};
|
|
239
|
+
md.renderer.rules.image = prev.image;
|
|
240
|
+
md.renderer.rules.paragraph_open = prev.pOpen;
|
|
241
|
+
md.renderer.rules.paragraph_close = prev.pClose;
|
|
242
|
+
return `
|
|
243
|
+
</div>
|
|
244
|
+
<!-- \u4E0B\u4E00\u9875\u6309\u94AE -->
|
|
245
|
+
<!-- <div class="swiper-button-next"></div> -->
|
|
246
|
+
<!-- \u4E0A\u4E00\u9875\u6309\u94AE -->
|
|
247
|
+
<!-- <div class="swiper-button-prev"></div> -->
|
|
248
|
+
<!-- \u5206\u9875\u5BFC\u822A -->
|
|
249
|
+
<!-- <div class="swiper-pagination"></div> -->
|
|
250
|
+
</div>
|
|
251
|
+
</div>
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function getMarkdownConfig() {
|
|
258
|
+
const markdown = {
|
|
259
|
+
lineNumbers: true,
|
|
260
|
+
math: true,
|
|
261
|
+
config(md) {
|
|
262
|
+
md.core.ruler.before("normalize", "save-source", (state) => {
|
|
263
|
+
state.env.source = state.src;
|
|
264
|
+
return true;
|
|
265
|
+
});
|
|
266
|
+
simpleMermaidMarkdown(md);
|
|
267
|
+
configureMarkMapContainer(md);
|
|
268
|
+
md.use(markdownItTaskLists);
|
|
269
|
+
md.use(mila, {
|
|
270
|
+
attrs: {
|
|
271
|
+
target: "_self",
|
|
272
|
+
rel: "noopener"
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
configureSwiperContainer(md);
|
|
276
|
+
},
|
|
277
|
+
anchor: {
|
|
278
|
+
slugify: generateAnchor
|
|
279
|
+
},
|
|
280
|
+
image: {
|
|
281
|
+
lazyLoading: true
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
return markdown;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// vitepress/configs/theme.config.ts
|
|
288
|
+
function getThemeConfig(config) {
|
|
289
|
+
const themeConfig = {
|
|
290
|
+
docFooter: {
|
|
291
|
+
prev: "\u4E0A\u4E00\u7BC7",
|
|
292
|
+
next: "\u4E0B\u4E00\u7BC7"
|
|
293
|
+
},
|
|
294
|
+
externalLinkIcon: true,
|
|
295
|
+
outline: {
|
|
296
|
+
level: [2, 3],
|
|
297
|
+
label: "\u76EE\u5F55"
|
|
298
|
+
},
|
|
299
|
+
nav: [
|
|
300
|
+
{
|
|
301
|
+
text: "\u{1F440} README",
|
|
302
|
+
link: "/README"
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
text: "Menus",
|
|
306
|
+
items: config.menuItems
|
|
307
|
+
}
|
|
308
|
+
],
|
|
309
|
+
search: {
|
|
310
|
+
// 使用本地搜索(不依赖远程服务器)
|
|
311
|
+
provider: "local",
|
|
312
|
+
options: {
|
|
313
|
+
miniSearch: {
|
|
314
|
+
/**
|
|
315
|
+
* 控制如何对文档进行分词、字段提取等预处理
|
|
316
|
+
* @type {Pick<import('minisearch').Options, 'extractField' | 'tokenize' | 'processTerm'>}
|
|
317
|
+
*/
|
|
318
|
+
options: {
|
|
319
|
+
// 自定义分词逻辑
|
|
320
|
+
tokenize: (text, language) => {
|
|
321
|
+
if (language === "zh") {
|
|
322
|
+
return text.match(/[\u4e00-\u9fa5]+|\S+/g) || [];
|
|
323
|
+
}
|
|
324
|
+
return text.split(/\s+/);
|
|
325
|
+
},
|
|
326
|
+
// 将所有词转为小写,确保大小写不敏感匹配
|
|
327
|
+
processTerm: (term) => term.toLowerCase()
|
|
328
|
+
},
|
|
329
|
+
/**
|
|
330
|
+
* 控制搜索时的行为(如模糊匹配、权重)
|
|
331
|
+
* @type {import('minisearch').SearchOptions}
|
|
332
|
+
* @default
|
|
333
|
+
* { fuzzy: 0.2, prefix: true, boost: { title: 4, text: 2, titles: 1 } }
|
|
334
|
+
*/
|
|
335
|
+
searchOptions: {
|
|
336
|
+
fuzzy: 0.2,
|
|
337
|
+
// 模糊匹配阈值(0-1),允许拼写错误的阈值(数值越低越严格)
|
|
338
|
+
prefix: true,
|
|
339
|
+
// 是否启用前缀匹配(输入"jav"可匹配"javascript")
|
|
340
|
+
boost: {
|
|
341
|
+
title: 10,
|
|
342
|
+
// 文件名作为 h1 标题,权重最高
|
|
343
|
+
headings: 5,
|
|
344
|
+
// h2 - h6
|
|
345
|
+
text: 3,
|
|
346
|
+
// 正文内容索引
|
|
347
|
+
code: 1
|
|
348
|
+
// 代码块索引权重
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
/**
|
|
353
|
+
* 控制哪些 Markdown 内容参与本地搜索引擎索引
|
|
354
|
+
* @param {string} src 当前 Markdown 文件的原始内容(即 .md 文件中的文本)
|
|
355
|
+
* @param {import('vitepress').MarkdownEnv} env 包含当前页面环境信息的对象,比如 frontmatter、路径等
|
|
356
|
+
* @param {import('markdown-it-async')} md 一个 Markdown 渲染器实例,用来将 Markdown 转换为 HTML
|
|
357
|
+
*/
|
|
358
|
+
async _render(src, env, md) {
|
|
359
|
+
const filePath = env.relativePath;
|
|
360
|
+
if (filePath.includes("TOC.md")) return "";
|
|
361
|
+
const notesIndex = filePath.indexOf("notes/");
|
|
362
|
+
let folderName = "";
|
|
363
|
+
if (notesIndex !== -1) {
|
|
364
|
+
const pathAfterNotes = filePath.slice(notesIndex + "notes/".length);
|
|
365
|
+
folderName = pathAfterNotes.split("/")[0];
|
|
366
|
+
}
|
|
367
|
+
const titleField = `# ${folderName}
|
|
368
|
+
`;
|
|
369
|
+
const html = md.render(titleField + "\n\n" + src, env);
|
|
370
|
+
return html;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
// sidebar: [...sidebar],
|
|
375
|
+
sidebar: [
|
|
376
|
+
{
|
|
377
|
+
text: "\u{1F440} README",
|
|
378
|
+
link: "/README"
|
|
379
|
+
}
|
|
380
|
+
],
|
|
381
|
+
socialLinks: config.socialLinks
|
|
382
|
+
};
|
|
383
|
+
return themeConfig;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// vitepress/plugins/updateConfigPlugin.ts
|
|
387
|
+
function updateConfigPlugin() {
|
|
388
|
+
let updateCommand;
|
|
389
|
+
return {
|
|
390
|
+
name: "tnotes-update-config",
|
|
391
|
+
configureServer(server) {
|
|
392
|
+
updateCommand = new UpdateNoteConfigCommand();
|
|
393
|
+
server.middlewares.use(async (req, res, next) => {
|
|
394
|
+
if (req.url === "/__tnotes_update_config" && req.method === "POST") {
|
|
395
|
+
let body = "";
|
|
396
|
+
req.on("data", (chunk) => {
|
|
397
|
+
body += chunk.toString();
|
|
398
|
+
});
|
|
399
|
+
req.on("end", async () => {
|
|
400
|
+
try {
|
|
401
|
+
const data = JSON.parse(body);
|
|
402
|
+
const { noteIndex, config } = data;
|
|
403
|
+
if (!noteIndex || !config) {
|
|
404
|
+
res.statusCode = 400;
|
|
405
|
+
res.end("Missing noteIndex or config");
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
await updateCommand.updateConfig({
|
|
409
|
+
noteIndex,
|
|
410
|
+
config: {
|
|
411
|
+
done: config.done,
|
|
412
|
+
enableDiscussions: config.enableDiscussions,
|
|
413
|
+
description: config.description
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
res.statusCode = 200;
|
|
417
|
+
res.setHeader("Content-Type", "application/json");
|
|
418
|
+
res.end(JSON.stringify({ success: true }));
|
|
419
|
+
} catch (error) {
|
|
420
|
+
console.error("\u66F4\u65B0\u914D\u7F6E\u5931\u8D25:", error);
|
|
421
|
+
res.statusCode = 500;
|
|
422
|
+
res.end(error instanceof Error ? error.message : String(error));
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
} else {
|
|
426
|
+
next();
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// vitepress/plugins/renameNotePlugin.ts
|
|
434
|
+
function renameNotePlugin() {
|
|
435
|
+
const renameCommand = new RenameNoteCommand();
|
|
436
|
+
return {
|
|
437
|
+
name: "tnotes-rename-note",
|
|
438
|
+
configureServer(server) {
|
|
439
|
+
server.middlewares.use(async (req, res, next) => {
|
|
440
|
+
if (req.url === "/__tnotes_rename_note" && req.method === "POST") {
|
|
441
|
+
let body = "";
|
|
442
|
+
req.on("data", (chunk) => {
|
|
443
|
+
body += chunk.toString();
|
|
444
|
+
});
|
|
445
|
+
req.on("end", async () => {
|
|
446
|
+
try {
|
|
447
|
+
const { noteIndex, newTitle } = JSON.parse(body);
|
|
448
|
+
if (!noteIndex || !newTitle) {
|
|
449
|
+
res.statusCode = 400;
|
|
450
|
+
res.end("Missing noteIndex or newTitle");
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const startTime = Date.now();
|
|
454
|
+
await renameCommand.renameNote({ noteIndex, newTitle });
|
|
455
|
+
const duration = Date.now() - startTime;
|
|
456
|
+
res.statusCode = 200;
|
|
457
|
+
res.setHeader("Content-Type", "application/json");
|
|
458
|
+
res.end(
|
|
459
|
+
JSON.stringify({
|
|
460
|
+
success: true,
|
|
461
|
+
duration,
|
|
462
|
+
newTitle,
|
|
463
|
+
message: "\u91CD\u547D\u540D\u5B8C\u6210"
|
|
464
|
+
})
|
|
465
|
+
);
|
|
466
|
+
} catch (error) {
|
|
467
|
+
res.statusCode = 500;
|
|
468
|
+
res.end(error instanceof Error ? error.message : "Rename failed");
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
} else {
|
|
472
|
+
next();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
// vitepress/plugins/getNoteByConfigIdPlugin.ts
|
|
480
|
+
function getNoteByConfigIdPlugin() {
|
|
481
|
+
return {
|
|
482
|
+
name: "tnotes-get-note-by-config-id",
|
|
483
|
+
configureServer(server) {
|
|
484
|
+
server.middlewares.use(async (req, res, next) => {
|
|
485
|
+
if (req.url?.startsWith("/__tnotes_get_note?") && req.method === "GET") {
|
|
486
|
+
try {
|
|
487
|
+
const url = new URL(req.url, `http://${req.headers.host}`);
|
|
488
|
+
const configId = url.searchParams.get("configId");
|
|
489
|
+
if (!configId) {
|
|
490
|
+
res.statusCode = 400;
|
|
491
|
+
res.setHeader("Content-Type", "application/json");
|
|
492
|
+
res.end(
|
|
493
|
+
JSON.stringify({
|
|
494
|
+
success: false,
|
|
495
|
+
error: "Missing configId parameter"
|
|
496
|
+
})
|
|
497
|
+
);
|
|
498
|
+
return;
|
|
499
|
+
}
|
|
500
|
+
const noteIndexCache = NoteIndexCache.getInstance();
|
|
501
|
+
if (!noteIndexCache.isInitialized()) {
|
|
502
|
+
res.statusCode = 503;
|
|
503
|
+
res.setHeader("Content-Type", "application/json");
|
|
504
|
+
res.end(
|
|
505
|
+
JSON.stringify({
|
|
506
|
+
success: false,
|
|
507
|
+
error: "Service not initialized"
|
|
508
|
+
})
|
|
509
|
+
);
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const noteItem = noteIndexCache.getByConfigId(configId);
|
|
513
|
+
if (!noteItem) {
|
|
514
|
+
res.statusCode = 200;
|
|
515
|
+
res.setHeader("Content-Type", "application/json");
|
|
516
|
+
res.end(
|
|
517
|
+
JSON.stringify({
|
|
518
|
+
success: true,
|
|
519
|
+
found: false,
|
|
520
|
+
data: null
|
|
521
|
+
})
|
|
522
|
+
);
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
res.statusCode = 200;
|
|
526
|
+
res.setHeader("Content-Type", "application/json");
|
|
527
|
+
res.end(
|
|
528
|
+
JSON.stringify({
|
|
529
|
+
success: true,
|
|
530
|
+
found: true,
|
|
531
|
+
data: {
|
|
532
|
+
noteIndex: noteItem.noteIndex,
|
|
533
|
+
folderName: noteItem.folderName,
|
|
534
|
+
// 构建笔记的完整 URL(包含 README)
|
|
535
|
+
url: `/notes/${encodeURIComponent(
|
|
536
|
+
noteItem.folderName
|
|
537
|
+
)}/README`
|
|
538
|
+
}
|
|
539
|
+
})
|
|
540
|
+
);
|
|
541
|
+
logger.debug(
|
|
542
|
+
`\u67E5\u8BE2\u7B14\u8BB0: configId=${configId}, noteIndex=${noteItem.noteIndex}`
|
|
543
|
+
);
|
|
544
|
+
} catch (error) {
|
|
545
|
+
logger.error("\u67E5\u8BE2\u7B14\u8BB0\u5931\u8D25:", error);
|
|
546
|
+
res.statusCode = 500;
|
|
547
|
+
res.setHeader("Content-Type", "application/json");
|
|
548
|
+
res.end(
|
|
549
|
+
JSON.stringify({
|
|
550
|
+
success: false,
|
|
551
|
+
error: error instanceof Error ? error.message : String(error)
|
|
552
|
+
})
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
} else {
|
|
556
|
+
next();
|
|
557
|
+
}
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// vitepress/plugins/buildProgressPlugin.ts
|
|
564
|
+
import {
|
|
565
|
+
existsSync,
|
|
566
|
+
readFileSync,
|
|
567
|
+
writeFileSync,
|
|
568
|
+
mkdirSync,
|
|
569
|
+
readdirSync
|
|
570
|
+
} from "fs";
|
|
571
|
+
import { join } from "path";
|
|
572
|
+
var CACHE_DIR = join(process.cwd(), "node_modules", ".tnotes-progress");
|
|
573
|
+
var CACHE_FILE = join(CACHE_DIR, "build-cache.json");
|
|
574
|
+
function getCacheData() {
|
|
575
|
+
try {
|
|
576
|
+
if (existsSync(CACHE_FILE)) {
|
|
577
|
+
return JSON.parse(readFileSync(CACHE_FILE, "utf-8"));
|
|
578
|
+
}
|
|
579
|
+
} catch {
|
|
580
|
+
}
|
|
581
|
+
return { transformCount: 0, chunkCount: 0 };
|
|
582
|
+
}
|
|
583
|
+
function setCacheData(data) {
|
|
584
|
+
try {
|
|
585
|
+
if (!existsSync(CACHE_DIR)) {
|
|
586
|
+
mkdirSync(CACHE_DIR, { recursive: true });
|
|
587
|
+
}
|
|
588
|
+
writeFileSync(CACHE_FILE, JSON.stringify(data), "utf-8");
|
|
589
|
+
} catch {
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
function countSourceFiles(srcDir) {
|
|
593
|
+
let count = 0;
|
|
594
|
+
const extensions = /\.(vue|ts|js|jsx|tsx|css|scss|sass|styl|less|md)$/i;
|
|
595
|
+
const scan = (dir) => {
|
|
596
|
+
try {
|
|
597
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
598
|
+
for (const entry of entries) {
|
|
599
|
+
const fullPath = join(dir, entry.name);
|
|
600
|
+
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
601
|
+
scan(fullPath);
|
|
602
|
+
} else if (entry.isFile() && extensions.test(entry.name)) {
|
|
603
|
+
count++;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
} catch {
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
scan(srcDir);
|
|
610
|
+
return count;
|
|
611
|
+
}
|
|
612
|
+
var globalStartTime = 0;
|
|
613
|
+
var globalTransformCount = 0;
|
|
614
|
+
var globalChunkCount = 0;
|
|
615
|
+
var globalHasError = false;
|
|
616
|
+
var globalIsBuilding = false;
|
|
617
|
+
var globalOutDir = "";
|
|
618
|
+
var globalLastPercent = 0;
|
|
619
|
+
var globalFileCount = 0;
|
|
620
|
+
var globalLastLoggedPercent = -1;
|
|
621
|
+
var isTTY = !!(process.stdout.isTTY && process.stderr.isTTY);
|
|
622
|
+
var isCI = !!(process.env.CI || process.env.GITHUB_ACTIONS || process.env.GITLAB_CI || process.env.CIRCLECI || process.env.TRAVIS || process.env.JENKINS_URL);
|
|
623
|
+
var useSingleLineMode = isTTY && !isCI;
|
|
624
|
+
var originalStdoutWrite = null;
|
|
625
|
+
var originalStderrWrite = null;
|
|
626
|
+
function interceptOutput() {
|
|
627
|
+
if (originalStdoutWrite) return;
|
|
628
|
+
originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
629
|
+
originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
630
|
+
const filter = (chunk) => {
|
|
631
|
+
const str = chunk.toString();
|
|
632
|
+
return str.includes("\u{1F528}") || str.includes("\u2705 \u6784\u5EFA\u6210\u529F") || str.includes("\u274C \u6784\u5EFA\u5931\u8D25") || str.includes("\u{1F4C1}") || str.includes("\u{1F4CA}") || str.includes("\u{1F4E6}") || str.includes("\u23F1\uFE0F") || str.includes("\x1B[2K");
|
|
633
|
+
};
|
|
634
|
+
process.stdout.write = ((chunk, encodingOrCallback, callback) => {
|
|
635
|
+
if (filter(chunk)) {
|
|
636
|
+
return originalStdoutWrite(chunk, encodingOrCallback, callback);
|
|
637
|
+
}
|
|
638
|
+
if (typeof encodingOrCallback === "function") encodingOrCallback();
|
|
639
|
+
else if (callback) callback();
|
|
640
|
+
return true;
|
|
641
|
+
});
|
|
642
|
+
process.stderr.write = ((chunk, encodingOrCallback, callback) => {
|
|
643
|
+
const str = chunk.toString();
|
|
644
|
+
if (filter(chunk) || str.toLowerCase().includes("error")) {
|
|
645
|
+
return originalStderrWrite(chunk, encodingOrCallback, callback);
|
|
646
|
+
}
|
|
647
|
+
if (typeof encodingOrCallback === "function") encodingOrCallback();
|
|
648
|
+
else if (callback) callback();
|
|
649
|
+
return true;
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
function restoreOutput() {
|
|
653
|
+
if (originalStdoutWrite) {
|
|
654
|
+
process.stdout.write = originalStdoutWrite;
|
|
655
|
+
originalStdoutWrite = null;
|
|
656
|
+
}
|
|
657
|
+
if (originalStderrWrite) {
|
|
658
|
+
process.stderr.write = originalStderrWrite;
|
|
659
|
+
originalStderrWrite = null;
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
function renderProgress(percent, transforms, chunks, width, complete, incomplete, isFinal = false) {
|
|
663
|
+
if (!originalStderrWrite) return;
|
|
664
|
+
if (!useSingleLineMode && !isFinal) {
|
|
665
|
+
const currentPercent = Math.floor(percent * 100);
|
|
666
|
+
const currentBucket = Math.floor(currentPercent / 10) * 10;
|
|
667
|
+
if (currentBucket <= globalLastLoggedPercent) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
globalLastLoggedPercent = currentBucket;
|
|
671
|
+
}
|
|
672
|
+
const filled = Math.floor(percent * width);
|
|
673
|
+
const empty = width - filled;
|
|
674
|
+
const bar = complete.repeat(filled) + incomplete.repeat(empty);
|
|
675
|
+
const percentStr = (percent * 100).toFixed(0).padStart(3, " ");
|
|
676
|
+
const elapsed = ((Date.now() - globalStartTime) / 1e3).toFixed(1);
|
|
677
|
+
const prefix = useSingleLineMode ? "\r\x1B[2K" : "";
|
|
678
|
+
const ending = isFinal || !useSingleLineMode ? "\n" : "";
|
|
679
|
+
const line = `${prefix}Building [${bar}] ${percentStr}% | Transforms: ${transforms} | Chunks: ${chunks} | Time: ${elapsed}s${ending}`;
|
|
680
|
+
originalStderrWrite(line);
|
|
681
|
+
}
|
|
682
|
+
function buildProgressPlugin(options = {}) {
|
|
683
|
+
const { width = 40, complete = "\u2588", incomplete = "\u2591" } = options;
|
|
684
|
+
const cache = getCacheData();
|
|
685
|
+
const hasCache = cache.transformCount > 0;
|
|
686
|
+
return {
|
|
687
|
+
name: "tnotes-build-progress",
|
|
688
|
+
enforce: "pre",
|
|
689
|
+
apply: "build",
|
|
690
|
+
config(config, { command }) {
|
|
691
|
+
if (command === "build") {
|
|
692
|
+
config.logLevel = "silent";
|
|
693
|
+
if (!globalIsBuilding) {
|
|
694
|
+
globalIsBuilding = true;
|
|
695
|
+
globalStartTime = Date.now();
|
|
696
|
+
globalTransformCount = 0;
|
|
697
|
+
globalChunkCount = 0;
|
|
698
|
+
globalHasError = false;
|
|
699
|
+
globalLastPercent = 0;
|
|
700
|
+
globalLastLoggedPercent = -1;
|
|
701
|
+
globalOutDir = config.build?.outDir || "dist";
|
|
702
|
+
if (!hasCache) {
|
|
703
|
+
globalFileCount = countSourceFiles(process.cwd());
|
|
704
|
+
}
|
|
705
|
+
interceptOutput();
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
transform(_code, id) {
|
|
710
|
+
globalTransformCount++;
|
|
711
|
+
if (hasCache) {
|
|
712
|
+
const total = cache.transformCount * 2 + cache.chunkCount * 2;
|
|
713
|
+
globalLastPercent = Math.min(0.9, globalTransformCount / total);
|
|
714
|
+
} else {
|
|
715
|
+
if (!id.includes("node_modules") && globalLastPercent < 0.7) {
|
|
716
|
+
globalLastPercent = Math.min(
|
|
717
|
+
0.7,
|
|
718
|
+
globalTransformCount / (globalFileCount * 4)
|
|
719
|
+
);
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
const transformsStr = hasCache ? `${globalTransformCount}/${cache.transformCount * 2}` : `${globalTransformCount}`;
|
|
723
|
+
const chunksStr = hasCache ? `${globalChunkCount}/${cache.chunkCount * 2}` : `${globalChunkCount}`;
|
|
724
|
+
renderProgress(
|
|
725
|
+
globalLastPercent,
|
|
726
|
+
transformsStr,
|
|
727
|
+
chunksStr,
|
|
728
|
+
width,
|
|
729
|
+
complete,
|
|
730
|
+
incomplete
|
|
731
|
+
);
|
|
732
|
+
return null;
|
|
733
|
+
},
|
|
734
|
+
renderChunk() {
|
|
735
|
+
globalChunkCount++;
|
|
736
|
+
if (hasCache) {
|
|
737
|
+
const total = cache.transformCount * 2 + cache.chunkCount * 2;
|
|
738
|
+
globalLastPercent = Math.min(
|
|
739
|
+
0.98,
|
|
740
|
+
(globalTransformCount + globalChunkCount) / total
|
|
741
|
+
);
|
|
742
|
+
} else {
|
|
743
|
+
if (globalLastPercent < 0.98) {
|
|
744
|
+
globalLastPercent = Math.min(0.98, globalLastPercent + 3e-3);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
const transformsStr = hasCache ? `${globalTransformCount}/${cache.transformCount * 2}` : `${globalTransformCount}`;
|
|
748
|
+
const chunksStr = hasCache ? `${globalChunkCount}/${cache.chunkCount * 2}` : `${globalChunkCount}`;
|
|
749
|
+
renderProgress(
|
|
750
|
+
globalLastPercent,
|
|
751
|
+
transformsStr,
|
|
752
|
+
chunksStr,
|
|
753
|
+
width,
|
|
754
|
+
complete,
|
|
755
|
+
incomplete
|
|
756
|
+
);
|
|
757
|
+
return null;
|
|
758
|
+
},
|
|
759
|
+
buildEnd(err) {
|
|
760
|
+
if (err) {
|
|
761
|
+
globalHasError = true;
|
|
762
|
+
}
|
|
763
|
+
},
|
|
764
|
+
closeBundle() {
|
|
765
|
+
setTimeout(() => {
|
|
766
|
+
if (!globalIsBuilding) return;
|
|
767
|
+
const elapsed = ((Date.now() - globalStartTime) / 1e3).toFixed(1);
|
|
768
|
+
const totalTransforms = hasCache ? cache.transformCount * 2 : globalTransformCount;
|
|
769
|
+
const totalChunks = hasCache ? cache.chunkCount * 2 : globalChunkCount;
|
|
770
|
+
const transformsStr = `${totalTransforms}/${totalTransforms}`;
|
|
771
|
+
const chunksStr = `${totalChunks}/${totalChunks}`;
|
|
772
|
+
renderProgress(
|
|
773
|
+
1,
|
|
774
|
+
transformsStr,
|
|
775
|
+
chunksStr,
|
|
776
|
+
width,
|
|
777
|
+
complete,
|
|
778
|
+
incomplete,
|
|
779
|
+
true
|
|
780
|
+
);
|
|
781
|
+
restoreOutput();
|
|
782
|
+
if (!globalHasError) {
|
|
783
|
+
setCacheData({
|
|
784
|
+
transformCount: Math.floor(globalTransformCount / 2),
|
|
785
|
+
chunkCount: Math.floor(globalChunkCount / 2)
|
|
786
|
+
});
|
|
787
|
+
console.log(`\u2705 \u6784\u5EFA\u6210\u529F\uFF01`);
|
|
788
|
+
console.log(` \u{1F4C1} \u8F93\u51FA\u76EE\u5F55: ${globalOutDir}`);
|
|
789
|
+
console.log(` \u23F1\uFE0F \u8017\u65F6: ${elapsed}s`);
|
|
790
|
+
} else {
|
|
791
|
+
console.log(`
|
|
792
|
+
\u274C \u6784\u5EFA\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u9519\u8BEF\u4FE1\u606F`);
|
|
793
|
+
}
|
|
794
|
+
globalIsBuilding = false;
|
|
795
|
+
}, 500);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// vitepress/config/index.ts
|
|
801
|
+
function loadTNotesConfig(rootPath) {
|
|
802
|
+
const configPath = path2.resolve(rootPath, ".tnotes.json");
|
|
803
|
+
const configContent = fs2.readFileSync(configPath, "utf-8");
|
|
804
|
+
return JSON.parse(configContent);
|
|
805
|
+
}
|
|
806
|
+
function defineNotesConfig(overrides = {}) {
|
|
807
|
+
const rootPath = process.cwd();
|
|
808
|
+
const config = loadTNotesConfig(rootPath);
|
|
809
|
+
const { repoName } = config;
|
|
810
|
+
const IGNORE_LIST = getIgnoreList(config);
|
|
811
|
+
const GITHUB_PAGE_URL = getGithubPageUrl(config);
|
|
812
|
+
const {
|
|
813
|
+
transformPageData: overrideTransformPageData,
|
|
814
|
+
vite: overrideVite,
|
|
815
|
+
...restOverrides
|
|
816
|
+
} = overrides;
|
|
817
|
+
return defineConfig({
|
|
818
|
+
appearance: "dark",
|
|
819
|
+
base: "/" + repoName + "/",
|
|
820
|
+
cleanUrls: true,
|
|
821
|
+
description: repoName,
|
|
822
|
+
head: getHeadConfig(config, GITHUB_PAGE_URL),
|
|
823
|
+
ignoreDeadLinks: true,
|
|
824
|
+
lang: "zh-Hans",
|
|
825
|
+
lastUpdated: false,
|
|
826
|
+
markdown: getMarkdownConfig(),
|
|
827
|
+
sitemap: {
|
|
828
|
+
hostname: GITHUB_PAGE_URL,
|
|
829
|
+
lastmodDateOnly: false
|
|
830
|
+
},
|
|
831
|
+
themeConfig: getThemeConfig(config),
|
|
832
|
+
title: repoName,
|
|
833
|
+
srcExclude: IGNORE_LIST,
|
|
834
|
+
vite: {
|
|
835
|
+
plugins: [
|
|
836
|
+
buildProgressPlugin(),
|
|
837
|
+
updateConfigPlugin(),
|
|
838
|
+
renameNotePlugin(),
|
|
839
|
+
getNoteByConfigIdPlugin(),
|
|
840
|
+
...overrideVite?.plugins || []
|
|
841
|
+
],
|
|
842
|
+
server: {
|
|
843
|
+
watch: {
|
|
844
|
+
ignored: IGNORE_LIST
|
|
845
|
+
},
|
|
846
|
+
...overrideVite?.server
|
|
847
|
+
},
|
|
848
|
+
css: {
|
|
849
|
+
preprocessorOptions: {
|
|
850
|
+
scss: {
|
|
851
|
+
silenceDeprecations: ["legacy-js-api"]
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
...overrideVite?.css
|
|
855
|
+
},
|
|
856
|
+
build: {
|
|
857
|
+
chunkSizeWarningLimit: 1e3,
|
|
858
|
+
...overrideVite?.build
|
|
859
|
+
},
|
|
860
|
+
define: {
|
|
861
|
+
__TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
|
|
862
|
+
__TNOTES_AUTHOR__: JSON.stringify(config.author),
|
|
863
|
+
__TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
|
|
864
|
+
__TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
|
|
865
|
+
...overrideVite?.define
|
|
866
|
+
},
|
|
867
|
+
resolve: {
|
|
868
|
+
dedupe: ["vue", "vitepress"],
|
|
869
|
+
...overrideVite?.resolve
|
|
870
|
+
},
|
|
871
|
+
optimizeDeps: {
|
|
872
|
+
include: [
|
|
873
|
+
// VitePress 内部 CJS 依赖 —— 需要 Vite 预构建为 ESM
|
|
874
|
+
"vitepress > @vscode/markdown-it-katex",
|
|
875
|
+
"vitepress > @braintree/sanitize-url",
|
|
876
|
+
"vitepress > dayjs",
|
|
877
|
+
"vitepress > dayjs/plugin/utc",
|
|
878
|
+
"vitepress > dayjs/plugin/localizedFormat"
|
|
879
|
+
],
|
|
880
|
+
...overrideVite?.optimizeDeps
|
|
881
|
+
}
|
|
882
|
+
},
|
|
883
|
+
transformPageData(pageData, ctx) {
|
|
884
|
+
if (/^notes\/\d{4}/.test(pageData.relativePath)) {
|
|
885
|
+
const fullPath = path2.resolve(rootPath, pageData.relativePath);
|
|
886
|
+
try {
|
|
887
|
+
pageData.frontmatter.rawContent = fs2.readFileSync(fullPath, "utf-8");
|
|
888
|
+
} catch {
|
|
889
|
+
pageData.frontmatter.rawContent = null;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
if (typeof overrideTransformPageData === "function") {
|
|
893
|
+
return overrideTransformPageData(pageData, ctx);
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
router: {
|
|
897
|
+
prefetchLinks: false
|
|
898
|
+
},
|
|
899
|
+
...restOverrides
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
export {
|
|
903
|
+
defineNotesConfig
|
|
904
|
+
};
|