diff --git a/package.json b/package.json index 63609b061..9de8ed6c0 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,7 @@ "dayjs": "^1.11.4", "element-plus": "^2.2.9", "fast-glob": "^3.2.11", + "gitalk": "^1.7.2", "vue": "^3.2.37" } } diff --git a/repos/.vitepress/config/theme.ts b/repos/.vitepress/config/theme.ts index eb15797ef..38bfcbef7 100644 --- a/repos/.vitepress/config/theme.ts +++ b/repos/.vitepress/config/theme.ts @@ -38,5 +38,21 @@ export const themeConfig: DefaultTheme.Config = { articleMetadataConfig: { author: '查尔斯', // 文章全局默认作者名称 authorLink: '/about/me' // 点击作者名时默认跳转的链接 + }, + // 评论配置 + commentConfig: { + type: 'gitalk', + options: { + clientID: '1de126ce1fbdbe049709', + clientSecret: '97e359a006ba7b0d8e9d9bf38b83de59eb69ecba', + repo: 'https://github.com/Charles7c/charles7c.github.io-comments', + owner: 'Charles7c', + admin: ['Charles7c'], + language: 'zh-CN', + distractionFreeMode: false, + pagerDirection: 'last', // 按评论创建时间倒序排序 + proxy: 'https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token' + }, + hideComments: false // 全局隐藏评论,默认 false } } \ No newline at end of file diff --git a/repos/.vitepress/theme/components/ArticleMetadata.vue b/repos/.vitepress/theme/components/ArticleMetadata.vue index b6ad73011..be8ff4fc6 100644 --- a/repos/.vitepress/theme/components/ArticleMetadata.vue +++ b/repos/.vitepress/theme/components/ArticleMetadata.vue @@ -28,18 +28,12 @@ import relativeTime from 'dayjs/plugin/relativeTime' const { theme, frontmatter } = useData() const date = computed(() => new Date(frontmatter.value.date)) const isoDatetime = computed(() => date.value.toISOString()) -const datetime = ref('') +const datetime = date.value.toLocaleString('zh', {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'}) // 获取发布时间的相对时间, 例如: 1天前、2周前、3个月前、4年前 dayjs.extend(relativeTime) dayjs.locale('zh-cn') const toDate = dayjs().to(dayjs(frontmatter.value.date)) - -onMounted(() => { - watchEffect(() => { - datetime.value = date.value.toLocaleString(window.navigator.language, {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'}) - }) -}) \ No newline at end of file diff --git a/repos/.vitepress/theme/components/MyLayout.vue b/repos/.vitepress/theme/components/MyLayout.vue index fa140ea4c..a2a1eca2f 100644 --- a/repos/.vitepress/theme/components/MyLayout.vue +++ b/repos/.vitepress/theme/components/MyLayout.vue @@ -1,13 +1,14 @@