@tnotesjs/core 0.1.21 → 0.1.23

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 (122) hide show
  1. package/README.md +87 -87
  2. package/dist/{chunk-4MO7F7Q4.js → chunk-BSTQOJVE.js} +1 -1
  3. package/dist/{chunk-SQVHJR2Z.js → chunk-O4DCXHOV.js} +0 -3
  4. package/dist/cli/index.js +2 -2
  5. package/dist/index.js +1 -1
  6. package/dist/vitepress/config/index.js +2 -2
  7. package/package.json +3 -4
  8. package/types/config.ts +60 -61
  9. package/types/index.ts +11 -11
  10. package/types/note.ts +33 -33
  11. package/vitepress/assets/icons/icon__check.svg +3 -3
  12. package/vitepress/assets/icons/icon__clipboard.svg +7 -7
  13. package/vitepress/assets/icons/icon__close.svg +1 -1
  14. package/vitepress/assets/icons/icon__collapse.svg +1 -1
  15. package/vitepress/assets/icons/icon__confirm.svg +1 -1
  16. package/vitepress/assets/icons/icon__copy.svg +4 -4
  17. package/vitepress/assets/icons/icon__focus.svg +1 -1
  18. package/vitepress/assets/icons/icon__fold.svg +3 -3
  19. package/vitepress/assets/icons/icon__folder.svg +1 -1
  20. package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
  21. package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
  22. package/vitepress/assets/icons/icon__github.svg +3 -3
  23. package/vitepress/assets/icons/icon__mindmap.svg +1 -1
  24. package/vitepress/assets/icons/icon__next.svg +1 -1
  25. package/vitepress/assets/icons/icon__number_gray.svg +1 -1
  26. package/vitepress/assets/icons/icon__number_purple.svg +1 -1
  27. package/vitepress/assets/icons/icon__prev.svg +1 -1
  28. package/vitepress/assets/icons/icon__restore.svg +1 -1
  29. package/vitepress/assets/icons/icon__rotate.svg +4 -4
  30. package/vitepress/assets/icons/icon__search.svg +1 -1
  31. package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
  32. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
  33. package/vitepress/assets/icons/icon__totop.svg +5 -5
  34. package/vitepress/assets/icons/icon__vscode.svg +5 -5
  35. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
  36. package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
  37. package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
  38. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
  39. package/vitepress/assets/icons/index.ts +39 -39
  40. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
  41. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +369 -369
  42. package/vitepress/components/CodeBlockFullscreen/index.ts +209 -213
  43. package/vitepress/components/CodeBlockFullscreen/styles.css +126 -126
  44. package/vitepress/components/Discussions/Discussions.vue +244 -211
  45. package/vitepress/components/EnWordList/EnWordList.vue +663 -543
  46. package/vitepress/components/EnWordList/RightClickMenu.vue +89 -66
  47. package/vitepress/components/Footprints/Footprints.vue +472 -377
  48. package/vitepress/components/Layout/AboutModal.vue +331 -105
  49. package/vitepress/components/Layout/AboutPanel.vue +484 -270
  50. package/vitepress/components/Layout/ContentCollapse.vue +590 -603
  51. package/vitepress/components/Layout/CustomSidebar.vue +817 -817
  52. package/vitepress/components/Layout/DocBeforeControls.vue +351 -149
  53. package/vitepress/components/Layout/DocFooter.vue +233 -233
  54. package/vitepress/components/Layout/ImagePreview.vue +484 -281
  55. package/vitepress/components/Layout/Layout.vue +744 -621
  56. package/vitepress/components/Layout/NavBarSettingsTrigger.vue +0 -2
  57. package/vitepress/components/Layout/NoteStatus.vue +140 -140
  58. package/vitepress/components/Layout/SidebarItems.vue +1083 -1083
  59. package/vitepress/components/Layout/SidebarNavBefore.vue +170 -171
  60. package/vitepress/components/Layout/SidebarResizeHandle.vue +311 -319
  61. package/vitepress/components/Layout/Swiper.vue +167 -167
  62. package/vitepress/components/Layout/ToggleFullContent.vue +47 -35
  63. package/vitepress/components/Layout/ToggleSidebar.vue +37 -26
  64. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
  65. package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
  66. package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
  67. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
  68. package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
  69. package/vitepress/components/Layout/composables/useSidebarLayout.ts +122 -122
  70. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
  71. package/vitepress/components/Layout/homeReadme.data.ts +124 -124
  72. package/vitepress/components/LoadingPage/LoadingPage.vue +1 -6
  73. package/vitepress/components/MarkMap/MarkMap.vue +564 -405
  74. package/vitepress/components/Mermaid/Mermaid.vue +643 -365
  75. package/vitepress/components/NotesTable/NotesTable.vue +174 -98
  76. package/vitepress/components/NotesTable/README.md +67 -67
  77. package/vitepress/components/Settings/Settings.vue +711 -334
  78. package/vitepress/components/Settings/SettingsDialog.vue +1 -11
  79. package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
  80. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
  81. package/vitepress/components/SidebarCard/SidebarCard.vue +945 -946
  82. package/vitepress/components/Tooltip/Tooltip.vue +70 -70
  83. package/vitepress/components/constants.ts +109 -109
  84. package/vitepress/components/notesConfig.data.ts +73 -73
  85. package/vitepress/components/sidebar.data.ts +59 -59
  86. package/vitepress/components/tnotes-config.data.ts +21 -21
  87. package/vitepress/components/utils.ts +26 -26
  88. package/vitepress/config/index.ts +169 -169
  89. package/vitepress/configs/constants.ts +26 -26
  90. package/vitepress/configs/head.config.ts +25 -25
  91. package/vitepress/configs/index.ts +9 -9
  92. package/vitepress/configs/markdown-it.d.ts +23 -23
  93. package/vitepress/configs/markdown.config.ts +368 -367
  94. package/vitepress/configs/theme.config.ts +108 -108
  95. package/vitepress/plugins/buildProgressPlugin.ts +434 -434
  96. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
  97. package/vitepress/plugins/renameNotePlugin.ts +68 -68
  98. package/vitepress/plugins/sidebarStructurePlugin.ts +260 -260
  99. package/vitepress/plugins/updateConfigPlugin.ts +63 -63
  100. package/vitepress/theme/index.ts +137 -137
  101. package/vitepress/theme/styles/base.scss +66 -64
  102. package/vitepress/theme/styles/components/404.scss +31 -31
  103. package/vitepress/theme/styles/components/collapse.scss +172 -172
  104. package/vitepress/theme/styles/components/markmap.scss +101 -101
  105. package/vitepress/theme/styles/components/swiper.scss +255 -255
  106. package/vitepress/theme/styles/index.scss +25 -25
  107. package/vitepress/theme/styles/layout.scss +78 -78
  108. package/vitepress/theme/styles/utilities.scss +39 -39
  109. package/vitepress/theme/styles/vitepress-override.scss +25 -25
  110. package/vitepress/components/Discussions/Discussions.module.scss +0 -32
  111. package/vitepress/components/EnWordList/EnWordList.module.scss +0 -124
  112. package/vitepress/components/EnWordList/RightClickMenu.module.scss +0 -22
  113. package/vitepress/components/Footprints/Footprints.module.scss +0 -93
  114. package/vitepress/components/Layout/AboutModal.module.scss +0 -233
  115. package/vitepress/components/Layout/ImagePreview.module.scss +0 -201
  116. package/vitepress/components/Layout/Layout.module.scss +0 -661
  117. package/vitepress/components/Layout/ToggleFullContent.module.scss +0 -11
  118. package/vitepress/components/Layout/ToggleSidebar.module.scss +0 -11
  119. package/vitepress/components/MarkMap/MarkMap.module.scss +0 -159
  120. package/vitepress/components/Mermaid/Mermaid.module.scss +0 -275
  121. package/vitepress/components/NotesTable/NotesTable.module.scss +0 -77
  122. package/vitepress/components/Settings/Settings.module.scss +0 -375
@@ -1,26 +1,26 @@
1
- export const formatDate = (timestamp: number): string => {
2
- const date = new Date(timestamp)
3
- const year = date.getFullYear()
4
- const month = String(date.getMonth() + 1).padStart(2, '0')
5
- const day = String(date.getDate()).padStart(2, '0')
6
- const weekDays = ['日', '一', '二', '三', '四', '五', '六']
7
- const weekDay = weekDays[date.getDay()]
8
- const hours = String(date.getHours()).padStart(2, '0')
9
- const minutes = String(date.getMinutes()).padStart(2, '0')
10
- const seconds = String(date.getSeconds()).padStart(2, '0')
11
-
12
- const footprintsDay = getFootprintsDay(timestamp)
13
- // const period = hours < 12 ? '上午' : '下午'
14
- // const formattedHours = hours % 12 || 12
15
-
16
- return `👣 ${footprintsDay} | ${year}年${month}月${day}日 周${weekDay} ${hours}:${minutes}:${seconds}`
17
- // return `${year}-${month}-${day} 周${weekDay} ${period} ${formattedHours}:${minutes}:${seconds}`
18
- }
19
-
20
- export const getFootprintsDay = (timestamp: number = Date.now()): number =>
21
- Math.floor(
22
- (timestamp - new Date(1999, 5, 29).getTime()) / (1000 * 60 * 60 * 24)
23
- ) + 1
24
-
25
- export const scrollToTop = (): void =>
26
- window.scrollTo({ top: 0, behavior: 'smooth' })
1
+ export const formatDate = (timestamp: number): string => {
2
+ const date = new Date(timestamp)
3
+ const year = date.getFullYear()
4
+ const month = String(date.getMonth() + 1).padStart(2, '0')
5
+ const day = String(date.getDate()).padStart(2, '0')
6
+ const weekDays = ['日', '一', '二', '三', '四', '五', '六']
7
+ const weekDay = weekDays[date.getDay()]
8
+ const hours = String(date.getHours()).padStart(2, '0')
9
+ const minutes = String(date.getMinutes()).padStart(2, '0')
10
+ const seconds = String(date.getSeconds()).padStart(2, '0')
11
+
12
+ const footprintsDay = getFootprintsDay(timestamp)
13
+ // const period = hours < 12 ? '上午' : '下午'
14
+ // const formattedHours = hours % 12 || 12
15
+
16
+ return `👣 ${footprintsDay} | ${year}年${month}月${day}日 周${weekDay} ${hours}:${minutes}:${seconds}`
17
+ // return `${year}-${month}-${day} 周${weekDay} ${period} ${formattedHours}:${minutes}:${seconds}`
18
+ }
19
+
20
+ export const getFootprintsDay = (timestamp: number = Date.now()): number =>
21
+ Math.floor(
22
+ (timestamp - new Date(1999, 5, 29).getTime()) / (1000 * 60 * 60 * 24)
23
+ ) + 1
24
+
25
+ export const scrollToTop = (): void =>
26
+ window.scrollTo({ top: 0, behavior: 'smooth' })
@@ -1,169 +1,169 @@
1
- /**
2
- * .vitepress/tnotes/vitepress/config/index.ts
3
- *
4
- * VitePress 站点配置工厂函数
5
- *
6
- * 将所有共享配置封装在 tnotesjs/core 中,外围 config.mts 只需一行调用:
7
- * import { defineNotesConfig } from './tnotes/vitepress/config'
8
- * export default defineNotesConfig()
9
- */
10
- import fs from 'fs'
11
- import path from 'path'
12
- import { defineConfig, type UserConfig } from 'vitepress'
13
-
14
- import {
15
- getIgnoreList,
16
- getGithubPageUrl,
17
- getHeadConfig,
18
- getMarkdownConfig,
19
- getThemeConfig,
20
- } from '../configs'
21
- import { buildProgressPlugin } from '../plugins/buildProgressPlugin'
22
- import { fileWatcherBridgePlugin } from '../plugins/fileWatcherBridgePlugin'
23
- import { getNoteByConfigIdPlugin } from '../plugins/getNoteByConfigIdPlugin'
24
- import { renameNotePlugin } from '../plugins/renameNotePlugin'
25
- import { sidebarStructurePlugin } from '../plugins/sidebarStructurePlugin'
26
- import { updateConfigPlugin } from '../plugins/updateConfigPlugin'
27
-
28
- import type { TNotesConfig } from '../../types'
29
-
30
- /**
31
- * 读取 .tnotes.json 配置文件
32
- */
33
- function loadTNotesConfig(rootPath: string): TNotesConfig {
34
- const configPath = path.resolve(rootPath, '.tnotes.json')
35
- const configContent = fs.readFileSync(configPath, 'utf-8')
36
- return JSON.parse(configContent) as TNotesConfig
37
- }
38
-
39
- /**
40
- * 创建 VitePress 站点配置
41
- *
42
- * @param overrides - 可选的覆盖配置,会与默认配置合并
43
- * @returns VitePress 配置对象
44
- */
45
- export function defineNotesConfig(overrides: UserConfig = {}) {
46
- const rootPath = process.cwd()
47
- const config = loadTNotesConfig(rootPath)
48
- const { repoName } = config
49
-
50
- const IGNORE_LIST = getIgnoreList(config)
51
- const GITHUB_PAGE_URL = getGithubPageUrl(config)
52
-
53
- const {
54
- transformPageData: overrideTransformPageData,
55
- vite: overrideVite,
56
- ...restOverrides
57
- } = overrides
58
-
59
- return defineConfig({
60
- appearance: 'dark',
61
- base: '/' + repoName + '/',
62
- cleanUrls: true,
63
- description: repoName,
64
- head: getHeadConfig(config, GITHUB_PAGE_URL),
65
- ignoreDeadLinks: true,
66
- lang: 'zh-Hans',
67
- lastUpdated: false,
68
- markdown: getMarkdownConfig(),
69
- sitemap: {
70
- hostname: GITHUB_PAGE_URL,
71
- lastmodDateOnly: false,
72
- },
73
- themeConfig: getThemeConfig(config),
74
- title: repoName,
75
- srcExclude: IGNORE_LIST,
76
- vite: {
77
- plugins: [
78
- buildProgressPlugin() as any,
79
- updateConfigPlugin() as any,
80
- renameNotePlugin() as any,
81
- sidebarStructurePlugin() as any,
82
- getNoteByConfigIdPlugin() as any,
83
- fileWatcherBridgePlugin() as any,
84
- ...(overrideVite?.plugins || []),
85
- ],
86
- server: {
87
- // 显式同时监听 IPv4 / IPv6,避免 Node 18+ 在 Windows 下偶发只绑定 ::1
88
- // 导致 Chrome 解析 localhost → 127.0.0.1 时连接被拒、页面一直 pending。
89
- // host: true,
90
- watch: {
91
- ignored: IGNORE_LIST,
92
- },
93
- ...overrideVite?.server,
94
- },
95
- css: {
96
- preprocessorOptions: {
97
- scss: {
98
- silenceDeprecations: ['legacy-js-api'],
99
- },
100
- },
101
- ...overrideVite?.css,
102
- },
103
- build: {
104
- chunkSizeWarningLimit: 1000,
105
- ...overrideVite?.build,
106
- },
107
- define: {
108
- __TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
109
- __TNOTES_AUTHOR__: JSON.stringify(config.author),
110
- __TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
111
- __TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
112
- ...overrideVite?.define,
113
- },
114
- resolve: {
115
- dedupe: ['vue', 'vitepress'],
116
- ...overrideVite?.resolve,
117
- },
118
- optimizeDeps: {
119
- include: [
120
- // VitePress 内部 CJS 依赖 —— 需要 Vite 预构建为 ESM
121
- 'vitepress > @vscode/markdown-it-katex',
122
- 'vitepress > @braintree/sanitize-url',
123
- 'vitepress > dayjs',
124
- 'vitepress > dayjs/plugin/utc',
125
- 'vitepress > dayjs/plugin/localizedFormat',
126
- ],
127
- ...overrideVite?.optimizeDeps,
128
- },
129
- },
130
- transformPageData(pageData, ctx) {
131
- // 为笔记页面注入原始 Markdown 内容(用于一键复制功能)
132
- //
133
- // 这里的 rawContent 会被 VitePress 序列化进 SFC 的
134
- // `<script>export const __pageData = JSON.parse("...")</script>` 块。
135
- // 如果直接写入原文,原文中的 `<script>` / `</script>` 字面量会被两
136
- // 类规则误命中:
137
- // 1. HTML 解析器看到 `</script` 就提前闭合脚本块,触发
138
- // "Invalid end tag"。
139
- // 2. VitePress 内部还会用
140
- // `scriptClientRE = /<script\b[^>]*client\b[^>]*>([^]*?)<\/script>/`
141
- // 在整段 vueSrc 上扫一遍,匹配到原文里的 `<script src="/client.js">`
142
- // 之类开标签后会一路吞到真正的 `</script>`。
143
- //
144
- // 与其针对每条规则各自做转义(耦合 VitePress 内部实现细节),
145
- // 不如直接对原文做 base64 编码:base64 字符集仅 `[A-Za-z0-9+/=]`,
146
- // 不包含 `<` `>`,可彻底规避任何 HTML/正则误匹配。
147
- // 前端消费时使用 `atob` + `TextDecoder('utf-8')` 还原原文。
148
- if (/^notes\/\d{4}/.test(pageData.relativePath)) {
149
- const fullPath = path.resolve(rootPath, pageData.relativePath)
150
- try {
151
- const raw = fs.readFileSync(fullPath, 'utf-8')
152
- pageData.frontmatter.rawContent = Buffer.from(raw, 'utf-8').toString(
153
- 'base64',
154
- )
155
- } catch {
156
- pageData.frontmatter.rawContent = null
157
- }
158
- }
159
- // 执行外部覆盖的 transformPageData(如有)
160
- if (typeof overrideTransformPageData === 'function') {
161
- return overrideTransformPageData(pageData, ctx)
162
- }
163
- },
164
- router: {
165
- prefetchLinks: false,
166
- },
167
- ...restOverrides,
168
- })
169
- }
1
+ /**
2
+ * .vitepress/tnotes/vitepress/config/index.ts
3
+ *
4
+ * VitePress 站点配置工厂函数
5
+ *
6
+ * 将所有共享配置封装在 tnotesjs/core 中,外围 config.mts 只需一行调用:
7
+ * import { defineNotesConfig } from './tnotes/vitepress/config'
8
+ * export default defineNotesConfig()
9
+ */
10
+ import fs from 'fs'
11
+ import path from 'path'
12
+ import { defineConfig, type UserConfig } from 'vitepress'
13
+
14
+ import {
15
+ getIgnoreList,
16
+ getGithubPageUrl,
17
+ getHeadConfig,
18
+ getMarkdownConfig,
19
+ getThemeConfig,
20
+ } from '../configs'
21
+ import { buildProgressPlugin } from '../plugins/buildProgressPlugin'
22
+ import { fileWatcherBridgePlugin } from '../plugins/fileWatcherBridgePlugin'
23
+ import { getNoteByConfigIdPlugin } from '../plugins/getNoteByConfigIdPlugin'
24
+ import { renameNotePlugin } from '../plugins/renameNotePlugin'
25
+ import { sidebarStructurePlugin } from '../plugins/sidebarStructurePlugin'
26
+ import { updateConfigPlugin } from '../plugins/updateConfigPlugin'
27
+
28
+ import type { TNotesConfig } from '../../types'
29
+
30
+ /**
31
+ * 读取 .tnotes.json 配置文件
32
+ */
33
+ function loadTNotesConfig(rootPath: string): TNotesConfig {
34
+ const configPath = path.resolve(rootPath, '.tnotes.json')
35
+ const configContent = fs.readFileSync(configPath, 'utf-8')
36
+ return JSON.parse(configContent) as TNotesConfig
37
+ }
38
+
39
+ /**
40
+ * 创建 VitePress 站点配置
41
+ *
42
+ * @param overrides - 可选的覆盖配置,会与默认配置合并
43
+ * @returns VitePress 配置对象
44
+ */
45
+ export function defineNotesConfig(overrides: UserConfig = {}) {
46
+ const rootPath = process.cwd()
47
+ const config = loadTNotesConfig(rootPath)
48
+ const { repoName } = config
49
+
50
+ const IGNORE_LIST = getIgnoreList(config)
51
+ const GITHUB_PAGE_URL = getGithubPageUrl(config)
52
+
53
+ const {
54
+ transformPageData: overrideTransformPageData,
55
+ vite: overrideVite,
56
+ ...restOverrides
57
+ } = overrides
58
+
59
+ return defineConfig({
60
+ appearance: 'dark',
61
+ base: '/' + repoName + '/',
62
+ cleanUrls: true,
63
+ description: repoName,
64
+ head: getHeadConfig(config, GITHUB_PAGE_URL),
65
+ ignoreDeadLinks: true,
66
+ lang: 'zh-Hans',
67
+ lastUpdated: false,
68
+ markdown: getMarkdownConfig(),
69
+ sitemap: {
70
+ hostname: GITHUB_PAGE_URL,
71
+ lastmodDateOnly: false,
72
+ },
73
+ themeConfig: getThemeConfig(config),
74
+ title: repoName,
75
+ srcExclude: IGNORE_LIST,
76
+ vite: {
77
+ plugins: [
78
+ buildProgressPlugin() as any,
79
+ updateConfigPlugin() as any,
80
+ renameNotePlugin() as any,
81
+ sidebarStructurePlugin() as any,
82
+ getNoteByConfigIdPlugin() as any,
83
+ fileWatcherBridgePlugin() as any,
84
+ ...(overrideVite?.plugins || []),
85
+ ],
86
+ server: {
87
+ // 显式同时监听 IPv4 / IPv6,避免 Node 18+ 在 Windows 下偶发只绑定 ::1
88
+ // 导致 Chrome 解析 localhost → 127.0.0.1 时连接被拒、页面一直 pending。
89
+ // host: true,
90
+ watch: {
91
+ ignored: IGNORE_LIST,
92
+ },
93
+ ...overrideVite?.server,
94
+ },
95
+ css: {
96
+ preprocessorOptions: {
97
+ scss: {
98
+ silenceDeprecations: ['legacy-js-api'],
99
+ },
100
+ },
101
+ ...overrideVite?.css,
102
+ },
103
+ build: {
104
+ chunkSizeWarningLimit: 1000,
105
+ ...overrideVite?.build,
106
+ },
107
+ define: {
108
+ __TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
109
+ __TNOTES_AUTHOR__: JSON.stringify(config.author),
110
+ __TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
111
+ __TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
112
+ ...overrideVite?.define,
113
+ },
114
+ resolve: {
115
+ dedupe: ['vue', 'vitepress'],
116
+ ...overrideVite?.resolve,
117
+ },
118
+ optimizeDeps: {
119
+ include: [
120
+ // VitePress 内部 CJS 依赖 —— 需要 Vite 预构建为 ESM
121
+ 'vitepress > @vscode/markdown-it-katex',
122
+ 'vitepress > @braintree/sanitize-url',
123
+ 'vitepress > dayjs',
124
+ 'vitepress > dayjs/plugin/utc',
125
+ 'vitepress > dayjs/plugin/localizedFormat',
126
+ ],
127
+ ...overrideVite?.optimizeDeps,
128
+ },
129
+ },
130
+ transformPageData(pageData, ctx) {
131
+ // 为笔记页面注入原始 Markdown 内容(用于一键复制功能)
132
+ //
133
+ // 这里的 rawContent 会被 VitePress 序列化进 SFC 的
134
+ // `<script>export const __pageData = JSON.parse("...")</script>` 块。
135
+ // 如果直接写入原文,原文中的 `<script>` / `</script>` 字面量会被两
136
+ // 类规则误命中:
137
+ // 1. HTML 解析器看到 `</script` 就提前闭合脚本块,触发
138
+ // "Invalid end tag"。
139
+ // 2. VitePress 内部还会用
140
+ // `scriptClientRE = /<script\b[^>]*client\b[^>]*>([^]*?)<\/script>/`
141
+ // 在整段 vueSrc 上扫一遍,匹配到原文里的 `<script src="/client.js">`
142
+ // 之类开标签后会一路吞到真正的 `</script>`。
143
+ //
144
+ // 与其针对每条规则各自做转义(耦合 VitePress 内部实现细节),
145
+ // 不如直接对原文做 base64 编码:base64 字符集仅 `[A-Za-z0-9+/=]`,
146
+ // 不包含 `<` `>`,可彻底规避任何 HTML/正则误匹配。
147
+ // 前端消费时使用 `atob` + `TextDecoder('utf-8')` 还原原文。
148
+ if (/^notes\/\d{4}/.test(pageData.relativePath)) {
149
+ const fullPath = path.resolve(rootPath, pageData.relativePath)
150
+ try {
151
+ const raw = fs.readFileSync(fullPath, 'utf-8')
152
+ pageData.frontmatter.rawContent = Buffer.from(raw, 'utf-8').toString(
153
+ 'base64',
154
+ )
155
+ } catch {
156
+ pageData.frontmatter.rawContent = null
157
+ }
158
+ }
159
+ // 执行外部覆盖的 transformPageData(如有)
160
+ if (typeof overrideTransformPageData === 'function') {
161
+ return overrideTransformPageData(pageData, ctx)
162
+ }
163
+ },
164
+ router: {
165
+ prefetchLinks: false,
166
+ },
167
+ ...restOverrides,
168
+ })
169
+ }
@@ -1,26 +1,26 @@
1
- /**
2
- * .vitepress/config/constants.ts
3
- *
4
- * 常量配置 - 从运行时配置派生,不再硬编码相对路径 import
5
- */
6
- import type { TNotesConfig } from '../../types'
7
-
8
- /**
9
- * 获取忽略的文件和目录列表
10
- */
11
- export function getIgnoreList(config: TNotesConfig): string[] {
12
- return [...config.ignore_dirs.map((dir: string) => `**/${dir}/**`)]
13
- }
14
-
15
- /**
16
- * 获取 GitHub Pages URL
17
- */
18
- export function getGithubPageUrl(config: TNotesConfig): string {
19
- return (
20
- 'https://' +
21
- config.author.toLowerCase() +
22
- '.github.io/' +
23
- config.repoName +
24
- '/'
25
- )
26
- }
1
+ /**
2
+ * .vitepress/config/constants.ts
3
+ *
4
+ * 常量配置 - 从运行时配置派生,不再硬编码相对路径 import
5
+ */
6
+ import type { TNotesConfig } from '../../types'
7
+
8
+ /**
9
+ * 获取忽略的文件和目录列表
10
+ */
11
+ export function getIgnoreList(config: TNotesConfig): string[] {
12
+ return [...config.ignore_dirs.map((dir: string) => `**/${dir}/**`)]
13
+ }
14
+
15
+ /**
16
+ * 获取 GitHub Pages URL
17
+ */
18
+ export function getGithubPageUrl(config: TNotesConfig): string {
19
+ return (
20
+ 'https://' +
21
+ config.author.toLowerCase() +
22
+ '.github.io/' +
23
+ config.repoName +
24
+ '/'
25
+ )
26
+ }
@@ -1,26 +1,26 @@
1
- /**
2
- * .vitepress/config/head.config.ts
3
- *
4
- * HTML head 标签配置
5
- */
1
+ /**
2
+ * .vitepress/config/head.config.ts
3
+ *
4
+ * HTML head 标签配置
5
+ */
6
6
  import { HeadConfig } from 'vitepress'
7
-
8
- import type { TNotesConfig } from '../../types'
9
-
10
- export function getHeadConfig(config: TNotesConfig, githubPageUrl: string): HeadConfig[] {
11
- const head: HeadConfig[] = [
12
- [
13
- 'meta',
14
- {
15
- name: 'keywords',
16
- content: config.keywords.join(', '),
17
- },
18
- ],
19
- ['meta', { name: 'author', content: config.author }],
20
- ['link', { rel: 'canonical', href: githubPageUrl }],
21
- ['link', { rel: 'icon', href: githubPageUrl + 'favicon.ico' }],
22
- ['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
23
- ]
24
-
25
- return head
26
- }
7
+
8
+ import type { TNotesConfig } from '../../types'
9
+
10
+ export function getHeadConfig(config: TNotesConfig, githubPageUrl: string): HeadConfig[] {
11
+ const head: HeadConfig[] = [
12
+ [
13
+ 'meta',
14
+ {
15
+ name: 'keywords',
16
+ content: config.keywords.join(', '),
17
+ },
18
+ ],
19
+ ['meta', { name: 'author', content: config.author }],
20
+ ['link', { rel: 'canonical', href: githubPageUrl }],
21
+ ['link', { rel: 'icon', href: githubPageUrl + 'favicon.ico' }],
22
+ ['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
23
+ ]
24
+
25
+ return head
26
+ }
@@ -1,9 +1,9 @@
1
- /**
2
- * .vitepress/config/_index.ts
3
- *
4
- * 配置模块统一导出
5
- */
6
- export { getIgnoreList, getGithubPageUrl } from './constants'
7
- export { getHeadConfig } from './head.config'
8
- export { getMarkdownConfig } from './markdown.config'
9
- export { getThemeConfig } from './theme.config'
1
+ /**
2
+ * .vitepress/config/_index.ts
3
+ *
4
+ * 配置模块统一导出
5
+ */
6
+ export { getIgnoreList, getGithubPageUrl } from './constants'
7
+ export { getHeadConfig } from './head.config'
8
+ export { getMarkdownConfig } from './markdown.config'
9
+ export { getThemeConfig } from './theme.config'
@@ -1,26 +1,26 @@
1
- /**
2
- * .vitepress/config/markdown-it.d.ts
3
- *
4
- * 第三方库类型声明
5
- */
6
-
7
- declare module 'markdown-it-container' {
1
+ /**
2
+ * .vitepress/config/markdown-it.d.ts
3
+ *
4
+ * 第三方库类型声明
5
+ */
6
+
7
+ declare module 'markdown-it-container' {
8
8
  import { PluginWithOptions } from 'markdown-it'
9
-
10
- const markdownItContainer: PluginWithOptions<any>
11
- export default markdownItContainer
12
- }
13
-
14
- declare module 'markdown-it-link-attributes' {
9
+
10
+ const markdownItContainer: PluginWithOptions<any>
11
+ export default markdownItContainer
12
+ }
13
+
14
+ declare module 'markdown-it-link-attributes' {
15
15
  import { PluginWithOptions } from 'markdown-it'
16
-
17
- const markdownItLinkAttributes: PluginWithOptions<any>
18
- export default markdownItLinkAttributes
19
- }
20
-
21
- declare module 'markdown-it-task-lists' {
16
+
17
+ const markdownItLinkAttributes: PluginWithOptions<any>
18
+ export default markdownItLinkAttributes
19
+ }
20
+
21
+ declare module 'markdown-it-task-lists' {
22
22
  import { PluginWithOptions } from 'markdown-it'
23
-
24
- const markdownItTaskLists: PluginWithOptions<any>
25
- export default markdownItTaskLists
26
- }
23
+
24
+ const markdownItTaskLists: PluginWithOptions<any>
25
+ export default markdownItTaskLists
26
+ }