@tnotesjs/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of @tnotesjs/core might be problematic. Click here for more details.

Files changed (117) hide show
  1. package/README.md +105 -0
  2. package/dist/chunk-K3X5OP3N.js +1532 -0
  3. package/dist/cli/index.d.ts +2 -0
  4. package/dist/cli/index.js +4199 -0
  5. package/dist/index.d.ts +138 -0
  6. package/dist/index.js +9 -0
  7. package/package.json +74 -0
  8. package/types/config.ts +61 -0
  9. package/types/index.ts +11 -0
  10. package/types/note.ts +33 -0
  11. package/vitepress/assets/icons/icon__check.svg +3 -0
  12. package/vitepress/assets/icons/icon__clipboard.svg +8 -0
  13. package/vitepress/assets/icons/icon__close.svg +1 -0
  14. package/vitepress/assets/icons/icon__collapse.svg +1 -0
  15. package/vitepress/assets/icons/icon__confirm.svg +1 -0
  16. package/vitepress/assets/icons/icon__copy.svg +4 -0
  17. package/vitepress/assets/icons/icon__focus.svg +1 -0
  18. package/vitepress/assets/icons/icon__fold.svg +3 -0
  19. package/vitepress/assets/icons/icon__folder.svg +1 -0
  20. package/vitepress/assets/icons/icon__fullscreen.svg +1 -0
  21. package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -0
  22. package/vitepress/assets/icons/icon__github.svg +4 -0
  23. package/vitepress/assets/icons/icon__mindmap.svg +1 -0
  24. package/vitepress/assets/icons/icon__next.svg +1 -0
  25. package/vitepress/assets/icons/icon__number_gray.svg +1 -0
  26. package/vitepress/assets/icons/icon__number_purple.svg +1 -0
  27. package/vitepress/assets/icons/icon__prev.svg +1 -0
  28. package/vitepress/assets/icons/icon__restore.svg +1 -0
  29. package/vitepress/assets/icons/icon__rotate.svg +4 -0
  30. package/vitepress/assets/icons/icon__search.svg +1 -0
  31. package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -0
  32. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -0
  33. package/vitepress/assets/icons/icon__totop.svg +6 -0
  34. package/vitepress/assets/icons/icon__vscode.svg +6 -0
  35. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -0
  36. package/vitepress/assets/icons/icon__zoom_in.svg +1 -0
  37. package/vitepress/assets/icons/icon__zoom_out.svg +1 -0
  38. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -0
  39. package/vitepress/assets/icons/index.ts +38 -0
  40. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -0
  41. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -0
  42. package/vitepress/components/CodeBlockFullscreen/index.ts +115 -0
  43. package/vitepress/components/CodeBlockFullscreen/styles.css +64 -0
  44. package/vitepress/components/Discussions/Discussions.module.scss +32 -0
  45. package/vitepress/components/Discussions/Discussions.vue +211 -0
  46. package/vitepress/components/EnWordList/EnWordList.module.scss +124 -0
  47. package/vitepress/components/EnWordList/EnWordList.vue +543 -0
  48. package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -0
  49. package/vitepress/components/EnWordList/RightClickMenu.vue +66 -0
  50. package/vitepress/components/Footprints/Footprints.module.scss +93 -0
  51. package/vitepress/components/Footprints/Footprints.vue +377 -0
  52. package/vitepress/components/Layout/AboutModal.module.scss +233 -0
  53. package/vitepress/components/Layout/AboutModal.vue +105 -0
  54. package/vitepress/components/Layout/AboutPanel.vue +266 -0
  55. package/vitepress/components/Layout/ContentCollapse.vue +603 -0
  56. package/vitepress/components/Layout/CustomSidebar.vue +605 -0
  57. package/vitepress/components/Layout/DocBeforeControls.vue +139 -0
  58. package/vitepress/components/Layout/DocFooter.vue +225 -0
  59. package/vitepress/components/Layout/ImagePreview.module.scss +201 -0
  60. package/vitepress/components/Layout/ImagePreview.vue +281 -0
  61. package/vitepress/components/Layout/Layout.module.scss +661 -0
  62. package/vitepress/components/Layout/Layout.vue +542 -0
  63. package/vitepress/components/Layout/NoteStatus.vue +140 -0
  64. package/vitepress/components/Layout/SidebarItems.vue +263 -0
  65. package/vitepress/components/Layout/SidebarNavBefore.vue +92 -0
  66. package/vitepress/components/Layout/Swiper.vue +167 -0
  67. package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -0
  68. package/vitepress/components/Layout/ToggleFullContent.vue +34 -0
  69. package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -0
  70. package/vitepress/components/Layout/ToggleSidebar.vue +35 -0
  71. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -0
  72. package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -0
  73. package/vitepress/components/Layout/composables/useNoteSave.ts +173 -0
  74. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -0
  75. package/vitepress/components/Layout/composables/useRedirect.ts +110 -0
  76. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -0
  77. package/vitepress/components/Layout/homeReadme.data.ts +124 -0
  78. package/vitepress/components/LoadingPage/LoadingPage.vue +192 -0
  79. package/vitepress/components/MarkMap/MarkMap.module.scss +159 -0
  80. package/vitepress/components/MarkMap/MarkMap.vue +404 -0
  81. package/vitepress/components/Mermaid/Mermaid.module.scss +275 -0
  82. package/vitepress/components/Mermaid/Mermaid.vue +364 -0
  83. package/vitepress/components/NotesTable/NotesTable.module.scss +77 -0
  84. package/vitepress/components/NotesTable/NotesTable.vue +98 -0
  85. package/vitepress/components/NotesTable/README.md +67 -0
  86. package/vitepress/components/Settings/Settings.module.scss +433 -0
  87. package/vitepress/components/Settings/Settings.vue +306 -0
  88. package/vitepress/components/SidebarCard/MindMapView.vue +483 -0
  89. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -0
  90. package/vitepress/components/SidebarCard/SidebarCard.vue +948 -0
  91. package/vitepress/components/Tooltip/Tooltip.vue +70 -0
  92. package/vitepress/components/constants.ts +91 -0
  93. package/vitepress/components/notesConfig.data.ts +73 -0
  94. package/vitepress/components/sidebar.data.ts +59 -0
  95. package/vitepress/components/tnotes-config.data.ts +21 -0
  96. package/vitepress/components/utils.ts +26 -0
  97. package/vitepress/config/index.ts +126 -0
  98. package/vitepress/configs/constants.ts +26 -0
  99. package/vitepress/configs/head.config.ts +25 -0
  100. package/vitepress/configs/index.ts +9 -0
  101. package/vitepress/configs/markdown-it.d.ts +23 -0
  102. package/vitepress/configs/markdown.config.ts +366 -0
  103. package/vitepress/configs/theme.config.ts +108 -0
  104. package/vitepress/plugins/buildProgressPlugin.ts +390 -0
  105. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -0
  106. package/vitepress/plugins/renameNotePlugin.ts +60 -0
  107. package/vitepress/plugins/updateConfigPlugin.ts +63 -0
  108. package/vitepress/theme/index.ts +95 -0
  109. package/vitepress/theme/styles/base.scss +50 -0
  110. package/vitepress/theme/styles/components/404.scss +31 -0
  111. package/vitepress/theme/styles/components/collapse.scss +175 -0
  112. package/vitepress/theme/styles/components/markmap.scss +101 -0
  113. package/vitepress/theme/styles/components/swiper.scss +255 -0
  114. package/vitepress/theme/styles/index.scss +25 -0
  115. package/vitepress/theme/styles/layout.scss +62 -0
  116. package/vitepress/theme/styles/utilities.scss +39 -0
  117. package/vitepress/theme/styles/vitepress-override.scss +25 -0
@@ -0,0 +1,70 @@
1
+ <template>
2
+ <span
3
+ class="tooltip-wrapper"
4
+ @mouseenter="showTooltip = true"
5
+ @mouseleave="showTooltip = false"
6
+ >
7
+ <slot></slot>
8
+ <span v-if="showTooltip" class="tooltip">{{ text }}</span>
9
+ </span>
10
+ </template>
11
+
12
+ <script setup lang="ts">
13
+ import { ref } from 'vue'
14
+
15
+ defineProps({
16
+ text: {
17
+ type: String,
18
+ required: true,
19
+ },
20
+ })
21
+
22
+ const showTooltip = ref(false)
23
+ </script>
24
+
25
+ <style scoped>
26
+ .tooltip-wrapper {
27
+ position: relative;
28
+ display: inline-block;
29
+ }
30
+
31
+ .tooltip {
32
+ position: absolute;
33
+ bottom: 100%;
34
+ left: 50%;
35
+ transform: translateX(-50%) translateY(-8px);
36
+ background-color: var(--vp-c-bg-elv);
37
+ color: var(--vp-c-text-1);
38
+ padding: 6px 12px;
39
+ border-radius: 6px;
40
+ font-size: 14px;
41
+ font-weight: 500;
42
+ white-space: nowrap;
43
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
44
+ border: 1px solid var(--vp-c-divider);
45
+ z-index: 100;
46
+ animation: tooltipFadeIn 0.15s ease-out;
47
+ pointer-events: none;
48
+ }
49
+
50
+ .tooltip::after {
51
+ content: '';
52
+ position: absolute;
53
+ top: 100%;
54
+ left: 50%;
55
+ transform: translateX(-50%);
56
+ border: 6px solid transparent;
57
+ border-top-color: var(--vp-c-bg-elv);
58
+ }
59
+
60
+ @keyframes tooltipFadeIn {
61
+ from {
62
+ opacity: 0;
63
+ transform: translateX(-50%) translateY(-4px);
64
+ }
65
+ to {
66
+ opacity: 1;
67
+ transform: translateX(-50%) translateY(-8px);
68
+ }
69
+ }
70
+ </style>
@@ -0,0 +1,91 @@
1
+ /**
2
+ * 以下常量由 defineNotesConfig() 通过 vite.define 注入
3
+ * 见 vitepress/config/index.ts 中的 define 配置
4
+ */
5
+ declare const __TNOTES_REPO_NAME__: string
6
+ declare const __TNOTES_AUTHOR__: string
7
+ declare const __TNOTES_IGNORE_DIRS__: string[]
8
+ declare const __TNOTES_ROOT_ITEM__: any
9
+
10
+ /**
11
+ * 笔记仓库名儿
12
+ */
13
+ export const REPO_NAME: string = __TNOTES_REPO_NAME__
14
+
15
+ /**
16
+ * 笔记仓库作者
17
+ */
18
+ export const AUTHOR: string = __TNOTES_AUTHOR__
19
+
20
+ /**
21
+ * notes 目录下需要忽略的笔记目录
22
+ * @example
23
+ * [".vscode", "0000", "assets", "node_modules"]
24
+ */
25
+ export const IGNORE_DIRS: string[] = __TNOTES_IGNORE_DIRS__
26
+
27
+ /**
28
+ * 根知识库配置项
29
+ */
30
+ export const ROOT_ITEM = __TNOTES_ROOT_ITEM__
31
+
32
+ /**
33
+ * 存储本地笔记文件夹所在位置的 key
34
+ */
35
+ export const NOTES_DIR_KEY: string = 'NOTES_DIR_KEY__' + REPO_NAME
36
+
37
+ /**
38
+ * 用户选择的视图
39
+ */
40
+ export const NOTES_VIEW_KEY: string = 'NOTES_VIEW_KEY__' + REPO_NAME
41
+
42
+ /**
43
+ * 全局配置 EnWordList.vue 组件是否自动展示词汇卡片
44
+ */
45
+ export const EN_WORD_LIST_COMP_IS_AUTO_SHOW_CARD: string =
46
+ 'EN_WORD_LIST_COMP_IS_AUTO_SHOW_CARD__' + REPO_NAME
47
+
48
+ /**
49
+ * MarkMap 默认主题配置
50
+ */
51
+ export const MARKMAP_THEME_KEY: string = 'MARKMAP_THEME_KEY__' + REPO_NAME
52
+
53
+ /**
54
+ * MarkMap 默认展开层级配置
55
+ */
56
+ export const MARKMAP_EXPAND_LEVEL_KEY: string =
57
+ 'MARKMAP_EXPAND_LEVEL_KEY__' + REPO_NAME
58
+
59
+ /**
60
+ * 侧边栏是否显示笔记编号配置
61
+ */
62
+ export const SIDEBAR_SHOW_NOTE_ID_KEY: string =
63
+ 'SIDEBAR_SHOW_NOTE_ID_KEY__' + REPO_NAME
64
+
65
+ /**
66
+ * 侧边栏最大解析层级配置
67
+ * 默认值为 3,表示支持 3 层嵌套(组 → 子组 → 笔记)
68
+ */
69
+ export const SIDEBAR_MAX_DEPTH_KEY: string =
70
+ 'SIDEBAR_MAX_DEPTH_KEY__' + REPO_NAME
71
+
72
+ /**
73
+ * VitePress HOME README 文件名
74
+ * 该文件内容基于 HOME README 而生成,作为 github pages 中的 README 文件,主要用于展示笔记的目录结构。
75
+ */
76
+ export const TOC: string = 'TOC'
77
+ export const TOC_MD: string = TOC + '.md'
78
+
79
+ /**
80
+ * 英语单词仓库基地址
81
+ * https://github.com/tnotesjs/en-words/blob/main/{word}.md
82
+ */
83
+ export const EN_WORDS_REPO_BASE_URL: string =
84
+ 'https://github.com/tnotesjs/TNotes.en-words/blob/main/'
85
+
86
+ /**
87
+ * 英语单词仓库 raw 地址
88
+ * https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/{word}.md
89
+ */
90
+ export const EN_WORDS_REPO_BASE_RAW_URL: string =
91
+ 'https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/'
@@ -0,0 +1,73 @@
1
+ // .vitepress/components/notesConfig.data.ts
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+
5
+ const rootPath = process.cwd()
6
+
7
+ /**
8
+ * 从配置文件读取忽略目录列表
9
+ * 注意:data loader 运行在 Node.js 上下文,不经过 vite.define,
10
+ * 因此需要直接读取配置文件而非从 constants.ts 导入。
11
+ */
12
+ function getIgnoreDirs(): string[] {
13
+ try {
14
+ const configPath = path.resolve(process.cwd(), '.tnotes.json')
15
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'))
16
+ return config.ignore_dirs || []
17
+ } catch {
18
+ return []
19
+ }
20
+ }
21
+
22
+ interface NoteConfig {
23
+ [key: string]: any
24
+ redirect?: string
25
+ }
26
+
27
+ export default {
28
+ // 监听笔记目录下第一级的 .tnotes.json 文件变化
29
+ watch: [
30
+ path.resolve(rootPath, 'notes').replace(/\\/g, '/') + '/*/.tnotes.json',
31
+ ],
32
+ load(watchedFiles: string[]): Record<string, NoteConfig> {
33
+ // console.log('watchedFiles', watchedFiles)
34
+
35
+ const IGNORE_DIRS = getIgnoreDirs()
36
+
37
+ // 初始化一个空对象,用于存储所有笔记的配置数据(以笔记索引为键)
38
+ const allNotesConfig: Record<string, NoteConfig> = {}
39
+
40
+ // 遍历所有监听到的 .tnotes.json 文件
41
+ watchedFiles.forEach((filePath) => {
42
+ try {
43
+ // 检查目录是否在忽略列表中
44
+ const dirName = filePath.split('/').slice(-2, -1)[0] // 提取目录名称
45
+ if (IGNORE_DIRS.includes(dirName)) {
46
+ console.log(`Skipping ignored directory: ${dirName}`)
47
+ return // 跳过忽略的目录
48
+ }
49
+
50
+ // 读取文件内容
51
+ const fileContent = fs.readFileSync(filePath, 'utf-8')
52
+ const configData = JSON.parse(fileContent) as NoteConfig
53
+
54
+ // 提取笔记索引(文件路径中前 4 个数字)
55
+ const noteIndexMatch = filePath.match(/notes\/(\d{4})\./)
56
+ if (noteIndexMatch) {
57
+ const noteIndex = noteIndexMatch[1] // 获取笔记索引
58
+ const redirect = filePath.replace(/\.tnotes\.json$/, 'README')
59
+ allNotesConfig[noteIndex] = {
60
+ ...configData,
61
+ redirect,
62
+ } // 将配置数据存入对象
63
+ }
64
+ } catch (error) {
65
+ console.error(`Failed to load config file: ${filePath}`, error)
66
+ }
67
+ })
68
+
69
+ // console.log('All notes config loaded:', allNotesConfig)
70
+
71
+ return allNotesConfig
72
+ },
73
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * .vitepress/tnotes/vitepress/components/sidebar.data.ts
3
+ */
4
+
5
+ import fs from 'node:fs'
6
+ import path from 'node:path'
7
+
8
+ const rootPath = process.cwd()
9
+
10
+ /**
11
+ * VitePress Data Loader for Sidebar
12
+ * 通过监听 sidebar.json 文件变化,使用 HMR 热更新
13
+ */
14
+
15
+ interface SidebarItem {
16
+ text: string
17
+ link: string
18
+ }
19
+
20
+ interface SidebarGroup {
21
+ text: string
22
+ collapsed?: boolean
23
+ items: SidebarItem[]
24
+ }
25
+
26
+ interface SidebarConfig {
27
+ '/notes/': SidebarGroup[]
28
+ }
29
+
30
+ export default {
31
+ // 监听 sidebar.json 文件变化
32
+ watch: [path.resolve(rootPath, 'sidebar.json')],
33
+
34
+ load(watchedFiles: string[]): SidebarConfig {
35
+ const sidebarFilePath = watchedFiles[0]
36
+
37
+ try {
38
+ // 读取 sidebar.json 文件
39
+ const fileContent = fs.readFileSync(sidebarFilePath, 'utf-8')
40
+ const sidebarArray = JSON.parse(fileContent) as SidebarGroup[]
41
+
42
+ // 期望的格式是 { '/notes/': [...] }
43
+ const sidebarData: SidebarConfig = {
44
+ '/notes/': sidebarArray,
45
+ }
46
+
47
+ console.log('[sidebar.data.ts] Sidebar loaded,')
48
+
49
+ return sidebarData
50
+ } catch (error) {
51
+ console.error('❌ [sidebar.data.ts] Failed to load sidebar.json:', error)
52
+
53
+ // 返回空的 sidebar 配置作为后备
54
+ return {
55
+ '/notes/': [],
56
+ }
57
+ }
58
+ },
59
+ }
@@ -0,0 +1,21 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ const rootPath = process.cwd()
5
+
6
+ export interface TNotesConfig {
7
+ sidebarShowNoteId: boolean
8
+ author?: string
9
+ repoName?: string
10
+ [key: string]: any
11
+ }
12
+
13
+ export default {
14
+ watch: [path.resolve(rootPath, '.tnotes.json')],
15
+ load(watchedFiles: string[]): TNotesConfig {
16
+ console.log('[tnotes-config.data.ts] Config loaded')
17
+ const fileContent = fs.readFileSync(watchedFiles[0], 'utf-8')
18
+ const config = JSON.parse(fileContent) as TNotesConfig
19
+ return config
20
+ },
21
+ }
@@ -0,0 +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' })
@@ -0,0 +1,126 @@
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
+ import type { TNotesConfig } from '../../types'
14
+ import {
15
+ getIgnoreList,
16
+ getGithubPageUrl,
17
+ getHeadConfig,
18
+ getMarkdownConfig,
19
+ getThemeConfig,
20
+ } from '../configs'
21
+ import { updateConfigPlugin } from '../plugins/updateConfigPlugin'
22
+ import { renameNotePlugin } from '../plugins/renameNotePlugin'
23
+ import { getNoteByConfigIdPlugin } from '../plugins/getNoteByConfigIdPlugin'
24
+ import { buildProgressPlugin } from '../plugins/buildProgressPlugin'
25
+
26
+ /**
27
+ * 读取 .tnotes.json 配置文件
28
+ */
29
+ function loadTNotesConfig(rootPath: string): TNotesConfig {
30
+ const configPath = path.resolve(rootPath, '.tnotes.json')
31
+ const configContent = fs.readFileSync(configPath, 'utf-8')
32
+ return JSON.parse(configContent) as TNotesConfig
33
+ }
34
+
35
+ /**
36
+ * 创建 VitePress 站点配置
37
+ *
38
+ * @param overrides - 可选的覆盖配置,会与默认配置合并
39
+ * @returns VitePress 配置对象
40
+ */
41
+ export function defineNotesConfig(overrides: UserConfig = {}) {
42
+ const rootPath = process.cwd()
43
+ const config = loadTNotesConfig(rootPath)
44
+ const { repoName } = config
45
+
46
+ const IGNORE_LIST = getIgnoreList(config)
47
+ const GITHUB_PAGE_URL = getGithubPageUrl(config)
48
+
49
+ const {
50
+ transformPageData: overrideTransformPageData,
51
+ vite: overrideVite,
52
+ ...restOverrides
53
+ } = overrides
54
+
55
+ return defineConfig({
56
+ appearance: 'dark',
57
+ base: '/' + repoName + '/',
58
+ cleanUrls: true,
59
+ description: repoName,
60
+ head: getHeadConfig(config, GITHUB_PAGE_URL),
61
+ ignoreDeadLinks: true,
62
+ lang: 'zh-Hans',
63
+ lastUpdated: false,
64
+ markdown: getMarkdownConfig(),
65
+ sitemap: {
66
+ hostname: GITHUB_PAGE_URL,
67
+ lastmodDateOnly: false,
68
+ },
69
+ themeConfig: getThemeConfig(config),
70
+ title: repoName,
71
+ srcExclude: IGNORE_LIST,
72
+ vite: {
73
+ plugins: [
74
+ buildProgressPlugin() as any,
75
+ updateConfigPlugin() as any,
76
+ renameNotePlugin() as any,
77
+ getNoteByConfigIdPlugin() as any,
78
+ ...(overrideVite?.plugins || []),
79
+ ],
80
+ server: {
81
+ watch: {
82
+ ignored: IGNORE_LIST,
83
+ },
84
+ ...overrideVite?.server,
85
+ },
86
+ css: {
87
+ preprocessorOptions: {
88
+ scss: {
89
+ silenceDeprecations: ['legacy-js-api'],
90
+ },
91
+ },
92
+ ...overrideVite?.css,
93
+ },
94
+ build: {
95
+ chunkSizeWarningLimit: 1000,
96
+ ...overrideVite?.build,
97
+ },
98
+ define: {
99
+ __TNOTES_REPO_NAME__: JSON.stringify(config.repoName),
100
+ __TNOTES_AUTHOR__: JSON.stringify(config.author),
101
+ __TNOTES_IGNORE_DIRS__: JSON.stringify(config.ignore_dirs),
102
+ __TNOTES_ROOT_ITEM__: JSON.stringify(config.root_item),
103
+ ...overrideVite?.define,
104
+ },
105
+ },
106
+ transformPageData(pageData, ctx) {
107
+ // 为笔记页面注入原始 Markdown 内容(用于一键复制功能)
108
+ if (/^notes\/\d{4}/.test(pageData.relativePath)) {
109
+ const fullPath = path.resolve(rootPath, pageData.relativePath)
110
+ try {
111
+ pageData.frontmatter.rawContent = fs.readFileSync(fullPath, 'utf-8')
112
+ } catch {
113
+ pageData.frontmatter.rawContent = null
114
+ }
115
+ }
116
+ // 执行外部覆盖的 transformPageData(如有)
117
+ if (typeof overrideTransformPageData === 'function') {
118
+ return overrideTransformPageData(pageData, ctx)
119
+ }
120
+ },
121
+ router: {
122
+ prefetchLinks: false,
123
+ },
124
+ ...restOverrides,
125
+ })
126
+ }
@@ -0,0 +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
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * .vitepress/config/head.config.ts
3
+ *
4
+ * HTML head 标签配置
5
+ */
6
+ import { HeadConfig } from 'vitepress'
7
+ import type { TNotesConfig } from '../../types'
8
+
9
+ export function getHeadConfig(config: TNotesConfig, githubPageUrl: string): HeadConfig[] {
10
+ const head: HeadConfig[] = [
11
+ [
12
+ 'meta',
13
+ {
14
+ name: 'keywords',
15
+ content: config.keywords.join(', '),
16
+ },
17
+ ],
18
+ ['meta', { name: 'author', content: config.author }],
19
+ ['link', { rel: 'canonical', href: githubPageUrl }],
20
+ ['link', { rel: 'icon', href: githubPageUrl + 'favicon.ico' }],
21
+ ['link', { rel: 'preconnect', href: 'https://fonts.googleapis.com' }],
22
+ ]
23
+
24
+ return head
25
+ }
@@ -0,0 +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'
@@ -0,0 +1,23 @@
1
+ /**
2
+ * .vitepress/config/markdown-it.d.ts
3
+ *
4
+ * 第三方库类型声明
5
+ */
6
+
7
+ declare module 'markdown-it-container' {
8
+ import { PluginWithOptions } from 'markdown-it'
9
+ const markdownItContainer: PluginWithOptions<any>
10
+ export default markdownItContainer
11
+ }
12
+
13
+ declare module 'markdown-it-link-attributes' {
14
+ import { PluginWithOptions } from 'markdown-it'
15
+ const markdownItLinkAttributes: PluginWithOptions<any>
16
+ export default markdownItLinkAttributes
17
+ }
18
+
19
+ declare module 'markdown-it-task-lists' {
20
+ import { PluginWithOptions } from 'markdown-it'
21
+ const markdownItTaskLists: PluginWithOptions<any>
22
+ export default markdownItTaskLists
23
+ }