@tnotesjs/core 0.1.14 → 0.1.16

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 (117) hide show
  1. package/README.md +87 -87
  2. package/dist/{chunk-FVKQPBPP.js → chunk-4MO7F7Q4.js} +2005 -1769
  3. package/dist/cli/index.js +1 -1
  4. package/dist/vitepress/config/index.js +212 -4
  5. package/package.json +1 -1
  6. package/types/config.ts +61 -61
  7. package/types/index.ts +11 -11
  8. package/types/note.ts +33 -33
  9. package/vitepress/assets/icons/icon__check.svg +3 -3
  10. package/vitepress/assets/icons/icon__clipboard.svg +7 -7
  11. package/vitepress/assets/icons/icon__close.svg +1 -1
  12. package/vitepress/assets/icons/icon__collapse.svg +1 -1
  13. package/vitepress/assets/icons/icon__confirm.svg +1 -1
  14. package/vitepress/assets/icons/icon__copy.svg +4 -4
  15. package/vitepress/assets/icons/icon__focus.svg +1 -1
  16. package/vitepress/assets/icons/icon__fold.svg +3 -3
  17. package/vitepress/assets/icons/icon__folder.svg +1 -1
  18. package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
  19. package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
  20. package/vitepress/assets/icons/icon__github.svg +3 -3
  21. package/vitepress/assets/icons/icon__mindmap.svg +1 -1
  22. package/vitepress/assets/icons/icon__next.svg +1 -1
  23. package/vitepress/assets/icons/icon__number_gray.svg +1 -1
  24. package/vitepress/assets/icons/icon__number_purple.svg +1 -1
  25. package/vitepress/assets/icons/icon__prev.svg +1 -1
  26. package/vitepress/assets/icons/icon__restore.svg +1 -1
  27. package/vitepress/assets/icons/icon__rotate.svg +4 -4
  28. package/vitepress/assets/icons/icon__search.svg +1 -1
  29. package/vitepress/assets/icons/icon__setting.svg +1 -0
  30. package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
  31. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
  32. package/vitepress/assets/icons/icon__totop.svg +5 -5
  33. package/vitepress/assets/icons/icon__vscode.svg +5 -5
  34. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
  35. package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
  36. package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
  37. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
  38. package/vitepress/assets/icons/index.ts +39 -38
  39. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
  40. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -373
  41. package/vitepress/components/CodeBlockFullscreen/index.ts +115 -115
  42. package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
  43. package/vitepress/components/Discussions/Discussions.module.scss +32 -32
  44. package/vitepress/components/Discussions/Discussions.vue +211 -211
  45. package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
  46. package/vitepress/components/EnWordList/EnWordList.vue +543 -543
  47. package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
  48. package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
  49. package/vitepress/components/Footprints/Footprints.module.scss +93 -93
  50. package/vitepress/components/Footprints/Footprints.vue +377 -377
  51. package/vitepress/components/Layout/AboutModal.module.scss +233 -233
  52. package/vitepress/components/Layout/AboutModal.vue +105 -105
  53. package/vitepress/components/Layout/AboutPanel.vue +270 -270
  54. package/vitepress/components/Layout/ContentCollapse.vue +603 -603
  55. package/vitepress/components/Layout/CustomSidebar.vue +878 -608
  56. package/vitepress/components/Layout/DocBeforeControls.vue +149 -149
  57. package/vitepress/components/Layout/DocFooter.vue +233 -233
  58. package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
  59. package/vitepress/components/Layout/ImagePreview.vue +281 -281
  60. package/vitepress/components/Layout/Layout.module.scss +661 -661
  61. package/vitepress/components/Layout/Layout.vue +618 -560
  62. package/vitepress/components/Layout/NavBarSettingsTrigger.vue +59 -0
  63. package/vitepress/components/Layout/NoteStatus.vue +140 -140
  64. package/vitepress/components/Layout/SidebarItems.vue +1083 -268
  65. package/vitepress/components/Layout/SidebarNavBefore.vue +171 -114
  66. package/vitepress/components/Layout/Swiper.vue +167 -167
  67. package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
  68. package/vitepress/components/Layout/ToggleFullContent.vue +35 -35
  69. package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
  70. package/vitepress/components/Layout/ToggleSidebar.vue +36 -36
  71. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
  72. package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
  73. package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
  74. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
  75. package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
  76. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
  77. package/vitepress/components/Layout/homeReadme.data.ts +124 -124
  78. package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
  79. package/vitepress/components/MarkMap/MarkMap.vue +405 -405
  80. package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
  81. package/vitepress/components/Mermaid/Mermaid.vue +365 -365
  82. package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
  83. package/vitepress/components/NotesTable/NotesTable.vue +98 -98
  84. package/vitepress/components/NotesTable/README.md +67 -67
  85. package/vitepress/components/Settings/Settings.module.scss +375 -433
  86. package/vitepress/components/Settings/Settings.vue +376 -306
  87. package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
  88. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
  89. package/vitepress/components/SidebarCard/SidebarCard.vue +946 -946
  90. package/vitepress/components/Tooltip/Tooltip.vue +70 -70
  91. package/vitepress/components/constants.ts +109 -91
  92. package/vitepress/components/notesConfig.data.ts +73 -73
  93. package/vitepress/components/sidebar.data.ts +59 -59
  94. package/vitepress/components/tnotes-config.data.ts +21 -21
  95. package/vitepress/components/utils.ts +26 -26
  96. package/vitepress/config/index.ts +169 -167
  97. package/vitepress/configs/constants.ts +26 -26
  98. package/vitepress/configs/head.config.ts +25 -25
  99. package/vitepress/configs/index.ts +9 -9
  100. package/vitepress/configs/markdown-it.d.ts +23 -23
  101. package/vitepress/configs/markdown.config.ts +366 -366
  102. package/vitepress/configs/theme.config.ts +108 -108
  103. package/vitepress/plugins/buildProgressPlugin.ts +434 -434
  104. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
  105. package/vitepress/plugins/renameNotePlugin.ts +68 -68
  106. package/vitepress/plugins/sidebarStructurePlugin.ts +260 -0
  107. package/vitepress/plugins/updateConfigPlugin.ts +63 -63
  108. package/vitepress/theme/index.ts +137 -137
  109. package/vitepress/theme/styles/base.scss +50 -50
  110. package/vitepress/theme/styles/components/404.scss +31 -31
  111. package/vitepress/theme/styles/components/collapse.scss +175 -175
  112. package/vitepress/theme/styles/components/markmap.scss +101 -101
  113. package/vitepress/theme/styles/components/swiper.scss +255 -255
  114. package/vitepress/theme/styles/index.scss +25 -25
  115. package/vitepress/theme/styles/layout.scss +70 -62
  116. package/vitepress/theme/styles/utilities.scss +39 -39
  117. package/vitepress/theme/styles/vitepress-override.scss +25 -25
@@ -1,560 +1,618 @@
1
- <template>
2
- <Layout>
3
- <template v-if="showNotFound" #not-found>
4
- <div class="not-found-container">
5
- <h1>404</h1>
6
- <p>Page not found</p>
7
- <!-- <div class="debug-info">
8
- <p>Current path: {{ decodedCurrentPath }}</p>
9
- <p>Matched ID: {{ matchedId }}</p>
10
- <p>Redirect path: {{ redirectPath }}</p>
11
- </div> -->layout
12
- </div>
13
- </template>
14
- <template #doc-top>
15
- <!-- <pre>vscodesNoteDir: {{ vscodeNotesDir }}</pre> -->
16
- <!-- <pre>vpData.page.value: {{ vpData.page.value }}</pre>
17
- <pre>currentNoteConfig: {{ currentNoteConfig }}</pre> -->
18
- <!-- <button @click="copyRawFile" title="Copy raw file">raw</button> -->
19
- <!-- <pre>{{ tocData }}</pre> -->
20
- <ImagePreview />
21
- <Swiper />
22
- <ContentCollapse />
23
- </template>
24
- <!-- <template #doc-bottom>doc-bottom</template> -->
25
- <template #doc-before>
26
- <DocBeforeControls
27
- :is-full-content-mode="isFullContentMode"
28
- :vscode-notes-dir="vscodeNotesDir"
29
- :is-home-readme="isHomeReadme"
30
- :current-note-id="currentNoteId"
31
- :created_at="created_at"
32
- :updated_at="updated_at"
33
- :home-readme-created-at="homeReadmeCreatedAt"
34
- :home-readme-updated-at="homeReadmeUpdatedAt"
35
- :time-modal-open="timeModalOpen"
36
- :all-collapsed="allCollapsed"
37
- @open-time-modal="openTimeModal"
38
- @toggle-all-collapse="toggleAllCollapse"
39
- />
40
- <!-- 笔记状态标题 -->
41
- <NoteStatus
42
- :note-config="currentNoteConfig"
43
- :is-notes-page="isNotesPage"
44
- />
45
-
46
- <AboutModal
47
- v-model="timeModalOpen"
48
- @close="onTimeModalClose"
49
- :title="modalTitle"
50
- >
51
- <template #title>
52
- {{ modalTitle }}
53
- </template>
54
-
55
- <AboutPanel
56
- :is-home-readme="isHomeReadme"
57
- :current-note-id="currentNoteId"
58
- :is-dev="isDev"
59
- v-model:editable-note-title="editableNoteTitle"
60
- v-model:editable-description="editableDescription"
61
- v-model:editable-note-status="editableNoteStatus"
62
- v-model:editable-discussions-enabled="editableDiscussionsEnabled"
63
- v-model:title-error="titleError"
64
- :modal-created-at="modalCreatedAt"
65
- :modal-updated-at="modalUpdatedAt"
66
- :modal-github-url="modalGithubUrl"
67
- :modal-github-page-url="modalGithubPageUrl"
68
- :completion-percentage="completionPercentage"
69
- :done-notes-len="doneNotesLen"
70
- :total-notes-len="totalNotesLen"
71
- @title-input="onTitleInput"
72
- @title-blur="onTitleBlur"
73
- @description-input="onDescriptionInput"
74
- @config-change="onConfigChange"
75
- />
76
-
77
- <!-- 操作按钮(仅开发环境且非首页显示) -->
78
- <template #footer v-if="isDev && !isHomeReadme">
79
- <div :class="$style.actionBar">
80
- <button
81
- :class="[
82
- $style.saveButton,
83
- { [$style.disabled]: !hasConfigChanges },
84
- ]"
85
- @click="saveNoteConfig"
86
- :disabled="!hasConfigChanges || isSaving"
87
- type="button"
88
- >
89
- {{ saveButtonText }}
90
- </button>
91
- <button
92
- v-if="hasConfigChanges"
93
- @click="resetNoteConfig"
94
- :class="$style.resetButton"
95
- type="button"
96
- >
97
- 重置
98
- </button>
99
- </div>
100
-
101
- <!-- 保存进度提示 -->
102
- <Transition name="toast">
103
- <div v-if="isSaving && savingMessage" :class="$style.loadingToast">
104
- <div :class="$style.loadingSpinner"></div>
105
- <span>{{ savingMessage }}</span>
106
- </div>
107
- </Transition>
108
-
109
- <!-- 保存成功提示 -->
110
- <Transition name="toast">
111
- <div v-if="showSuccessToast" :class="$style.toast">✓ 保存成功</div>
112
- </Transition>
113
- </template>
114
- </AboutModal>
115
- </template>
116
- <template #doc-footer-before>
117
- <!-- <div class="footer-time-info">
118
- <p title="首次提交时间">首次提交时间:{{ formatDate(created_at) }}</p>
119
- <p title="最近提交时间">最近提交时间:{{ formatDate(updated_at) }}</p>
120
- </div> -->
121
- </template>
122
- <template #doc-after>
123
- <!-- 自定义 DocFooter -->
124
- <DocFooter />
125
- <!-- {{ REPO_NAME + '.' + currentNoteId }} -->
126
- <Discussions
127
- v-if="isDiscussionsVisible"
128
- :id="currentNoteConfig.id"
129
- :note-number="currentNoteId || ''"
130
- :note-title="currentNoteTitle"
131
- />
132
- </template>
133
- <!-- <template #doc-bottom>
134
- <Discussions id="TNotes.template.0003" />
135
- </template> -->
136
-
137
- <template #aside-top>
138
- <!-- aside-top -->
139
- <!-- {{ vpData.page.value.title }} -->
140
- </template>
141
- <!-- <template #aside-outline-before>
142
- <span
143
- @click="scrollToTop"
144
- style="cursor: pointer; height: 1em; width: 1em"
145
- title="回到顶部"
146
- >
147
- <img :src="icon__totop" alt="to top" />
148
- </span>
149
- </template> -->
150
-
151
- <!-- 使用 sidebar-nav-before 插槽插入控制按钮 -->
152
- <template #sidebar-nav-before>
153
- <SidebarNavBefore
154
- :is-expanded="allSidebarExpanded"
155
- :show-note-id="showNoteId"
156
- @toggle-expand="toggleSidebarSections"
157
- @toggle-note-id="toggleNoteId"
158
- @focus-current="focusCurrentNote"
159
- @open-settings="openSettings"
160
- />
161
- </template>
162
-
163
- <!-- 使用 sidebar-nav-after 插槽插入自定义 Sidebar -->
164
- <template #sidebar-nav-after>
165
- <CustomSidebar ref="customSidebarRef" />
166
- </template>
167
- <!-- <template #sidebar-nav-after>sidebar-nav-after</template> -->
168
-
169
- <!-- <template #aside-outline-after>aside-outline-after</template> -->
170
- <!-- <template #aside-bottom>aside-bottom</template> -->
171
- <!-- <template #aside-ads-before>aside-ads-before</template> -->
172
- <!-- <template #aside-ads-after>aside-ads-after</template> -->
173
- <!-- <template #layout-top>layout-top</template> -->
174
- <!-- <template #layout-bottom>layout-bottom</template> -->
175
- <!-- <template #nav-bar-title-before>nav-bar-title-before</template> -->
176
- <!-- <template #nav-bar-title-after>nav-bar-title-after</template> -->
177
- <!-- <template #nav-bar-content-before>nav-bar-content-before</template> -->
178
- <!-- <template #nav-bar-content-after>nav-bar-content-after</template> -->
179
-
180
- <!-- !NOTE 不清楚下面的插槽所对应的位置 -->
181
- <!-- <template #nav-screen-content-before>nav-screen-content-before</template> -->
182
- <!-- <template #nav-screen-content-after>nav-screen-content-after</template> -->
183
- </Layout>
184
-
185
- <!-- 全局重命名遮罩:关于面板保存或文件系统重命名时由 useRenameOverlay 控制 -->
186
- <LoadingPage
187
- :visible="renameOverlayState.visible"
188
- :message="renameOverlayState.message"
189
- :tip="renameOverlayState.tip"
190
- />
191
-
192
- <!-- 全局设置 Dialog:由 useSettingsDialog 控制显隐 -->
193
- <SettingsDialog />
194
- </template>
195
-
196
- <script setup>
197
- import { useData, useRoute, useRouter } from "vitepress";
198
- import DefaultTheme from "vitepress/theme";
199
- import { computed, onMounted, ref, watch } from "vue";
200
-
201
- import { useCodeBlockFullscreen } from "../CodeBlockFullscreen";
202
- import { SIDEBAR_SHOW_NOTE_ID_KEY } from "../constants";
203
- import { data as allNotesConfig } from "../notesConfig.data.ts";
204
- import AboutModal from "./AboutModal.vue";
205
- import AboutPanel from "./AboutPanel.vue";
206
- import Discussions from "../Discussions/Discussions.vue";
207
- import LoadingPage from "../LoadingPage/LoadingPage.vue";
208
- import { useCollapseControl } from "./composables/useCollapseControl";
209
- import { useNoteConfig } from "./composables/useNoteConfig";
210
- import { useNoteSave } from "./composables/useNoteSave";
211
- import { useNoteValidation } from "./composables/useNoteValidation";
212
- import { useRedirect } from "./composables/useRedirect";
213
- import { useRenameOverlay } from "./composables/useRenameOverlay";
214
- import { useVSCodeIntegration } from "./composables/useVSCodeIntegration";
215
- import ContentCollapse from "./ContentCollapse.vue";
216
- import CustomSidebar from "./CustomSidebar.vue";
217
- import DocBeforeControls from "./DocBeforeControls.vue";
218
- import DocFooter from "./DocFooter.vue";
219
- import { data as readmeData } from "./homeReadme.data.ts";
220
- import ImagePreview from "./ImagePreview.vue";
221
- import NoteStatus from "./NoteStatus.vue";
222
- import SidebarNavBefore from "./SidebarNavBefore.vue";
223
- import Swiper from "./Swiper.vue";
224
- import { useSettingsDialog } from "../Settings/composables/useSettingsDialog";
225
- import SettingsDialog from "../Settings/SettingsDialog.vue";
226
-
227
- const { Layout } = DefaultTheme;
228
- const vpData = useData();
229
- const router = useRouter();
230
- const route = useRoute();
231
-
232
- // 启用代码块全屏功能
233
- useCodeBlockFullscreen();
234
-
235
- // 全局重命名遮罩状态(由 useRenameRedirect 控制 show/hide)
236
- const { state: renameOverlayState } = useRenameOverlay();
237
-
238
- // 全局设置 Dialog 控制
239
- const { open: openSettings } = useSettingsDialog();
240
-
241
- // 自定义侧边栏引用
242
- const customSidebarRef = ref(null);
243
- const showNoteId = ref(false);
244
-
245
- // 计算是否有展开的一级章节
246
- const allSidebarExpanded = computed(() => {
247
- if (!customSidebarRef.value) return false;
248
- return customSidebarRef.value.hasAnyFirstLevelExpanded();
249
- });
250
-
251
- // 初始化笔记编号显示状态
252
- if (typeof window !== "undefined") {
253
- const savedShowNoteId = localStorage.getItem(SIDEBAR_SHOW_NOTE_ID_KEY);
254
- showNoteId.value = savedShowNoteId === "true";
255
- }
256
-
257
- // 切换侧边栏展开/折叠状态(智能切换)
258
- function toggleSidebarSections() {
259
- if (customSidebarRef.value) {
260
- customSidebarRef.value.toggleExpandCollapse();
261
- }
262
- }
263
-
264
- // 切换笔记编号显示状态
265
- function toggleNoteId() {
266
- showNoteId.value = !showNoteId.value;
267
- if (typeof window !== "undefined") {
268
- localStorage.setItem(SIDEBAR_SHOW_NOTE_ID_KEY, showNoteId.value.toString());
269
- // 刷新页面以应用变化
270
- window.location.reload();
271
- }
272
- }
273
-
274
- // 聚焦到当前笔记
275
- function focusCurrentNote() {
276
- if (customSidebarRef.value) {
277
- customSidebarRef.value.focusCurrentNote();
278
- }
279
- }
280
-
281
- // 提取当前笔记的 ID(前 4 个数字)
282
- const currentNoteId = computed(() => {
283
- const relativePath = vpData.page.value.relativePath;
284
- // relativePath 格式: notes/0001. 标题/README.md
285
- const match = relativePath.match(/notes\/(\d{4})/);
286
- const id = match ? match[1] : null;
287
-
288
- return id;
289
- });
290
-
291
- // 判断是否是笔记页面(notes 目录下)
292
- const isNotesPage = computed(() => {
293
- return vpData.page.value.relativePath.startsWith("notes/");
294
- });
295
-
296
- // 提取当前笔记的标题(从 relativePath)
297
- const currentNoteTitle = computed(() => {
298
- const relativePath = vpData.page.value.relativePath;
299
- // relativePath 格式: notes/0001. 标题/README.md
300
- const match = relativePath.match(/notes\/\d{4}\.\s+([^/]+)\//);
301
- const title = match ? match[1] : "";
302
-
303
- return title;
304
- });
305
-
306
- // 根据当前笔记 ID 获取配置数据
307
- const currentNoteConfig = computed(() => {
308
- return currentNoteId.value && allNotesConfig[currentNoteId.value]
309
- ? allNotesConfig[currentNoteId.value]
310
- : {
311
- bilibili: [],
312
- done: false,
313
- enableDiscussions: false,
314
- };
315
- });
316
-
317
- const isDiscussionsVisible = computed(
318
- () => currentNoteConfig.value.enableDiscussions,
319
- );
320
- const updated_at = computed(() => currentNoteConfig.value.updated_at);
321
- const created_at = computed(() => currentNoteConfig.value.created_at);
322
-
323
- // 判断是否为首页 README.md
324
- const isHomeReadme = computed(() => vpData.page.value.filePath === "README.md");
325
- const doneNotesLen = computed(() => readmeData?.doneNotesLen || 0);
326
- const totalNotesLen = computed(() => readmeData?.totalNotesLen || 0);
327
-
328
- // 完成进度百分比
329
- const completionPercentage = computed(() => {
330
- if (!totalNotesLen.value || totalNotesLen.value === 0) return null;
331
- return Math.round((doneNotesLen.value / totalNotesLen.value) * 100);
332
- });
333
-
334
- // 首页 README.md 的时间戳
335
- const homeReadmeCreatedAt = computed(() => readmeData?.created_at);
336
- const homeReadmeUpdatedAt = computed(() => readmeData?.updated_at);
337
-
338
- // 计算当前笔记的 GitHub URL
339
- const currentNoteGithubUrl = computed(() => {
340
- if (!currentNoteId.value) return "";
341
-
342
- // 从 relativePath 提取笔记路径
343
- // 格式如: notes/0001. xxx/README.md
344
- const relativePath = vpData.page.value.relativePath;
345
- const match = relativePath.match(/notes\/(\d{4}\.[^/]+)/);
346
-
347
- if (!match) return "";
348
-
349
- const notePath = match[0]; // notes/0001. xxx
350
- const repoName = vpData.site.value.title.toLowerCase(); // TNotes.introduction
351
-
352
- return `https://github.com/tnotesjs/${repoName}/tree/main/${notePath}`;
353
- });
354
-
355
- // #region - Composables
356
- // 404 重定向
357
- const { showNotFound, decodedCurrentPath, initRedirectCheck } =
358
- useRedirect(allNotesConfig);
359
-
360
- // modal 控制
361
- const timeModalOpen = ref(false);
362
-
363
- // 笔记配置管理
364
- const {
365
- editableNoteStatus,
366
- editableDiscussionsEnabled,
367
- editableNoteTitle,
368
- editableDescription,
369
- titleError,
370
- hasConfigChanges,
371
- resetNoteConfig,
372
- updateOriginalValues,
373
- } = useNoteConfig(
374
- currentNoteId,
375
- currentNoteConfig,
376
- currentNoteTitle,
377
- timeModalOpen,
378
- );
379
-
380
- // 标题验证
381
- const { onTitleInput: validateTitleInput, onTitleBlur: validateTitleBlur } =
382
- useNoteValidation();
383
-
384
- // 保存逻辑
385
- const {
386
- isSaving,
387
- showSuccessToast,
388
- savingMessage,
389
- saveButtonText,
390
- saveNoteConfig,
391
- } = useNoteSave(
392
- currentNoteId,
393
- computed(() => {
394
- if (typeof window === "undefined") return false;
395
- return (
396
- window.location.hostname === "localhost" ||
397
- window.location.hostname === "127.0.0.1"
398
- );
399
- }),
400
- hasConfigChanges,
401
- titleError,
402
- editableNoteTitle,
403
- computed(() => currentNoteTitle.value),
404
- editableNoteStatus,
405
- computed(() => currentNoteConfig.value.done || false),
406
- editableDiscussionsEnabled,
407
- computed(() => currentNoteConfig.value.enableDiscussions || false),
408
- editableDescription,
409
- computed(() => currentNoteConfig.value.description || ""),
410
- allNotesConfig,
411
- updateOriginalValues,
412
- );
413
-
414
- // 折叠控制
415
- const { allCollapsed, toggleAllCollapse } = useCollapseControl();
416
-
417
- // VSCode 集成
418
- const { vscodeNotesDir, updateVscodeNoteDir, interceptHomeReadmeLinks } =
419
- useVSCodeIntegration();
420
-
421
- // 判断是否为开发环境
422
- const isDev = computed(() => {
423
- if (typeof window === "undefined") return false;
424
- return (
425
- window.location.hostname === "localhost" ||
426
- window.location.hostname === "127.0.0.1"
427
- );
428
- });
429
-
430
- // #endregion
431
-
432
- // modal 标题
433
- const modalTitle = computed(() => {
434
- return isHomeReadme.value ? "关于这个知识库" : "关于这篇笔记";
435
- });
436
-
437
- // modal 中显示的 GitHub 链接
438
- const modalGithubUrl = computed(() => {
439
- if (isHomeReadme.value) {
440
- const repoName = vpData.site.value.title.toLowerCase();
441
- return `https://github.com/tnotesjs/${repoName}`;
442
- }
443
- return currentNoteGithubUrl.value;
444
- });
445
-
446
- // modal 中显示的 GitHub Page 链接
447
- const modalGithubPageUrl = computed(() => {
448
- if (isHomeReadme.value) {
449
- const repoName = vpData.site.value.title; // 保持原始大小写
450
- return `https://tnotesjs.github.io/${repoName}/`;
451
- }
452
- // 笔记页面的 GitHub Page 链接
453
- if (currentNoteId.value && currentNoteTitle.value) {
454
- const repoName = vpData.site.value.title; // 保持原始大小写
455
- const encodedTitle = encodeURIComponent(currentNoteTitle.value);
456
- return `https://tnotesjs.github.io/${repoName}/notes/${currentNoteId.value}.%20${encodedTitle}/README`;
457
- }
458
- return "";
459
- });
460
-
461
- // modal 中显示的创建时间
462
- const modalCreatedAt = computed(() => {
463
- return isHomeReadme.value ? homeReadmeCreatedAt.value : created_at.value;
464
- });
465
-
466
- // modal 中显示的更新时间
467
- const modalUpdatedAt = computed(() => {
468
- return isHomeReadme.value ? homeReadmeUpdatedAt.value : updated_at.value;
469
- });
470
-
471
- function openTimeModal() {
472
- timeModalOpen.value = true;
473
- }
474
-
475
- function onTimeModalClose() {
476
- timeModalOpen.value = false;
477
- }
478
-
479
- // 配置变更时的回调
480
- function onConfigChange() {
481
- // 配置变更时不需要做额外操作,只需要触发 hasConfigChanges 计算
482
- }
483
-
484
- // 标题输入事件
485
- function onTitleInput() {
486
- validateTitleInput(editableNoteTitle, titleError);
487
- }
488
-
489
- // 标题失焦事件
490
- function onTitleBlur() {
491
- validateTitleBlur(editableNoteTitle, titleError);
492
- }
493
-
494
- // 简介输入事件
495
- function onDescriptionInput() {
496
- // 简介没有特殊验证,只需要触发变更检测
497
- }
498
-
499
- // #region - 全屏状态检测
500
- const isFullContentMode = ref(false);
501
-
502
- function checkFullContentMode() {
503
- if (typeof document === "undefined") return;
504
-
505
- const vpApp = document.querySelector(".VPContent");
506
- if (vpApp) {
507
- const sidebar = document.querySelector(".VPSidebar");
508
- if (sidebar) {
509
- const sidebarDisplay = window.getComputedStyle(sidebar).display;
510
- isFullContentMode.value = sidebarDisplay === "none";
511
- }
512
- }
513
- }
514
- // #endregion
515
-
516
- // 生命周期钩子
517
- onMounted(() => {
518
- updateVscodeNoteDir();
519
- interceptHomeReadmeLinks(isHomeReadme, router);
520
- initRedirectCheck();
521
-
522
- if (typeof window !== "undefined") {
523
- checkFullContentMode();
524
- window.addEventListener("resize", checkFullContentMode);
525
-
526
- // 监听 VitePress 的侧边栏切换事件
527
- const observer = new MutationObserver(checkFullContentMode);
528
- const vpLayout = document.querySelector(".Layout");
529
- if (vpLayout) {
530
- observer.observe(vpLayout, {
531
- attributes: true,
532
- childList: true,
533
- subtree: true,
534
- });
535
- }
536
- }
537
- });
538
-
539
- // 监听路由变化
540
- watch(
541
- () => vpData.page.value.relativePath,
542
- () => {
543
- updateVscodeNoteDir();
544
- interceptHomeReadmeLinks(isHomeReadme, router);
545
- },
546
- );
547
-
548
- watch(
549
- () => route.path,
550
- () => {
551
- setTimeout(checkFullContentMode, 100);
552
- },
553
- );
554
- </script>
555
-
556
- <style>
557
- @import "../CodeBlockFullscreen/styles.css";
558
- </style>
559
-
560
- <style module src="./Layout.module.scss" scoped></style>
1
+ <template>
2
+ <Layout>
3
+ <template v-if="showNotFound" #not-found>
4
+ <div class="not-found-container">
5
+ <h1>404</h1>
6
+ <p>Page not found</p>
7
+ <!-- <div class="debug-info">
8
+ <p>Current path: {{ decodedCurrentPath }}</p>
9
+ <p>Matched ID: {{ matchedId }}</p>
10
+ <p>Redirect path: {{ redirectPath }}</p>
11
+ </div> -->layout
12
+ </div>
13
+ </template>
14
+ <template #doc-top>
15
+ <!-- <pre>vscodesNoteDir: {{ vscodeNotesDir }}</pre> -->
16
+ <!-- <pre>vpData.page.value: {{ vpData.page.value }}</pre>
17
+ <pre>currentNoteConfig: {{ currentNoteConfig }}</pre> -->
18
+ <!-- <button @click="copyRawFile" title="Copy raw file">raw</button> -->
19
+ <!-- <pre>{{ tocData }}</pre> -->
20
+ <ImagePreview />
21
+ <Swiper />
22
+ <ContentCollapse />
23
+ </template>
24
+ <!-- <template #doc-bottom>doc-bottom</template> -->
25
+ <template #doc-before>
26
+ <DocBeforeControls
27
+ :is-full-content-mode="isFullContentMode"
28
+ :vscode-notes-dir="vscodeNotesDir"
29
+ :is-home-readme="isHomeReadme"
30
+ :current-note-id="currentNoteId"
31
+ :created_at="created_at"
32
+ :updated_at="updated_at"
33
+ :home-readme-created-at="homeReadmeCreatedAt"
34
+ :home-readme-updated-at="homeReadmeUpdatedAt"
35
+ :time-modal-open="timeModalOpen"
36
+ :all-collapsed="allCollapsed"
37
+ @open-time-modal="openTimeModal"
38
+ @toggle-all-collapse="toggleAllCollapse"
39
+ />
40
+ <!-- 笔记状态标题 -->
41
+ <NoteStatus
42
+ :note-config="currentNoteConfig"
43
+ :is-notes-page="isNotesPage"
44
+ />
45
+
46
+ <AboutModal
47
+ v-model="timeModalOpen"
48
+ @close="onTimeModalClose"
49
+ :title="modalTitle"
50
+ >
51
+ <template #title>
52
+ {{ modalTitle }}
53
+ </template>
54
+
55
+ <AboutPanel
56
+ :is-home-readme="modalIsHomeReadme"
57
+ :current-note-id="modalNoteId"
58
+ :is-dev="isDev"
59
+ v-model:editable-note-title="editableNoteTitle"
60
+ v-model:editable-description="editableDescription"
61
+ v-model:editable-note-status="editableNoteStatus"
62
+ v-model:editable-discussions-enabled="editableDiscussionsEnabled"
63
+ v-model:title-error="titleError"
64
+ :modal-created-at="modalCreatedAt"
65
+ :modal-updated-at="modalUpdatedAt"
66
+ :modal-github-url="modalGithubUrl"
67
+ :modal-github-page-url="modalGithubPageUrl"
68
+ :completion-percentage="completionPercentage"
69
+ :done-notes-len="doneNotesLen"
70
+ :total-notes-len="totalNotesLen"
71
+ @title-input="onTitleInput"
72
+ @title-blur="onTitleBlur"
73
+ @description-input="onDescriptionInput"
74
+ @config-change="onConfigChange"
75
+ />
76
+
77
+ <!-- 操作按钮(仅开发环境且非首页显示) -->
78
+ <template #footer v-if="isDev && !modalIsHomeReadme">
79
+ <div :class="$style.actionBar">
80
+ <button
81
+ :class="[
82
+ $style.saveButton,
83
+ { [$style.disabled]: !hasConfigChanges },
84
+ ]"
85
+ @click="saveNoteConfig"
86
+ :disabled="!hasConfigChanges || isSaving"
87
+ type="button"
88
+ >
89
+ {{ saveButtonText }}
90
+ </button>
91
+ <button
92
+ v-if="hasConfigChanges"
93
+ @click="resetNoteConfig"
94
+ :class="$style.resetButton"
95
+ type="button"
96
+ >
97
+ 重置
98
+ </button>
99
+ </div>
100
+
101
+ <!-- 保存进度提示 -->
102
+ <Transition name="toast">
103
+ <div v-if="isSaving && savingMessage" :class="$style.loadingToast">
104
+ <div :class="$style.loadingSpinner"></div>
105
+ <span>{{ savingMessage }}</span>
106
+ </div>
107
+ </Transition>
108
+
109
+ <!-- 保存成功提示 -->
110
+ <Transition name="toast">
111
+ <div v-if="showSuccessToast" :class="$style.toast">✓ 保存成功</div>
112
+ </Transition>
113
+ </template>
114
+ </AboutModal>
115
+ </template>
116
+ <template #doc-footer-before>
117
+ <!-- <div class="footer-time-info">
118
+ <p title="首次提交时间">首次提交时间:{{ formatDate(created_at) }}</p>
119
+ <p title="最近提交时间">最近提交时间:{{ formatDate(updated_at) }}</p>
120
+ </div> -->
121
+ </template>
122
+ <template #doc-after>
123
+ <!-- 自定义 DocFooter -->
124
+ <DocFooter />
125
+ <!-- {{ REPO_NAME + '.' + currentNoteId }} -->
126
+ <Discussions
127
+ v-if="isDiscussionsVisible"
128
+ :id="currentNoteConfig.id"
129
+ :note-number="currentNoteId || ''"
130
+ :note-title="currentNoteTitle"
131
+ />
132
+ </template>
133
+ <!-- <template #doc-bottom>
134
+ <Discussions id="TNotes.template.0003" />
135
+ </template> -->
136
+
137
+ <template #aside-top>
138
+ <!-- aside-top -->
139
+ <!-- {{ vpData.page.value.title }} -->
140
+ </template>
141
+ <!-- <template #aside-outline-before>
142
+ <span
143
+ @click="scrollToTop"
144
+ style="cursor: pointer; height: 1em; width: 1em"
145
+ title="回到顶部"
146
+ >
147
+ <img :src="icon__totop" alt="to top" />
148
+ </span>
149
+ </template> -->
150
+
151
+ <!-- 使用 sidebar-nav-before 插槽插入控制按钮 -->
152
+ <template #sidebar-nav-before>
153
+ <SidebarNavBefore
154
+ :is-expanded="allSidebarExpanded"
155
+ :show-note-id="showNoteId"
156
+ @toggle-expand="toggleSidebarSections"
157
+ @toggle-note-id="toggleNoteId"
158
+ @focus-current="focusCurrentNote"
159
+ />
160
+ </template>
161
+
162
+ <!-- 使用 sidebar-nav-after 插槽插入自定义 Sidebar -->
163
+ <template #sidebar-nav-after>
164
+ <CustomSidebar
165
+ ref="customSidebarRef"
166
+ @open-note-about="openSidebarNoteAbout"
167
+ />
168
+ </template>
169
+ <!-- <template #sidebar-nav-after>sidebar-nav-after</template> -->
170
+
171
+ <!-- <template #aside-outline-after>aside-outline-after</template> -->
172
+ <!-- <template #aside-bottom>aside-bottom</template> -->
173
+ <!-- <template #aside-ads-before>aside-ads-before</template> -->
174
+ <!-- <template #aside-ads-after>aside-ads-after</template> -->
175
+ <!-- <template #layout-top>layout-top</template> -->
176
+ <!-- <template #layout-bottom>layout-bottom</template> -->
177
+ <!-- <template #nav-bar-title-before>nav-bar-title-before</template> -->
178
+ <!-- <template #nav-bar-title-after>nav-bar-title-after</template> -->
179
+ <!-- <template #nav-bar-content-before>nav-bar-content-before</template> -->
180
+ <!-- 设置入口:固定在 VPNav 右侧(social-links / appearance 之后,extra 之前) -->
181
+ <template #nav-bar-content-after>
182
+ <NavBarSettingsTrigger />
183
+ </template>
184
+
185
+ <!-- !NOTE 不清楚下面的插槽所对应的位置 -->
186
+ <!-- <template #nav-screen-content-before>nav-screen-content-before</template> -->
187
+ <!-- <template #nav-screen-content-after>nav-screen-content-after</template> -->
188
+ </Layout>
189
+
190
+ <!-- 全局重命名遮罩:关于面板保存或文件系统重命名时由 useRenameOverlay 控制 -->
191
+ <LoadingPage
192
+ :visible="renameOverlayState.visible"
193
+ :message="renameOverlayState.message"
194
+ :tip="renameOverlayState.tip"
195
+ />
196
+
197
+ <!-- 全局设置 Dialog:由 useSettingsDialog 控制显隐 -->
198
+ <SettingsDialog />
199
+ </template>
200
+
201
+ <script setup>
202
+ import { useData, useRoute, useRouter } from "vitepress";
203
+ import DefaultTheme from "vitepress/theme";
204
+ import { computed, onMounted, ref, watch } from "vue";
205
+
206
+ import { useCodeBlockFullscreen } from "../CodeBlockFullscreen";
207
+ import { SIDEBAR_SHOW_NOTE_ID_KEY } from "../constants";
208
+ import { data as allNotesConfig } from "../notesConfig.data.ts";
209
+ import AboutModal from "./AboutModal.vue";
210
+ import AboutPanel from "./AboutPanel.vue";
211
+ import Discussions from "../Discussions/Discussions.vue";
212
+ import LoadingPage from "../LoadingPage/LoadingPage.vue";
213
+ import { useCollapseControl } from "./composables/useCollapseControl";
214
+ import { useNoteConfig } from "./composables/useNoteConfig";
215
+ import { useNoteSave } from "./composables/useNoteSave";
216
+ import { useNoteValidation } from "./composables/useNoteValidation";
217
+ import { useRedirect } from "./composables/useRedirect";
218
+ import { useRenameOverlay } from "./composables/useRenameOverlay";
219
+ import { useVSCodeIntegration } from "./composables/useVSCodeIntegration";
220
+ import ContentCollapse from "./ContentCollapse.vue";
221
+ import CustomSidebar from "./CustomSidebar.vue";
222
+ import DocBeforeControls from "./DocBeforeControls.vue";
223
+ import DocFooter from "./DocFooter.vue";
224
+ import { data as readmeData } from "./homeReadme.data.ts";
225
+ import ImagePreview from "./ImagePreview.vue";
226
+ import NavBarSettingsTrigger from "./NavBarSettingsTrigger.vue";
227
+ import NoteStatus from "./NoteStatus.vue";
228
+ import SidebarNavBefore from "./SidebarNavBefore.vue";
229
+ import Swiper from "./Swiper.vue";
230
+ import SettingsDialog from "../Settings/SettingsDialog.vue";
231
+
232
+ const { Layout } = DefaultTheme;
233
+ const vpData = useData();
234
+ const router = useRouter();
235
+ const route = useRoute();
236
+
237
+ // 启用代码块全屏功能
238
+ useCodeBlockFullscreen();
239
+
240
+ // 全局重命名遮罩状态(由 useRenameRedirect 控制 show/hide)
241
+ const { state: renameOverlayState } = useRenameOverlay();
242
+
243
+ // 自定义侧边栏引用
244
+ const customSidebarRef = ref(null);
245
+ const showNoteId = ref(false);
246
+
247
+ // 计算是否有展开的一级章节
248
+ const allSidebarExpanded = computed(() => {
249
+ if (!customSidebarRef.value) return false;
250
+ return customSidebarRef.value.hasAnyFirstLevelExpanded();
251
+ });
252
+
253
+ // 初始化笔记编号显示状态
254
+ if (typeof window !== "undefined") {
255
+ const savedShowNoteId = localStorage.getItem(SIDEBAR_SHOW_NOTE_ID_KEY);
256
+ showNoteId.value = savedShowNoteId === "true";
257
+ }
258
+
259
+ // 切换侧边栏展开/折叠状态(智能切换)
260
+ function toggleSidebarSections() {
261
+ if (customSidebarRef.value) {
262
+ customSidebarRef.value.toggleExpandCollapse();
263
+ }
264
+ }
265
+
266
+ // 切换笔记编号显示状态
267
+ function toggleNoteId() {
268
+ showNoteId.value = !showNoteId.value;
269
+ if (typeof window !== "undefined") {
270
+ localStorage.setItem(SIDEBAR_SHOW_NOTE_ID_KEY, showNoteId.value.toString());
271
+ // 刷新页面以应用变化
272
+ window.location.reload();
273
+ }
274
+ }
275
+
276
+ // 聚焦到当前笔记
277
+ function focusCurrentNote() {
278
+ if (customSidebarRef.value) {
279
+ customSidebarRef.value.focusCurrentNote();
280
+ }
281
+ }
282
+
283
+ // 提取当前笔记的 ID(前 4 个数字)
284
+ const currentNoteId = computed(() => {
285
+ const relativePath = vpData.page.value.relativePath;
286
+ // relativePath 格式: notes/0001. 标题/README.md
287
+ const match = relativePath.match(/notes\/(\d{4})/);
288
+ const id = match ? match[1] : null;
289
+
290
+ return id;
291
+ });
292
+
293
+ // 判断是否是笔记页面(notes 目录下)
294
+ const isNotesPage = computed(() => {
295
+ return vpData.page.value.relativePath.startsWith("notes/");
296
+ });
297
+
298
+ // 提取当前笔记的标题(从 relativePath
299
+ const currentNoteTitle = computed(() => {
300
+ const relativePath = vpData.page.value.relativePath;
301
+ // relativePath 格式: notes/0001. 标题/README.md
302
+ const match = relativePath.match(/notes\/\d{4}\.\s+([^/]+)\//);
303
+ const title = match ? match[1] : "";
304
+
305
+ return title;
306
+ });
307
+
308
+ // 根据当前笔记 ID 获取配置数据
309
+ const currentNoteConfig = computed(() => {
310
+ return currentNoteId.value && allNotesConfig[currentNoteId.value]
311
+ ? allNotesConfig[currentNoteId.value]
312
+ : {
313
+ bilibili: [],
314
+ done: false,
315
+ enableDiscussions: false,
316
+ };
317
+ });
318
+
319
+ function getEmptyNoteConfig() {
320
+ return {
321
+ bilibili: [],
322
+ done: false,
323
+ enableDiscussions: false,
324
+ };
325
+ }
326
+
327
+ const isDiscussionsVisible = computed(
328
+ () => currentNoteConfig.value.enableDiscussions,
329
+ );
330
+ const updated_at = computed(() => currentNoteConfig.value.updated_at);
331
+ const created_at = computed(() => currentNoteConfig.value.created_at);
332
+
333
+ // 判断是否为首页 README.md
334
+ const isHomeReadme = computed(() => vpData.page.value.filePath === "README.md");
335
+ const doneNotesLen = computed(() => readmeData?.doneNotesLen || 0);
336
+ const totalNotesLen = computed(() => readmeData?.totalNotesLen || 0);
337
+
338
+ // 完成进度百分比
339
+ const completionPercentage = computed(() => {
340
+ if (!totalNotesLen.value || totalNotesLen.value === 0) return null;
341
+ return Math.round((doneNotesLen.value / totalNotesLen.value) * 100);
342
+ });
343
+
344
+ // 首页 README.md 的时间戳
345
+ const homeReadmeCreatedAt = computed(() => readmeData?.created_at);
346
+ const homeReadmeUpdatedAt = computed(() => readmeData?.updated_at);
347
+
348
+ // #region - Composables
349
+ // 404 重定向
350
+ const { showNotFound, decodedCurrentPath, initRedirectCheck } =
351
+ useRedirect(allNotesConfig);
352
+
353
+ // modal 控制
354
+ const timeModalOpen = ref(false);
355
+ const sidebarAboutNoteId = ref(null);
356
+
357
+ const modalIsHomeReadme = computed(
358
+ () => !sidebarAboutNoteId.value && isHomeReadme.value,
359
+ );
360
+
361
+ const modalNoteId = computed(() => sidebarAboutNoteId.value || currentNoteId.value);
362
+
363
+ function safeDecode(value) {
364
+ try {
365
+ return decodeURIComponent(value);
366
+ } catch {
367
+ return value;
368
+ }
369
+ }
370
+
371
+ function getNoteFolderSegment(noteId) {
372
+ if (!noteId) return "";
373
+
374
+ const source =
375
+ noteId === currentNoteId.value
376
+ ? vpData.page.value.relativePath
377
+ : allNotesConfig[noteId]?.redirect || "";
378
+ const match = source.match(/notes\/([^/]+)\/README/);
379
+
380
+ return match ? match[1] : "";
381
+ }
382
+
383
+ function getNoteTitleById(noteId) {
384
+ const folderSegment = getNoteFolderSegment(noteId);
385
+ const match = folderSegment.match(/^\d{4}\.\s+(.+)$/);
386
+
387
+ return match ? safeDecode(match[1]) : "";
388
+ }
389
+
390
+ const modalNoteTitle = computed(() => {
391
+ if (!sidebarAboutNoteId.value) return currentNoteTitle.value;
392
+ return getNoteTitleById(sidebarAboutNoteId.value);
393
+ });
394
+
395
+ const modalNoteConfig = computed(() => {
396
+ return modalNoteId.value && allNotesConfig[modalNoteId.value]
397
+ ? allNotesConfig[modalNoteId.value]
398
+ : getEmptyNoteConfig();
399
+ });
400
+
401
+ // 笔记配置管理
402
+ const {
403
+ editableNoteStatus,
404
+ editableDiscussionsEnabled,
405
+ editableNoteTitle,
406
+ editableDescription,
407
+ titleError,
408
+ hasConfigChanges,
409
+ resetNoteConfig,
410
+ updateOriginalValues,
411
+ } = useNoteConfig(
412
+ modalNoteId,
413
+ modalNoteConfig,
414
+ modalNoteTitle,
415
+ timeModalOpen,
416
+ );
417
+
418
+ // 标题验证
419
+ const { onTitleInput: validateTitleInput, onTitleBlur: validateTitleBlur } =
420
+ useNoteValidation();
421
+
422
+ // 保存逻辑
423
+ const {
424
+ isSaving,
425
+ showSuccessToast,
426
+ savingMessage,
427
+ saveButtonText,
428
+ saveNoteConfig,
429
+ } = useNoteSave(
430
+ modalNoteId,
431
+ computed(() => {
432
+ if (typeof window === "undefined") return false;
433
+ return (
434
+ window.location.hostname === "localhost" ||
435
+ window.location.hostname === "127.0.0.1"
436
+ );
437
+ }),
438
+ hasConfigChanges,
439
+ titleError,
440
+ editableNoteTitle,
441
+ computed(() => modalNoteTitle.value),
442
+ editableNoteStatus,
443
+ computed(() => modalNoteConfig.value.done || false),
444
+ editableDiscussionsEnabled,
445
+ computed(() => modalNoteConfig.value.enableDiscussions || false),
446
+ editableDescription,
447
+ computed(() => modalNoteConfig.value.description || ""),
448
+ allNotesConfig,
449
+ updateOriginalValues,
450
+ );
451
+
452
+ // 折叠控制
453
+ const { allCollapsed, toggleAllCollapse } = useCollapseControl();
454
+
455
+ // VSCode 集成
456
+ const { vscodeNotesDir, updateVscodeNoteDir, interceptHomeReadmeLinks } =
457
+ useVSCodeIntegration();
458
+
459
+ // 判断是否为开发环境
460
+ const isDev = computed(() => {
461
+ if (typeof window === "undefined") return false;
462
+ return (
463
+ window.location.hostname === "localhost" ||
464
+ window.location.hostname === "127.0.0.1"
465
+ );
466
+ });
467
+
468
+ // #endregion
469
+
470
+ // modal 标题
471
+ const modalTitle = computed(() => {
472
+ return modalIsHomeReadme.value ? "关于这个知识库" : "关于这篇笔记";
473
+ });
474
+
475
+ // modal 中显示的 GitHub 链接
476
+ const modalGithubUrl = computed(() => {
477
+ if (modalIsHomeReadme.value) {
478
+ const repoName = vpData.site.value.title.toLowerCase();
479
+ return `https://github.com/tnotesjs/${repoName}`;
480
+ }
481
+
482
+ const folderSegment = getNoteFolderSegment(modalNoteId.value);
483
+ if (!folderSegment) return "";
484
+
485
+ const repoName = vpData.site.value.title.toLowerCase();
486
+ return `https://github.com/tnotesjs/${repoName}/tree/main/notes/${encodeURIComponent(folderSegment)}`;
487
+ });
488
+
489
+ // modal 中显示的 GitHub Page 链接
490
+ const modalGithubPageUrl = computed(() => {
491
+ if (modalIsHomeReadme.value) {
492
+ const repoName = vpData.site.value.title; // 保持原始大小写
493
+ return `https://tnotesjs.github.io/${repoName}/`;
494
+ }
495
+ // 笔记页面的 GitHub Page 链接
496
+ const folderSegment = getNoteFolderSegment(modalNoteId.value);
497
+ if (modalNoteId.value && folderSegment) {
498
+ const repoName = vpData.site.value.title; // 保持原始大小写
499
+ return `https://tnotesjs.github.io/${repoName}/notes/${encodeURIComponent(folderSegment)}/README`;
500
+ }
501
+ return "";
502
+ });
503
+
504
+ // modal 中显示的创建时间
505
+ const modalCreatedAt = computed(() => {
506
+ return modalIsHomeReadme.value
507
+ ? homeReadmeCreatedAt.value
508
+ : modalNoteConfig.value.created_at;
509
+ });
510
+
511
+ // modal 中显示的更新时间
512
+ const modalUpdatedAt = computed(() => {
513
+ return modalIsHomeReadme.value
514
+ ? homeReadmeUpdatedAt.value
515
+ : modalNoteConfig.value.updated_at;
516
+ });
517
+
518
+ function openTimeModal() {
519
+ sidebarAboutNoteId.value = null;
520
+ timeModalOpen.value = true;
521
+ }
522
+
523
+ function onTimeModalClose() {
524
+ timeModalOpen.value = false;
525
+ sidebarAboutNoteId.value = null;
526
+ }
527
+
528
+ function openSidebarNoteAbout(noteIndex) {
529
+ sidebarAboutNoteId.value = noteIndex;
530
+ timeModalOpen.value = true;
531
+ }
532
+
533
+ // 配置变更时的回调
534
+ function onConfigChange() {
535
+ // 配置变更时不需要做额外操作,只需要触发 hasConfigChanges 计算
536
+ }
537
+
538
+ // 标题输入事件
539
+ function onTitleInput() {
540
+ validateTitleInput(editableNoteTitle, titleError);
541
+ }
542
+
543
+ // 标题失焦事件
544
+ function onTitleBlur() {
545
+ validateTitleBlur(editableNoteTitle, titleError);
546
+ }
547
+
548
+ // 简介输入事件
549
+ function onDescriptionInput() {
550
+ // 简介没有特殊验证,只需要触发变更检测
551
+ }
552
+
553
+ // #region - 全屏状态检测
554
+ const isFullContentMode = ref(false);
555
+
556
+ function checkFullContentMode() {
557
+ if (typeof document === "undefined") return;
558
+
559
+ const vpApp = document.querySelector(".VPContent");
560
+ if (vpApp) {
561
+ const sidebar = document.querySelector(".VPSidebar");
562
+ if (sidebar) {
563
+ const sidebarDisplay = window.getComputedStyle(sidebar).display;
564
+ isFullContentMode.value = sidebarDisplay === "none";
565
+ }
566
+ }
567
+ }
568
+ // #endregion
569
+
570
+ // 生命周期钩子
571
+ onMounted(() => {
572
+ updateVscodeNoteDir();
573
+ interceptHomeReadmeLinks(isHomeReadme, router);
574
+ initRedirectCheck();
575
+
576
+ if (typeof window !== "undefined") {
577
+ checkFullContentMode();
578
+ window.addEventListener("resize", checkFullContentMode);
579
+
580
+ // 监听 VitePress 的侧边栏切换事件
581
+ const observer = new MutationObserver(checkFullContentMode);
582
+ const vpLayout = document.querySelector(".Layout");
583
+ if (vpLayout) {
584
+ observer.observe(vpLayout, {
585
+ attributes: true,
586
+ childList: true,
587
+ subtree: true,
588
+ });
589
+ }
590
+ }
591
+ });
592
+
593
+ // 监听路由变化
594
+ watch(
595
+ () => vpData.page.value.relativePath,
596
+ () => {
597
+ updateVscodeNoteDir();
598
+ interceptHomeReadmeLinks(isHomeReadme, router);
599
+ },
600
+ );
601
+
602
+ watch(
603
+ () => route.path,
604
+ () => {
605
+ setTimeout(checkFullContentMode, 100);
606
+ },
607
+ );
608
+ </script>
609
+
610
+ <style>
611
+ @import "../CodeBlockFullscreen/styles.css";
612
+
613
+ #VPSidebarNav > .group {
614
+ display: none;
615
+ }
616
+ </style>
617
+
618
+ <style module src="./Layout.module.scss" scoped></style>