@tnotesjs/core 0.1.19 → 0.1.20

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 (114) hide show
  1. package/README.md +87 -87
  2. package/package.json +1 -1
  3. package/types/config.ts +61 -61
  4. package/types/index.ts +11 -11
  5. package/types/note.ts +33 -33
  6. package/vitepress/assets/icons/icon__check.svg +3 -3
  7. package/vitepress/assets/icons/icon__clipboard.svg +7 -7
  8. package/vitepress/assets/icons/icon__close.svg +1 -1
  9. package/vitepress/assets/icons/icon__collapse.svg +1 -1
  10. package/vitepress/assets/icons/icon__confirm.svg +1 -1
  11. package/vitepress/assets/icons/icon__copy.svg +4 -4
  12. package/vitepress/assets/icons/icon__focus.svg +1 -1
  13. package/vitepress/assets/icons/icon__fold.svg +3 -3
  14. package/vitepress/assets/icons/icon__folder.svg +1 -1
  15. package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
  16. package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
  17. package/vitepress/assets/icons/icon__github.svg +3 -3
  18. package/vitepress/assets/icons/icon__mindmap.svg +1 -1
  19. package/vitepress/assets/icons/icon__next.svg +1 -1
  20. package/vitepress/assets/icons/icon__number_gray.svg +1 -1
  21. package/vitepress/assets/icons/icon__number_purple.svg +1 -1
  22. package/vitepress/assets/icons/icon__prev.svg +1 -1
  23. package/vitepress/assets/icons/icon__restore.svg +1 -1
  24. package/vitepress/assets/icons/icon__rotate.svg +4 -4
  25. package/vitepress/assets/icons/icon__search.svg +1 -1
  26. package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
  27. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
  28. package/vitepress/assets/icons/icon__totop.svg +5 -5
  29. package/vitepress/assets/icons/icon__vscode.svg +5 -5
  30. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
  31. package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
  32. package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
  33. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
  34. package/vitepress/assets/icons/index.ts +39 -39
  35. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
  36. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +369 -369
  37. package/vitepress/components/CodeBlockFullscreen/index.ts +213 -213
  38. package/vitepress/components/CodeBlockFullscreen/styles.css +126 -126
  39. package/vitepress/components/Discussions/Discussions.module.scss +32 -32
  40. package/vitepress/components/Discussions/Discussions.vue +211 -211
  41. package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
  42. package/vitepress/components/EnWordList/EnWordList.vue +543 -543
  43. package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
  44. package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
  45. package/vitepress/components/Footprints/Footprints.module.scss +93 -93
  46. package/vitepress/components/Footprints/Footprints.vue +377 -377
  47. package/vitepress/components/Layout/AboutModal.module.scss +233 -233
  48. package/vitepress/components/Layout/AboutModal.vue +105 -105
  49. package/vitepress/components/Layout/AboutPanel.vue +270 -270
  50. package/vitepress/components/Layout/ContentCollapse.vue +603 -603
  51. package/vitepress/components/Layout/CustomSidebar.vue +817 -817
  52. package/vitepress/components/Layout/DocBeforeControls.vue +149 -149
  53. package/vitepress/components/Layout/DocFooter.vue +233 -233
  54. package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
  55. package/vitepress/components/Layout/ImagePreview.vue +281 -281
  56. package/vitepress/components/Layout/Layout.module.scss +661 -661
  57. package/vitepress/components/Layout/Layout.vue +621 -621
  58. package/vitepress/components/Layout/NoteStatus.vue +140 -140
  59. package/vitepress/components/Layout/SidebarItems.vue +1083 -1083
  60. package/vitepress/components/Layout/SidebarNavBefore.vue +171 -171
  61. package/vitepress/components/Layout/SidebarResizeHandle.vue +319 -319
  62. package/vitepress/components/Layout/Swiper.vue +167 -167
  63. package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
  64. package/vitepress/components/Layout/ToggleFullContent.vue +35 -35
  65. package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
  66. package/vitepress/components/Layout/ToggleSidebar.vue +26 -26
  67. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
  68. package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
  69. package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
  70. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
  71. package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
  72. package/vitepress/components/Layout/composables/useSidebarLayout.ts +122 -122
  73. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
  74. package/vitepress/components/Layout/homeReadme.data.ts +124 -124
  75. package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
  76. package/vitepress/components/MarkMap/MarkMap.vue +405 -405
  77. package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
  78. package/vitepress/components/Mermaid/Mermaid.vue +365 -365
  79. package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
  80. package/vitepress/components/NotesTable/NotesTable.vue +98 -98
  81. package/vitepress/components/NotesTable/README.md +67 -67
  82. package/vitepress/components/Settings/Settings.module.scss +375 -375
  83. package/vitepress/components/Settings/Settings.vue +334 -334
  84. package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
  85. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
  86. package/vitepress/components/SidebarCard/SidebarCard.vue +946 -946
  87. package/vitepress/components/Tooltip/Tooltip.vue +70 -70
  88. package/vitepress/components/constants.ts +109 -109
  89. package/vitepress/components/notesConfig.data.ts +73 -73
  90. package/vitepress/components/sidebar.data.ts +59 -59
  91. package/vitepress/components/tnotes-config.data.ts +21 -21
  92. package/vitepress/components/utils.ts +26 -26
  93. package/vitepress/config/index.ts +169 -169
  94. package/vitepress/configs/constants.ts +26 -26
  95. package/vitepress/configs/head.config.ts +25 -25
  96. package/vitepress/configs/index.ts +9 -9
  97. package/vitepress/configs/markdown-it.d.ts +23 -23
  98. package/vitepress/configs/markdown.config.ts +366 -366
  99. package/vitepress/configs/theme.config.ts +108 -108
  100. package/vitepress/plugins/buildProgressPlugin.ts +434 -434
  101. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
  102. package/vitepress/plugins/renameNotePlugin.ts +68 -68
  103. package/vitepress/plugins/sidebarStructurePlugin.ts +260 -260
  104. package/vitepress/plugins/updateConfigPlugin.ts +63 -63
  105. package/vitepress/theme/index.ts +137 -137
  106. package/vitepress/theme/styles/base.scss +64 -59
  107. package/vitepress/theme/styles/components/404.scss +31 -31
  108. package/vitepress/theme/styles/components/collapse.scss +172 -172
  109. package/vitepress/theme/styles/components/markmap.scss +101 -101
  110. package/vitepress/theme/styles/components/swiper.scss +255 -255
  111. package/vitepress/theme/styles/index.scss +25 -25
  112. package/vitepress/theme/styles/layout.scss +78 -78
  113. package/vitepress/theme/styles/utilities.scss +39 -39
  114. package/vitepress/theme/styles/vitepress-override.scss +25 -25
@@ -1,70 +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>
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>
@@ -1,109 +1,109 @@
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
- * 侧边栏目录风格配置
74
- */
75
- export const SIDEBAR_DENSITY_KEY: string =
76
- 'SIDEBAR_DENSITY_KEY__' + REPO_NAME
77
-
78
- /**
79
- * 侧边栏已完成笔记前缀配置
80
- */
81
- export const SIDEBAR_DONE_PREFIX_KEY: string =
82
- 'SIDEBAR_DONE_PREFIX_KEY__' + REPO_NAME
83
-
84
- /**
85
- * 侧边栏未完成笔记前缀配置
86
- */
87
- export const SIDEBAR_UNDONE_PREFIX_KEY: string =
88
- 'SIDEBAR_UNDONE_PREFIX_KEY__' + REPO_NAME
89
-
90
- /**
91
- * VitePress HOME README 文件名
92
- * 该文件内容基于 HOME README 而生成,作为 github pages 中的 README 文件,主要用于展示笔记的目录结构。
93
- */
94
- export const TOC: string = 'TOC'
95
- export const TOC_MD: string = TOC + '.md'
96
-
97
- /**
98
- * 英语单词仓库基地址
99
- * https://github.com/tnotesjs/en-words/blob/main/{word}.md
100
- */
101
- export const EN_WORDS_REPO_BASE_URL: string =
102
- 'https://github.com/tnotesjs/TNotes.en-words/blob/main/'
103
-
104
- /**
105
- * 英语单词仓库 raw 地址
106
- * https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/{word}.md
107
- */
108
- export const EN_WORDS_REPO_BASE_RAW_URL: string =
109
- 'https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/'
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
+ * 侧边栏目录风格配置
74
+ */
75
+ export const SIDEBAR_DENSITY_KEY: string =
76
+ 'SIDEBAR_DENSITY_KEY__' + REPO_NAME
77
+
78
+ /**
79
+ * 侧边栏已完成笔记前缀配置
80
+ */
81
+ export const SIDEBAR_DONE_PREFIX_KEY: string =
82
+ 'SIDEBAR_DONE_PREFIX_KEY__' + REPO_NAME
83
+
84
+ /**
85
+ * 侧边栏未完成笔记前缀配置
86
+ */
87
+ export const SIDEBAR_UNDONE_PREFIX_KEY: string =
88
+ 'SIDEBAR_UNDONE_PREFIX_KEY__' + REPO_NAME
89
+
90
+ /**
91
+ * VitePress HOME README 文件名
92
+ * 该文件内容基于 HOME README 而生成,作为 github pages 中的 README 文件,主要用于展示笔记的目录结构。
93
+ */
94
+ export const TOC: string = 'TOC'
95
+ export const TOC_MD: string = TOC + '.md'
96
+
97
+ /**
98
+ * 英语单词仓库基地址
99
+ * https://github.com/tnotesjs/en-words/blob/main/{word}.md
100
+ */
101
+ export const EN_WORDS_REPO_BASE_URL: string =
102
+ 'https://github.com/tnotesjs/TNotes.en-words/blob/main/'
103
+
104
+ /**
105
+ * 英语单词仓库 raw 地址
106
+ * https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/{word}.md
107
+ */
108
+ export const EN_WORDS_REPO_BASE_RAW_URL: string =
109
+ 'https://raw.githubusercontent.com/tnotesjs/TNotes.en-words/refs/heads/main/'
@@ -1,73 +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
- }
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
+ }
@@ -1,59 +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
- }
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
+ }
@@ -1,21 +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
- }
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
+ }