feat(gitalk): add gitalk component for doc post commenting

This commit is contained in:
Anda Toshiki 2023-05-23 21:53:39 +08:00
parent 0e7892e1f2
commit aaeba78205
5 changed files with 2290 additions and 7 deletions

View File

@ -0,0 +1,80 @@
<template>
<div id="comment-container"></div>
</template>
<script lang="ts" setup>
import { reactive, toRefs, onMounted } from 'vue';
import { useData } from 'vitepress';
import md5 from 'blueimp-md5';
import $ from 'jquery';
import { Message } from '@arco-design/web-vue';
import '@arco-design/web-vue/es/message/style/css.js';
import Gitalk from 'gitalk';
import '../../styles/component/gitalk.scss';
//
const props = defineProps({
commentConfig: Object,
});
const data = reactive({
type: props.commentConfig?.type ?? 'gitalk',
})
const { type } = toRefs(data);
//
const { page } = useData();
let gitalk;
if (type.value && type.value == 'gitalk') {
gitalk = new Gitalk({
clientID: '938407aebb84fc7e93d9',
clientSecret: '7e18d4f1b541dde0a35725b19141341b308ea3d4',
repo: 'toshiki-notebook',
owner: 'andatoshiki',
admin: ['andatoshiki'],
id: md5(page.value.relativePath),
language: 'en-US',
distractionFreeMode: false,
// : https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token
proxy: 'https://vercel.andatoshiki.top/github_access_token',
});
}
//
onMounted(() => {
if (type.value && type.value == 'gitalk') {
gitalk.render('comment-container')
//
let $gc = $('#comment-container');
$gc.on('click', '.gt-comment-like', function () {
if (!window.localStorage.getItem('GT_ACCESS_TOKEN')) {
Message.warning({
content: 'Please login before you like',
closable: true
})
return false
}
return true
})
// bug
$gc.on('click', '.gt-header-controls .gt-btn-public', function () {
let $gt = $('.gt-header-textarea')
$gt.css('height', '72px')
})
//
$gc.on('click', '.gt-header-controls .gt-btn-preview', function () {
let pl = $('.gt-header-controls .gt-btn-public');
if (pl.hasClass('hide')) {
pl.removeClass('hide')
} else {
//
pl.addClass('hide')
}
})
}
})
</script>
<style scoped></style>

View File

@ -20,6 +20,10 @@ import CustomLayout from './CustomLayout.vue'
import AsideSponsors from './components/AsideSponsors.vue' import AsideSponsors from './components/AsideSponsors.vue'
// @ts-ignore // @ts-ignore
import Copyright from './components/Copyright.vue' import Copyright from './components/Copyright.vue'
// @ts-ignore
import Comment from './components/layout/Comment.vue'
// import CodeTitle from './components/CodeTitle.vue'
if (typeof window !== 'undefined') { if (typeof window !== 'undefined') {
// unregister PWA service // unregister PWA service
@ -61,6 +65,7 @@ export default {
// aside buttom slots for sponsor // aside buttom slots for sponsor
'aside-bottom': () => h(AsideSponsors), 'aside-bottom': () => h(AsideSponsors),
'doc-footer-before': () => h(Copyright), 'doc-footer-before': () => h(Copyright),
'doc-after': () => h(Comment)
}) })
}, },
@ -78,7 +83,8 @@ export default {
enhanceApp(ctx) { enhanceApp(ctx) {
// custom component tag/slot // custom component tag/slot
// ctx.app.component('Link', CardLink) // ctx.app.component('CardLink', CardLink)
// ctx.app.component('DPlayer', vue3videoPlay)
// external plugin for vitepress hack performance // external plugin for vitepress hack performance
vitepressNprogress(ctx) // nprogress plugin for vitepress vitepressNprogress(ctx) // nprogress plugin for vitepress

File diff suppressed because it is too large Load Diff

View File

@ -27,20 +27,24 @@
"devDependencies": { "devDependencies": {
"@andatoshiki/markdown-it-image-caption": "0.0.2", "@andatoshiki/markdown-it-image-caption": "0.0.2",
"@andatoshiki/vitepress-plugin-nprogress": "^0.0.1", "@andatoshiki/vitepress-plugin-nprogress": "^0.0.1",
"@arco-design/web-vue": "^2.46.0",
"@luckrya/markdown-it-link-to-card": "^0.3.3", "@luckrya/markdown-it-link-to-card": "^0.3.3",
"@mdit-vue/shared": "^0.12.0", "@mdit-vue/shared": "^0.12.0",
"@types/node": "^18.14.2", "@types/node": "^18.14.2",
"@vitejs/plugin-vue": "^4.0.0", "@vitejs/plugin-vue": "^4.0.0",
"artplayer": "^4.6.2", "artplayer": "^4.6.2",
"blueimp-md5": "^2.19.0",
"conventional-changelog-cli": "^2.2.2", "conventional-changelog-cli": "^2.2.2",
"dplayer": "^1.27.1", "dplayer": "^1.27.1",
"feed": "^4.2.2", "feed": "^4.2.2",
"flv.js": "^1.6.2", "flv.js": "^1.6.2",
"fs": "^0.0.1-security", "fs": "^0.0.1-security",
"fs-extra": "^11.1.1", "fs-extra": "^11.1.1",
"gitalk": "^1.8.0",
"gray-matter": "^4.0.3", "gray-matter": "^4.0.3",
"hls.js": "^1.3.5", "hls.js": "^1.3.5",
"husky": "^8.0.3", "husky": "^8.0.3",
"jquery": "^3.7.0",
"lint-staged": "^13.2.0", "lint-staged": "^13.2.0",
"markdown-it-link-preview": "^1.1.3", "markdown-it-link-preview": "^1.1.3",
"markdown-it-table-captions": "^1.0.4", "markdown-it-table-captions": "^1.0.4",

File diff suppressed because it is too large Load Diff