@tnotesjs/core 0.0.1 → 0.0.3

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 (115) hide show
  1. package/README.md +84 -84
  2. package/dist/{chunk-CSSIRO3I.js → chunk-NI5B4S3T.js} +40 -3
  3. package/dist/cli/index.js +1 -1
  4. package/dist/vitepress/config/index.js +60 -17
  5. package/package.json +77 -77
  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__sidebar_collapsed.svg +1 -1
  30. package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
  31. package/vitepress/assets/icons/icon__totop.svg +5 -5
  32. package/vitepress/assets/icons/icon__vscode.svg +5 -5
  33. package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
  34. package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
  35. package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
  36. package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
  37. package/vitepress/assets/icons/index.ts +38 -38
  38. package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
  39. package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +373 -373
  40. package/vitepress/components/CodeBlockFullscreen/index.ts +115 -115
  41. package/vitepress/components/CodeBlockFullscreen/styles.css +64 -64
  42. package/vitepress/components/Discussions/Discussions.module.scss +32 -32
  43. package/vitepress/components/Discussions/Discussions.vue +211 -211
  44. package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
  45. package/vitepress/components/EnWordList/EnWordList.vue +543 -543
  46. package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
  47. package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
  48. package/vitepress/components/Footprints/Footprints.module.scss +93 -93
  49. package/vitepress/components/Footprints/Footprints.vue +377 -377
  50. package/vitepress/components/Layout/AboutModal.module.scss +233 -233
  51. package/vitepress/components/Layout/AboutModal.vue +105 -105
  52. package/vitepress/components/Layout/AboutPanel.vue +266 -266
  53. package/vitepress/components/Layout/ContentCollapse.vue +603 -603
  54. package/vitepress/components/Layout/CustomSidebar.vue +605 -605
  55. package/vitepress/components/Layout/DocBeforeControls.vue +139 -139
  56. package/vitepress/components/Layout/DocFooter.vue +225 -225
  57. package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
  58. package/vitepress/components/Layout/ImagePreview.vue +281 -281
  59. package/vitepress/components/Layout/Layout.module.scss +661 -661
  60. package/vitepress/components/Layout/Layout.vue +542 -542
  61. package/vitepress/components/Layout/NoteStatus.vue +140 -140
  62. package/vitepress/components/Layout/SidebarItems.vue +263 -263
  63. package/vitepress/components/Layout/SidebarNavBefore.vue +92 -92
  64. package/vitepress/components/Layout/Swiper.vue +167 -167
  65. package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
  66. package/vitepress/components/Layout/ToggleFullContent.vue +34 -34
  67. package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
  68. package/vitepress/components/Layout/ToggleSidebar.vue +35 -35
  69. package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
  70. package/vitepress/components/Layout/composables/useNoteConfig.ts +121 -121
  71. package/vitepress/components/Layout/composables/useNoteSave.ts +173 -173
  72. package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
  73. package/vitepress/components/Layout/composables/useRedirect.ts +110 -110
  74. package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
  75. package/vitepress/components/Layout/homeReadme.data.ts +124 -124
  76. package/vitepress/components/LoadingPage/LoadingPage.vue +192 -192
  77. package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
  78. package/vitepress/components/MarkMap/MarkMap.vue +404 -404
  79. package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
  80. package/vitepress/components/Mermaid/Mermaid.vue +364 -364
  81. package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
  82. package/vitepress/components/NotesTable/NotesTable.vue +98 -98
  83. package/vitepress/components/NotesTable/README.md +67 -67
  84. package/vitepress/components/Settings/Settings.module.scss +433 -433
  85. package/vitepress/components/Settings/Settings.vue +306 -306
  86. package/vitepress/components/SidebarCard/MindMapView.vue +483 -483
  87. package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
  88. package/vitepress/components/SidebarCard/SidebarCard.vue +948 -948
  89. package/vitepress/components/Tooltip/Tooltip.vue +70 -70
  90. package/vitepress/components/constants.ts +91 -91
  91. package/vitepress/components/notesConfig.data.ts +73 -73
  92. package/vitepress/components/sidebar.data.ts +59 -59
  93. package/vitepress/components/tnotes-config.data.ts +21 -21
  94. package/vitepress/components/utils.ts +26 -26
  95. package/vitepress/config/index.ts +141 -141
  96. package/vitepress/configs/constants.ts +26 -26
  97. package/vitepress/configs/head.config.ts +25 -25
  98. package/vitepress/configs/index.ts +9 -9
  99. package/vitepress/configs/markdown-it.d.ts +23 -23
  100. package/vitepress/configs/markdown.config.ts +366 -366
  101. package/vitepress/configs/theme.config.ts +108 -108
  102. package/vitepress/plugins/buildProgressPlugin.ts +466 -390
  103. package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
  104. package/vitepress/plugins/renameNotePlugin.ts +60 -60
  105. package/vitepress/plugins/updateConfigPlugin.ts +63 -63
  106. package/vitepress/theme/index.ts +95 -95
  107. package/vitepress/theme/styles/base.scss +50 -50
  108. package/vitepress/theme/styles/components/404.scss +31 -31
  109. package/vitepress/theme/styles/components/collapse.scss +175 -175
  110. package/vitepress/theme/styles/components/markmap.scss +101 -101
  111. package/vitepress/theme/styles/components/swiper.scss +255 -255
  112. package/vitepress/theme/styles/index.scss +25 -25
  113. package/vitepress/theme/styles/layout.scss +62 -62
  114. package/vitepress/theme/styles/utilities.scss +39 -39
  115. 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,91 +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/'
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/'
@@ -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
+ }