Skip to content

Commit 5a7bd7c

Browse files
committed
Update: 添加 Artalk 评论区
1 parent 8843c7c commit 5a7bd7c

File tree

10 files changed

+87
-18
lines changed

10 files changed

+87
-18
lines changed

.vitepress/themeConfig.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ export default {
1212
],
1313
// 左上角标题图标
1414
logo: '/logo-op0.png',
15+
// 评论配置
16+
comments: {
17+
type: 'artalk',
18+
options: {
19+
server: 'http://artalk.namichong.com',
20+
site: 'Hi! Tmiracle'
21+
}
22+
},
1523
search: {
1624
provider: 'local',
1725
options: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@element-plus/icons-vue": "^2.3.1",
1414
"@vueuse/core": "^12.2.0",
15+
"artalk": "^2.9.1",
1516
"element-plus": "^2.9.1",
1617
"floating-vue": "^5.2.2",
1718
"lodash-es": "^4.17.21",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<template>
2+
<div v-if="type === 'artalk' && visible" class="relative w-full h-a my-12">
3+
<div class="h-1px w-full bg-gray-300"/>
4+
<strong class="block text-[calc(var(--base-size)*1.2)]! my-4!">大佬~留个评论吧~</strong>
5+
<div id="comment"/>
6+
</div>
7+
</template>
8+
9+
<script setup lang="ts">
10+
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
11+
import { useData, useRoute } from 'vitepress';
12+
import 'artalk/Artalk.css';
13+
import Artalk from 'artalk';
14+
15+
const route = useRoute();
16+
const { site: _site, frontmatter } = useData();
17+
const { type, options: { server, site } } = _site.value.themeConfig.comments;
18+
const artalk = ref<Artalk | null>(null);
19+
const visible = ref(false);
20+
21+
function init() {
22+
artalk.value?.destroy();
23+
if (frontmatter.value.comment === false) {
24+
visible.value = false;
25+
} else {
26+
visible.value = true;
27+
nextTick(() => {
28+
artalk.value = Artalk.init({
29+
el: '#comment',
30+
pageKey: route.path,
31+
server,
32+
site
33+
});
34+
});
35+
}
36+
}
37+
38+
watch(() => route.path, () => {
39+
init();
40+
});
41+
42+
onMounted(() => {
43+
init();
44+
});
45+
46+
onUnmounted(() => {
47+
artalk.value?.destroy();
48+
});
49+
</script>
50+
51+
<style scoped lang="scss">
52+
53+
</style>

package/components/NanoMain/index.vue

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,26 @@
1515
defer
1616
@os-initialized="scrollbarInitialized"
1717
>
18-
<article
19-
ref="article"
20-
class="vp-doc VPDoc text-[var(--base-size)]"
21-
:class="[ 'w-full' ]"
22-
style="white-space: wrap;"
23-
:style="{ padding: articlePadding }"
24-
>
25-
<Content/>
26-
</article>
27-
<slot name="contentAfter">
28-
<!--<NanoGiscus/>-->
29-
</slot>
18+
<div :style="{ padding: articlePadding }">
19+
<article
20+
ref="article"
21+
class="vp-doc VPDoc text-[var(--base-size)]"
22+
:class="[ 'w-full' ]"
23+
style="white-space: wrap;"
24+
>
25+
<Content/>
26+
</article>
27+
<slot name="contentAfter">
28+
<NanoComment/>
29+
</slot>
30+
</div>
3031
</OverlayScrollbarsComponent>
3132
</div>
3233
</div>
3334
</template>
3435

3536
<script setup lang="ts">
36-
// import NanoGiscus from '@NanoUI/NanoGiscus/index.vue';
37+
import NanoComment from '@NanoUI/NanoComment/index.vue';
3738
import 'overlayscrollbars/styles/overlayscrollbars.css';
3839
import scrollbarOptions from '../../config/scrollbarOptions';
3940
import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue';

package/components/NanoSidebarDirItemTree/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
<div class="relative w-auto whitespace-nowrap">
33
<div class="relative cursor-pointer select-none rounded-2">
44
<div
5-
class="flex items-center flex-nowrap gap-[calc(var(--base-size)*.25)] py-[calc(var(--base-size)*.125)] w-auto"
5+
class="py-[calc(var(--base-size)*.15)] w-auto"
66
:class="setClass"
77
:style="{ paddingLeft: `calc(var(--base-size)*${ level })` }"
88
un-hover="bg-[var(--sidebar-hover-bg)]"
9+
un-flex="~ items-center nowrap gap-[calc(var(--base-size)*.25)]"
910
@click.stop="collapse"
1011
>
1112
<div class="w-[calc(var(--base-size)*1)] h-[calc(var(--base-size)*1)] shrink-0">
@@ -18,7 +19,7 @@
1819
<div class="menu-icon flex-center" v-html="item.icon"/>
1920
<div
2021
class="text-[calc(var(--base-size)*.975)]!"
21-
:class="[ item.link ? '' : 'text-blue-500' ]"
22+
:class="[ item.link ? 'text-gray-6' : 'text-blue-500' ]"
2223
v-text="item.text"
2324
/>
2425
</div>

package/theme/light/var.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
.nano-theme {
1010
--scale: 0;
11-
--base-size: calc((var(--scale) * 1px) + 14px);
11+
--base-size: calc((var(--scale) * 1px) + 16px);
1212

1313
* {
1414
font-size: var(--base-size);

package/type.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { DefaultTheme } from 'vitepress/types/default-theme';
2-
import type { GiscusProps } from '@giscus/vue/dist/types';
32

43
export type SidebarType = DefaultTheme.SidebarItem & { id?: string, icon?: string, items?: SidebarType[] };
54

@@ -8,5 +7,8 @@ export type ThemeConfig = DefaultTheme.Config & {
87
motto: string;
98
backgrounds?: string[];
109
aboutMePath: string;
11-
giscus?: GiscusProps;
10+
comments?: {
11+
type: 'custom' | 'artalk';
12+
options: object;
13+
}
1214
}

src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---
22
layout: home
33
title: 首页
4+
comment: false
45
---

src/nav/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: page
33
title: 资源导航
4+
comment: false
45
---
56

67
<Nav/>

src/translation-docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
layout: page
33
title: 文档翻译
4+
comment: false
45
---
56

67
<Doc/>

0 commit comments

Comments
 (0)