@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.
- package/README.md +87 -87
- package/package.json +1 -1
- package/types/config.ts +61 -61
- package/types/index.ts +11 -11
- package/types/note.ts +33 -33
- package/vitepress/assets/icons/icon__check.svg +3 -3
- package/vitepress/assets/icons/icon__clipboard.svg +7 -7
- package/vitepress/assets/icons/icon__close.svg +1 -1
- package/vitepress/assets/icons/icon__collapse.svg +1 -1
- package/vitepress/assets/icons/icon__confirm.svg +1 -1
- package/vitepress/assets/icons/icon__copy.svg +4 -4
- package/vitepress/assets/icons/icon__focus.svg +1 -1
- package/vitepress/assets/icons/icon__fold.svg +3 -3
- package/vitepress/assets/icons/icon__folder.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen.svg +1 -1
- package/vitepress/assets/icons/icon__fullscreen_exit.svg +1 -1
- package/vitepress/assets/icons/icon__github.svg +3 -3
- package/vitepress/assets/icons/icon__mindmap.svg +1 -1
- package/vitepress/assets/icons/icon__next.svg +1 -1
- package/vitepress/assets/icons/icon__number_gray.svg +1 -1
- package/vitepress/assets/icons/icon__number_purple.svg +1 -1
- package/vitepress/assets/icons/icon__prev.svg +1 -1
- package/vitepress/assets/icons/icon__restore.svg +1 -1
- package/vitepress/assets/icons/icon__rotate.svg +4 -4
- package/vitepress/assets/icons/icon__search.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_collapsed.svg +1 -1
- package/vitepress/assets/icons/icon__sidebar_opened.svg +1 -1
- package/vitepress/assets/icons/icon__totop.svg +5 -5
- package/vitepress/assets/icons/icon__vscode.svg +5 -5
- package/vitepress/assets/icons/icon__zoom_fit.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_in.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_out.svg +1 -1
- package/vitepress/assets/icons/icon__zoom_reset.svg +1 -1
- package/vitepress/assets/icons/index.ts +39 -39
- package/vitepress/components/BilibiliOutsidePlayer/BilibiliOutsidePlayer.vue +20 -20
- package/vitepress/components/CodeBlockFullscreen/CodeBlockFullscreen.vue +369 -369
- package/vitepress/components/CodeBlockFullscreen/index.ts +213 -213
- package/vitepress/components/CodeBlockFullscreen/styles.css +126 -126
- package/vitepress/components/Discussions/Discussions.module.scss +32 -32
- package/vitepress/components/Discussions/Discussions.vue +211 -211
- package/vitepress/components/EnWordList/EnWordList.module.scss +124 -124
- package/vitepress/components/EnWordList/EnWordList.vue +543 -543
- package/vitepress/components/EnWordList/RightClickMenu.module.scss +22 -22
- package/vitepress/components/EnWordList/RightClickMenu.vue +66 -66
- package/vitepress/components/Footprints/Footprints.module.scss +93 -93
- package/vitepress/components/Footprints/Footprints.vue +377 -377
- package/vitepress/components/Layout/AboutModal.module.scss +233 -233
- package/vitepress/components/Layout/AboutModal.vue +105 -105
- package/vitepress/components/Layout/AboutPanel.vue +270 -270
- package/vitepress/components/Layout/ContentCollapse.vue +603 -603
- package/vitepress/components/Layout/CustomSidebar.vue +817 -817
- package/vitepress/components/Layout/DocBeforeControls.vue +149 -149
- package/vitepress/components/Layout/DocFooter.vue +233 -233
- package/vitepress/components/Layout/ImagePreview.module.scss +201 -201
- package/vitepress/components/Layout/ImagePreview.vue +281 -281
- package/vitepress/components/Layout/Layout.module.scss +661 -661
- package/vitepress/components/Layout/Layout.vue +621 -621
- package/vitepress/components/Layout/NoteStatus.vue +140 -140
- package/vitepress/components/Layout/SidebarItems.vue +1083 -1083
- package/vitepress/components/Layout/SidebarNavBefore.vue +171 -171
- package/vitepress/components/Layout/SidebarResizeHandle.vue +319 -319
- package/vitepress/components/Layout/Swiper.vue +167 -167
- package/vitepress/components/Layout/ToggleFullContent.module.scss +11 -11
- package/vitepress/components/Layout/ToggleFullContent.vue +35 -35
- package/vitepress/components/Layout/ToggleSidebar.module.scss +11 -11
- package/vitepress/components/Layout/ToggleSidebar.vue +26 -26
- package/vitepress/components/Layout/composables/useCollapseControl.ts +88 -88
- package/vitepress/components/Layout/composables/useNoteConfig.ts +119 -119
- package/vitepress/components/Layout/composables/useNoteSave.ts +178 -178
- package/vitepress/components/Layout/composables/useNoteValidation.ts +85 -85
- package/vitepress/components/Layout/composables/useRedirect.ts +113 -113
- package/vitepress/components/Layout/composables/useSidebarLayout.ts +122 -122
- package/vitepress/components/Layout/composables/useVSCodeIntegration.ts +85 -85
- package/vitepress/components/Layout/homeReadme.data.ts +124 -124
- package/vitepress/components/MarkMap/MarkMap.module.scss +159 -159
- package/vitepress/components/MarkMap/MarkMap.vue +405 -405
- package/vitepress/components/Mermaid/Mermaid.module.scss +275 -275
- package/vitepress/components/Mermaid/Mermaid.vue +365 -365
- package/vitepress/components/NotesTable/NotesTable.module.scss +77 -77
- package/vitepress/components/NotesTable/NotesTable.vue +98 -98
- package/vitepress/components/NotesTable/README.md +67 -67
- package/vitepress/components/Settings/Settings.module.scss +375 -375
- package/vitepress/components/Settings/Settings.vue +334 -334
- package/vitepress/components/SidebarCard/MindMapView.vue +484 -484
- package/vitepress/components/SidebarCard/NotesTrendChart.vue +108 -108
- package/vitepress/components/SidebarCard/SidebarCard.vue +946 -946
- package/vitepress/components/Tooltip/Tooltip.vue +70 -70
- package/vitepress/components/constants.ts +109 -109
- package/vitepress/components/notesConfig.data.ts +73 -73
- package/vitepress/components/sidebar.data.ts +59 -59
- package/vitepress/components/tnotes-config.data.ts +21 -21
- package/vitepress/components/utils.ts +26 -26
- package/vitepress/config/index.ts +169 -169
- package/vitepress/configs/constants.ts +26 -26
- package/vitepress/configs/head.config.ts +25 -25
- package/vitepress/configs/index.ts +9 -9
- package/vitepress/configs/markdown-it.d.ts +23 -23
- package/vitepress/configs/markdown.config.ts +366 -366
- package/vitepress/configs/theme.config.ts +108 -108
- package/vitepress/plugins/buildProgressPlugin.ts +434 -434
- package/vitepress/plugins/getNoteByConfigIdPlugin.ts +107 -107
- package/vitepress/plugins/renameNotePlugin.ts +68 -68
- package/vitepress/plugins/sidebarStructurePlugin.ts +260 -260
- package/vitepress/plugins/updateConfigPlugin.ts +63 -63
- package/vitepress/theme/index.ts +137 -137
- package/vitepress/theme/styles/base.scss +64 -59
- package/vitepress/theme/styles/components/404.scss +31 -31
- package/vitepress/theme/styles/components/collapse.scss +172 -172
- package/vitepress/theme/styles/components/markmap.scss +101 -101
- package/vitepress/theme/styles/components/swiper.scss +255 -255
- package/vitepress/theme/styles/index.scss +25 -25
- package/vitepress/theme/styles/layout.scss +78 -78
- package/vitepress/theme/styles/utilities.scss +39 -39
- package/vitepress/theme/styles/vitepress-override.scss +25 -25
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
/* #region:same as vitepress theme */
|
|
2
|
-
.h2 {
|
|
3
|
-
margin: 48px 0 16px;
|
|
4
|
-
border-top: 1px solid var(--vp-c-divider);
|
|
5
|
-
padding-top: 24px;
|
|
6
|
-
letter-spacing: -0.02em;
|
|
7
|
-
line-height: 32px;
|
|
8
|
-
font-size: 1.2rem;
|
|
9
|
-
text-align: center;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/* #endregion:same as vitepress theme */
|
|
13
|
-
|
|
14
|
-
.discussionsLink {
|
|
15
|
-
display: inline-flex;
|
|
16
|
-
align-items: center;
|
|
17
|
-
gap: 0.5em;
|
|
18
|
-
color: var(--vp-c-brand-1);
|
|
19
|
-
text-decoration: none;
|
|
20
|
-
opacity: 0.9;
|
|
21
|
-
transition: opacity 0.25s;
|
|
22
|
-
|
|
23
|
-
&:hover {
|
|
24
|
-
opacity: 0.5;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.githubIcon {
|
|
29
|
-
width: 1em;
|
|
30
|
-
height: 1em;
|
|
31
|
-
flex-shrink: 0;
|
|
32
|
-
}
|
|
1
|
+
/* #region:same as vitepress theme */
|
|
2
|
+
.h2 {
|
|
3
|
+
margin: 48px 0 16px;
|
|
4
|
+
border-top: 1px solid var(--vp-c-divider);
|
|
5
|
+
padding-top: 24px;
|
|
6
|
+
letter-spacing: -0.02em;
|
|
7
|
+
line-height: 32px;
|
|
8
|
+
font-size: 1.2rem;
|
|
9
|
+
text-align: center;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* #endregion:same as vitepress theme */
|
|
13
|
+
|
|
14
|
+
.discussionsLink {
|
|
15
|
+
display: inline-flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: 0.5em;
|
|
18
|
+
color: var(--vp-c-brand-1);
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
opacity: 0.9;
|
|
21
|
+
transition: opacity 0.25s;
|
|
22
|
+
|
|
23
|
+
&:hover {
|
|
24
|
+
opacity: 0.5;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.githubIcon {
|
|
29
|
+
width: 1em;
|
|
30
|
+
height: 1em;
|
|
31
|
+
flex-shrink: 0;
|
|
32
|
+
}
|
|
@@ -1,212 +1,212 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
import { useData } from 'vitepress/client'
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { useData } from 'vitepress/client'
|
|
3
3
|
import { onMounted, onUnmounted, watch, computed } from 'vue'
|
|
4
|
-
|
|
5
|
-
import { icon__github } from '../../assets/icons'
|
|
6
|
-
import { REPO_NAME, AUTHOR } from '../constants'
|
|
7
|
-
import Tooltip from '../Tooltip/Tooltip.vue'
|
|
8
|
-
|
|
9
|
-
const props = defineProps({
|
|
10
|
-
/**
|
|
11
|
-
* 留言版 ID
|
|
12
|
-
* 来自于笔记配置文件中的 id 字段的 uuid 值
|
|
13
|
-
*/
|
|
14
|
-
id: {
|
|
15
|
-
type: String,
|
|
16
|
-
required: true,
|
|
17
|
-
},
|
|
18
|
-
/**
|
|
19
|
-
* 笔记序号(如 0001)
|
|
20
|
-
*/
|
|
21
|
-
noteNumber: {
|
|
22
|
-
type: String,
|
|
23
|
-
default: '',
|
|
24
|
-
},
|
|
25
|
-
/**
|
|
26
|
-
* 笔记标题
|
|
27
|
-
*/
|
|
28
|
-
noteTitle: {
|
|
29
|
-
type: String,
|
|
30
|
-
default: '',
|
|
31
|
-
},
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// 🔍 查阅支持的所有主题 https://giscus.app/zh-CN
|
|
35
|
-
const GISCUS_DARK_THEME = 'noborder_dark'
|
|
36
|
-
const GISCUS_LIGHT_THEME = 'noborder_light'
|
|
37
|
-
|
|
38
|
-
// 获取 VitePress 的数据 - 主题状态
|
|
39
|
-
const { isDark } = useData()
|
|
40
|
-
|
|
41
|
-
// 生成 GitHub Discussions 直接链接
|
|
42
|
-
const githubDiscussionsUrl = computed(() => {
|
|
43
|
-
return `https://github.com/orgs/tnotesjs/discussions?discussions_q=${props.id}`
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 生成 giscus backlink(带有笔记信息的 GitHub 页面链接)
|
|
48
|
-
*
|
|
49
|
-
* giscus 会在创建新 Discussion 时自动添加返回链接。
|
|
50
|
-
* 通过设置 <meta name="giscus:backlink"> 标签,可以自定义这个链接。
|
|
51
|
-
* 这样在 GitHub Discussions 中就能看到对应笔记的直接链接。
|
|
52
|
-
*
|
|
53
|
-
* 📖 官方文档:https://github.com/giscus/giscus/blob/main/ADVANCED-USAGE.md#giscusbacklink
|
|
54
|
-
*/
|
|
55
|
-
const giscusBacklink = computed(() => {
|
|
56
|
-
console.log('[Discussions] Props:', {
|
|
57
|
-
noteNumber: props.noteNumber,
|
|
58
|
-
noteTitle: props.noteTitle,
|
|
59
|
-
id: props.id,
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
if (!props.noteNumber || !props.noteTitle) {
|
|
63
|
-
console.log('[Discussions] 使用默认 URL:', window.location.href)
|
|
64
|
-
return window.location.href
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// 对笔记标题进行 URL 编码(处理中文和特殊字符)
|
|
68
|
-
const encodedTitle = encodeURIComponent(props.noteTitle)
|
|
69
|
-
|
|
70
|
-
// 生成笔记相关链接
|
|
71
|
-
const noteGithubUrl = `https://github.com/${AUTHOR}/${REPO_NAME}/tree/main/notes/${props.noteNumber}.%20${encodedTitle}`
|
|
72
|
-
const notePageUrl = `https://${AUTHOR.toLowerCase()}.github.io/${REPO_NAME}/notes/${
|
|
73
|
-
props.noteNumber
|
|
74
|
-
}.%20${encodedTitle}/README`
|
|
75
|
-
|
|
76
|
-
// 生成知识库相关链接
|
|
77
|
-
const repoGithubUrl = `https://github.com/${AUTHOR}/${REPO_NAME}`
|
|
78
|
-
const repoPageUrl = `https://${AUTHOR.toLowerCase()}.github.io/${REPO_NAME}/`
|
|
79
|
-
|
|
80
|
-
// 生成当前时间字符串
|
|
81
|
-
const now = new Date()
|
|
82
|
-
const year = now.getFullYear()
|
|
83
|
-
const month = String(now.getMonth() + 1).padStart(2, '0')
|
|
84
|
-
const day = String(now.getDate()).padStart(2, '0')
|
|
85
|
-
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
|
86
|
-
const weekDay = `周${weekDays[now.getDay()]}`
|
|
87
|
-
const hour = now.getHours()
|
|
88
|
-
const minute = String(now.getMinutes()).padStart(2, '0')
|
|
89
|
-
const second = String(now.getSeconds()).padStart(2, '0')
|
|
90
|
-
const period = hour < 12 ? '上午' : '下午'
|
|
91
|
-
const hour12 = hour % 12 || 12
|
|
92
|
-
const formattedTime = `${year}.${month}.${day} ${weekDay} ${period} ${hour12}:${minute}:${second}`
|
|
93
|
-
|
|
94
|
-
// 构建 Markdown 格式的笔记信息
|
|
95
|
-
const backlink = `
|
|
96
|
-
- **${props.noteNumber}. ${props.noteTitle}**:[GitHub](${noteGithubUrl})、[GitHub Page](${notePageUrl})
|
|
97
|
-
- **${REPO_NAME}**:[GitHub](${repoGithubUrl})、[GitHub Page](${repoPageUrl})
|
|
98
|
-
- **评论创建时间**:${formattedTime}
|
|
99
|
-
`.trim()
|
|
100
|
-
|
|
101
|
-
console.log('[Discussions] 生成的 backlink:', backlink)
|
|
102
|
-
return backlink
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
// 动态注入 giscus backlink meta 标签
|
|
106
|
-
const updateGiscusBacklink = () => {
|
|
107
|
-
// 移除旧的 giscus:backlink meta 标签
|
|
108
|
-
const oldMeta = document.querySelector('meta[name="giscus:backlink"]')
|
|
109
|
-
if (oldMeta) {
|
|
110
|
-
oldMeta.remove()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 添加新的 giscus:backlink meta 标签
|
|
114
|
-
const meta = document.createElement('meta')
|
|
115
|
-
meta.name = 'giscus:backlink'
|
|
116
|
-
meta.content = giscusBacklink.value
|
|
117
|
-
document.head.appendChild(meta)
|
|
118
|
-
|
|
119
|
-
console.log('[Discussions] 已添加 giscus:backlink meta 标签:', meta.content)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 动态注入 giscus 评论脚本
|
|
123
|
-
const loadGiscusScript = () => {
|
|
124
|
-
// 更新 giscus:backlink meta 标签
|
|
125
|
-
updateGiscusBacklink()
|
|
126
|
-
|
|
127
|
-
// 清除旧的 giscus 脚本和 iframe
|
|
128
|
-
const oldScript = document.getElementById('giscus-script')
|
|
129
|
-
const oldIframe = document.querySelector('iframe.giscus-frame')
|
|
130
|
-
if (oldScript) oldScript.remove()
|
|
131
|
-
if (oldIframe) oldIframe.remove()
|
|
132
|
-
|
|
133
|
-
// 创建新的 giscus 脚本
|
|
134
|
-
const giscusScript = document.createElement('script')
|
|
135
|
-
giscusScript.src = 'https://giscus.app/client.js'
|
|
136
|
-
giscusScript.setAttribute('data-repo', 'tnotesjs/TNotes.discussions')
|
|
137
|
-
giscusScript.setAttribute('data-repo-id', 'R_kgDOQauuyw')
|
|
138
|
-
giscusScript.setAttribute('data-category', 'Announcements')
|
|
139
|
-
giscusScript.setAttribute('data-category-id', 'DIC_kwDOQauuy84CyEuQ')
|
|
140
|
-
giscusScript.setAttribute('data-mapping', 'specific')
|
|
141
|
-
giscusScript.setAttribute('data-term', props.id)
|
|
142
|
-
giscusScript.setAttribute('data-strict', '0')
|
|
143
|
-
giscusScript.setAttribute('data-reactions-enabled', '1')
|
|
144
|
-
giscusScript.setAttribute('data-emit-metadata', '0')
|
|
145
|
-
giscusScript.setAttribute('data-input-position', 'top')
|
|
146
|
-
giscusScript.setAttribute('data-lang', 'zh-CN')
|
|
147
|
-
giscusScript.setAttribute('data-loading', 'lazy')
|
|
148
|
-
giscusScript.setAttribute(
|
|
149
|
-
'data-theme',
|
|
150
|
-
isDark.value ? GISCUS_DARK_THEME : GISCUS_LIGHT_THEME
|
|
151
|
-
)
|
|
152
|
-
giscusScript.setAttribute('crossorigin', 'anonymous')
|
|
153
|
-
giscusScript.async = true
|
|
154
|
-
giscusScript.id = 'giscus-script'
|
|
155
|
-
|
|
156
|
-
document.getElementById('giscus-comments')?.appendChild(giscusScript)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
onMounted(() => {
|
|
160
|
-
loadGiscusScript()
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
onUnmounted(() => {
|
|
164
|
-
// 组件卸载时移除 giscus:backlink meta 标签
|
|
165
|
-
const meta = document.querySelector('meta[name="giscus:backlink"]')
|
|
166
|
-
if (meta) {
|
|
167
|
-
meta.remove()
|
|
168
|
-
}
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
watch([() => props.id], ([newId]) => {
|
|
172
|
-
loadGiscusScript()
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
// 切换主题的时候,动态修改 giscus 评论主题,不需要重新 loadGiscusScript。
|
|
176
|
-
watch(isDark, (newVal) => {
|
|
177
|
-
const iframe = document.querySelector<HTMLIFrameElement>(
|
|
178
|
-
'iframe.giscus-frame'
|
|
179
|
-
)
|
|
180
|
-
if (iframe) {
|
|
181
|
-
iframe.contentWindow?.postMessage(
|
|
182
|
-
{
|
|
183
|
-
giscus: {
|
|
184
|
-
setConfig: {
|
|
185
|
-
theme: newVal ? GISCUS_DARK_THEME : GISCUS_LIGHT_THEME,
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
'https://giscus.app'
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
})
|
|
193
|
-
</script>
|
|
194
|
-
|
|
195
|
-
<template>
|
|
196
|
-
<h2 :class="$style.h2">
|
|
197
|
-
<Tooltip text="在 GitHub 上发表评论(支持上传图片)">
|
|
198
|
-
<a
|
|
199
|
-
:href="githubDiscussionsUrl"
|
|
200
|
-
target="_blank"
|
|
201
|
-
rel="noopener noreferrer"
|
|
202
|
-
:class="$style.discussionsLink"
|
|
203
|
-
>
|
|
204
|
-
<img :src="icon__github" alt="" :class="$style.githubIcon" />
|
|
205
|
-
Discussions
|
|
206
|
-
</a>
|
|
207
|
-
</Tooltip>
|
|
208
|
-
</h2>
|
|
209
|
-
<div id="giscus-comments"></div>
|
|
210
|
-
</template>
|
|
211
|
-
|
|
212
|
-
<style module src="./Discussions.module.scss"></style>
|
|
4
|
+
|
|
5
|
+
import { icon__github } from '../../assets/icons'
|
|
6
|
+
import { REPO_NAME, AUTHOR } from '../constants'
|
|
7
|
+
import Tooltip from '../Tooltip/Tooltip.vue'
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
/**
|
|
11
|
+
* 留言版 ID
|
|
12
|
+
* 来自于笔记配置文件中的 id 字段的 uuid 值
|
|
13
|
+
*/
|
|
14
|
+
id: {
|
|
15
|
+
type: String,
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
/**
|
|
19
|
+
* 笔记序号(如 0001)
|
|
20
|
+
*/
|
|
21
|
+
noteNumber: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: '',
|
|
24
|
+
},
|
|
25
|
+
/**
|
|
26
|
+
* 笔记标题
|
|
27
|
+
*/
|
|
28
|
+
noteTitle: {
|
|
29
|
+
type: String,
|
|
30
|
+
default: '',
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// 🔍 查阅支持的所有主题 https://giscus.app/zh-CN
|
|
35
|
+
const GISCUS_DARK_THEME = 'noborder_dark'
|
|
36
|
+
const GISCUS_LIGHT_THEME = 'noborder_light'
|
|
37
|
+
|
|
38
|
+
// 获取 VitePress 的数据 - 主题状态
|
|
39
|
+
const { isDark } = useData()
|
|
40
|
+
|
|
41
|
+
// 生成 GitHub Discussions 直接链接
|
|
42
|
+
const githubDiscussionsUrl = computed(() => {
|
|
43
|
+
return `https://github.com/orgs/tnotesjs/discussions?discussions_q=${props.id}`
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 生成 giscus backlink(带有笔记信息的 GitHub 页面链接)
|
|
48
|
+
*
|
|
49
|
+
* giscus 会在创建新 Discussion 时自动添加返回链接。
|
|
50
|
+
* 通过设置 <meta name="giscus:backlink"> 标签,可以自定义这个链接。
|
|
51
|
+
* 这样在 GitHub Discussions 中就能看到对应笔记的直接链接。
|
|
52
|
+
*
|
|
53
|
+
* 📖 官方文档:https://github.com/giscus/giscus/blob/main/ADVANCED-USAGE.md#giscusbacklink
|
|
54
|
+
*/
|
|
55
|
+
const giscusBacklink = computed(() => {
|
|
56
|
+
console.log('[Discussions] Props:', {
|
|
57
|
+
noteNumber: props.noteNumber,
|
|
58
|
+
noteTitle: props.noteTitle,
|
|
59
|
+
id: props.id,
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
if (!props.noteNumber || !props.noteTitle) {
|
|
63
|
+
console.log('[Discussions] 使用默认 URL:', window.location.href)
|
|
64
|
+
return window.location.href
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 对笔记标题进行 URL 编码(处理中文和特殊字符)
|
|
68
|
+
const encodedTitle = encodeURIComponent(props.noteTitle)
|
|
69
|
+
|
|
70
|
+
// 生成笔记相关链接
|
|
71
|
+
const noteGithubUrl = `https://github.com/${AUTHOR}/${REPO_NAME}/tree/main/notes/${props.noteNumber}.%20${encodedTitle}`
|
|
72
|
+
const notePageUrl = `https://${AUTHOR.toLowerCase()}.github.io/${REPO_NAME}/notes/${
|
|
73
|
+
props.noteNumber
|
|
74
|
+
}.%20${encodedTitle}/README`
|
|
75
|
+
|
|
76
|
+
// 生成知识库相关链接
|
|
77
|
+
const repoGithubUrl = `https://github.com/${AUTHOR}/${REPO_NAME}`
|
|
78
|
+
const repoPageUrl = `https://${AUTHOR.toLowerCase()}.github.io/${REPO_NAME}/`
|
|
79
|
+
|
|
80
|
+
// 生成当前时间字符串
|
|
81
|
+
const now = new Date()
|
|
82
|
+
const year = now.getFullYear()
|
|
83
|
+
const month = String(now.getMonth() + 1).padStart(2, '0')
|
|
84
|
+
const day = String(now.getDate()).padStart(2, '0')
|
|
85
|
+
const weekDays = ['日', '一', '二', '三', '四', '五', '六']
|
|
86
|
+
const weekDay = `周${weekDays[now.getDay()]}`
|
|
87
|
+
const hour = now.getHours()
|
|
88
|
+
const minute = String(now.getMinutes()).padStart(2, '0')
|
|
89
|
+
const second = String(now.getSeconds()).padStart(2, '0')
|
|
90
|
+
const period = hour < 12 ? '上午' : '下午'
|
|
91
|
+
const hour12 = hour % 12 || 12
|
|
92
|
+
const formattedTime = `${year}.${month}.${day} ${weekDay} ${period} ${hour12}:${minute}:${second}`
|
|
93
|
+
|
|
94
|
+
// 构建 Markdown 格式的笔记信息
|
|
95
|
+
const backlink = `
|
|
96
|
+
- **${props.noteNumber}. ${props.noteTitle}**:[GitHub](${noteGithubUrl})、[GitHub Page](${notePageUrl})
|
|
97
|
+
- **${REPO_NAME}**:[GitHub](${repoGithubUrl})、[GitHub Page](${repoPageUrl})
|
|
98
|
+
- **评论创建时间**:${formattedTime}
|
|
99
|
+
`.trim()
|
|
100
|
+
|
|
101
|
+
console.log('[Discussions] 生成的 backlink:', backlink)
|
|
102
|
+
return backlink
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
// 动态注入 giscus backlink meta 标签
|
|
106
|
+
const updateGiscusBacklink = () => {
|
|
107
|
+
// 移除旧的 giscus:backlink meta 标签
|
|
108
|
+
const oldMeta = document.querySelector('meta[name="giscus:backlink"]')
|
|
109
|
+
if (oldMeta) {
|
|
110
|
+
oldMeta.remove()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// 添加新的 giscus:backlink meta 标签
|
|
114
|
+
const meta = document.createElement('meta')
|
|
115
|
+
meta.name = 'giscus:backlink'
|
|
116
|
+
meta.content = giscusBacklink.value
|
|
117
|
+
document.head.appendChild(meta)
|
|
118
|
+
|
|
119
|
+
console.log('[Discussions] 已添加 giscus:backlink meta 标签:', meta.content)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 动态注入 giscus 评论脚本
|
|
123
|
+
const loadGiscusScript = () => {
|
|
124
|
+
// 更新 giscus:backlink meta 标签
|
|
125
|
+
updateGiscusBacklink()
|
|
126
|
+
|
|
127
|
+
// 清除旧的 giscus 脚本和 iframe
|
|
128
|
+
const oldScript = document.getElementById('giscus-script')
|
|
129
|
+
const oldIframe = document.querySelector('iframe.giscus-frame')
|
|
130
|
+
if (oldScript) oldScript.remove()
|
|
131
|
+
if (oldIframe) oldIframe.remove()
|
|
132
|
+
|
|
133
|
+
// 创建新的 giscus 脚本
|
|
134
|
+
const giscusScript = document.createElement('script')
|
|
135
|
+
giscusScript.src = 'https://giscus.app/client.js'
|
|
136
|
+
giscusScript.setAttribute('data-repo', 'tnotesjs/TNotes.discussions')
|
|
137
|
+
giscusScript.setAttribute('data-repo-id', 'R_kgDOQauuyw')
|
|
138
|
+
giscusScript.setAttribute('data-category', 'Announcements')
|
|
139
|
+
giscusScript.setAttribute('data-category-id', 'DIC_kwDOQauuy84CyEuQ')
|
|
140
|
+
giscusScript.setAttribute('data-mapping', 'specific')
|
|
141
|
+
giscusScript.setAttribute('data-term', props.id)
|
|
142
|
+
giscusScript.setAttribute('data-strict', '0')
|
|
143
|
+
giscusScript.setAttribute('data-reactions-enabled', '1')
|
|
144
|
+
giscusScript.setAttribute('data-emit-metadata', '0')
|
|
145
|
+
giscusScript.setAttribute('data-input-position', 'top')
|
|
146
|
+
giscusScript.setAttribute('data-lang', 'zh-CN')
|
|
147
|
+
giscusScript.setAttribute('data-loading', 'lazy')
|
|
148
|
+
giscusScript.setAttribute(
|
|
149
|
+
'data-theme',
|
|
150
|
+
isDark.value ? GISCUS_DARK_THEME : GISCUS_LIGHT_THEME
|
|
151
|
+
)
|
|
152
|
+
giscusScript.setAttribute('crossorigin', 'anonymous')
|
|
153
|
+
giscusScript.async = true
|
|
154
|
+
giscusScript.id = 'giscus-script'
|
|
155
|
+
|
|
156
|
+
document.getElementById('giscus-comments')?.appendChild(giscusScript)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
onMounted(() => {
|
|
160
|
+
loadGiscusScript()
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
onUnmounted(() => {
|
|
164
|
+
// 组件卸载时移除 giscus:backlink meta 标签
|
|
165
|
+
const meta = document.querySelector('meta[name="giscus:backlink"]')
|
|
166
|
+
if (meta) {
|
|
167
|
+
meta.remove()
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
|
|
171
|
+
watch([() => props.id], ([newId]) => {
|
|
172
|
+
loadGiscusScript()
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
// 切换主题的时候,动态修改 giscus 评论主题,不需要重新 loadGiscusScript。
|
|
176
|
+
watch(isDark, (newVal) => {
|
|
177
|
+
const iframe = document.querySelector<HTMLIFrameElement>(
|
|
178
|
+
'iframe.giscus-frame'
|
|
179
|
+
)
|
|
180
|
+
if (iframe) {
|
|
181
|
+
iframe.contentWindow?.postMessage(
|
|
182
|
+
{
|
|
183
|
+
giscus: {
|
|
184
|
+
setConfig: {
|
|
185
|
+
theme: newVal ? GISCUS_DARK_THEME : GISCUS_LIGHT_THEME,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
'https://giscus.app'
|
|
190
|
+
)
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
</script>
|
|
194
|
+
|
|
195
|
+
<template>
|
|
196
|
+
<h2 :class="$style.h2">
|
|
197
|
+
<Tooltip text="在 GitHub 上发表评论(支持上传图片)">
|
|
198
|
+
<a
|
|
199
|
+
:href="githubDiscussionsUrl"
|
|
200
|
+
target="_blank"
|
|
201
|
+
rel="noopener noreferrer"
|
|
202
|
+
:class="$style.discussionsLink"
|
|
203
|
+
>
|
|
204
|
+
<img :src="icon__github" alt="" :class="$style.githubIcon" />
|
|
205
|
+
Discussions
|
|
206
|
+
</a>
|
|
207
|
+
</Tooltip>
|
|
208
|
+
</h2>
|
|
209
|
+
<div id="giscus-comments"></div>
|
|
210
|
+
</template>
|
|
211
|
+
|
|
212
|
+
<style module src="./Discussions.module.scss"></style>
|