@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,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,167 +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 { updateConfigPlugin } from '../plugins/updateConfigPlugin'
26
-
27
- import type { TNotesConfig } from '../../types'
28
-
29
- /**
30
- * 读取 .tnotes.json 配置文件
31
- */
32
- function loadTNotesConfig(rootPath: string): TNotesConfig {
33
- const configPath = path.resolve(rootPath, '.tnotes.json')
34
- const configContent = fs.readFileSync(configPath, 'utf-8')
35
- return JSON.parse(configContent) as TNotesConfig
36
- }
37
-
38
- /**
39
- * 创建 VitePress 站点配置
40
- *
41
- * @param overrides - 可选的覆盖配置,会与默认配置合并
42
- * @returns VitePress 配置对象
43
- */
44
- export function defineNotesConfig(overrides: UserConfig = {}) {
45
- const rootPath = process.cwd()
46
- const config = loadTNotesConfig(rootPath)
47
- const { repoName } = config
48
-
49
- const IGNORE_LIST = getIgnoreList(config)
50
- const GITHUB_PAGE_URL = getGithubPageUrl(config)
51
-
52
- const {
53
- transformPageData: overrideTransformPageData,
54
- vite: overrideVite,
55
- ...restOverrides
56
- } = overrides
57
-
58
- return defineConfig({
59
- appearance: 'dark',
60
- base: '/' + repoName + '/',
61
- cleanUrls: true,
62
- description: repoName,
63
- head: getHeadConfig(config, GITHUB_PAGE_URL),
64
- ignoreDeadLinks: true,
65
- lang: 'zh-Hans',
66
- lastUpdated: false,
67
- markdown: getMarkdownConfig(),
68
- sitemap: {
69
- hostname: GITHUB_PAGE_URL,
70
- lastmodDateOnly: false,
71
- },
72
- themeConfig: getThemeConfig(config),
73
- title: repoName,
74
- srcExclude: IGNORE_LIST,
75
- vite: {
76
- plugins: [
77
- buildProgressPlugin() as any,
78
- updateConfigPlugin() as any,
79
- renameNotePlugin() as any,
80
- getNoteByConfigIdPlugin() as any,
81
- fileWatcherBridgePlugin() as any,
82
- ...(overrideVite?.plugins || []),
83
- ],
84
- server: {
85
- // 显式同时监听 IPv4 / IPv6,避免 Node 18+ 在 Windows 下偶发只绑定 ::1
86
- // 导致 Chrome 解析 localhost → 127.0.0.1 时连接被拒、页面一直 pending。
87
- // host: true,
88
- watch: {
89
- ignored: IGNORE_LIST,
90
- },
91
- ...overrideVite?.server,
92
- },
93
- css: {
94
- preprocessorOptions: {
95
- scss: {
96
- silenceDeprecations: ['legacy-js-api'],
97
- },
98
- },
99
- ...overrideVite?.css,
100
- },
101
- build: {
102
- chunkSizeWarningLimit: 1000,
103
- ...overrideVite?.build,
104
- },
105
- define: {
106
- __TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
107
- __TNOTES_AUTHOR__: JSON.stringify(config.author),
108
- __TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
109
- __TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
110
- ...overrideVite?.define,
111
- },
112
- resolve: {
113
- dedupe: ['vue', 'vitepress'],
114
- ...overrideVite?.resolve,
115
- },
116
- optimizeDeps: {
117
- include: [
118
- // VitePress 内部 CJS 依赖 —— 需要 Vite 预构建为 ESM
119
- 'vitepress > @vscode/markdown-it-katex',
120
- 'vitepress > @braintree/sanitize-url',
121
- 'vitepress > dayjs',
122
- 'vitepress > dayjs/plugin/utc',
123
- 'vitepress > dayjs/plugin/localizedFormat',
124
- ],
125
- ...overrideVite?.optimizeDeps,
126
- },
127
- },
128
- transformPageData(pageData, ctx) {
129
- // 为笔记页面注入原始 Markdown 内容(用于一键复制功能)
130
- //
131
- // 这里的 rawContent 会被 VitePress 序列化进 SFC 的
132
- // `<script>export const __pageData = JSON.parse("...")</script>` 块。
133
- // 如果直接写入原文,原文中的 `<script>` / `</script>` 字面量会被两
134
- // 类规则误命中:
135
- // 1. HTML 解析器看到 `</script` 就提前闭合脚本块,触发
136
- // "Invalid end tag"。
137
- // 2. VitePress 内部还会用
138
- // `scriptClientRE = /<script\b[^>]*client\b[^>]*>([^]*?)<\/script>/`
139
- // 在整段 vueSrc 上扫一遍,匹配到原文里的 `<script src="/client.js">`
140
- // 之类开标签后会一路吞到真正的 `</script>`。
141
- //
142
- // 与其针对每条规则各自做转义(耦合 VitePress 内部实现细节),
143
- // 不如直接对原文做 base64 编码:base64 字符集仅 `[A-Za-z0-9+/=]`,
144
- // 不包含 `<` `>`,可彻底规避任何 HTML/正则误匹配。
145
- // 前端消费时使用 `atob` + `TextDecoder('utf-8')` 还原原文。
146
- if (/^notes\/\d{4}/.test(pageData.relativePath)) {
147
- const fullPath = path.resolve(rootPath, pageData.relativePath)
148
- try {
149
- const raw = fs.readFileSync(fullPath, 'utf-8')
150
- pageData.frontmatter.rawContent = Buffer.from(raw, 'utf-8').toString(
151
- 'base64',
152
- )
153
- } catch {
154
- pageData.frontmatter.rawContent = null
155
- }
156
- }
157
- // 执行外部覆盖的 transformPageData(如有)
158
- if (typeof overrideTransformPageData === 'function') {
159
- return overrideTransformPageData(pageData, ctx)
160
- }
161
- },
162
- router: {
163
- prefetchLinks: false,
164
- },
165
- ...restOverrides,
166
- })
167
- }
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
+ }