c/docs/.vitepress/theme/index.ts

71 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-08-01 04:00:11 +02:00
// .vitepress/theme/index.ts
import DefaultTheme from 'vitepress/theme'
import mediumZoom from 'medium-zoom'
import { onMounted, watch, nextTick } from 'vue'
import giscusTalk from 'vitepress-plugin-comment-with-giscus'
import { useData, useRoute } from 'vitepress'
import './style/index.css'
export default {
extends: DefaultTheme,
setup() {
// Get frontmatter and route
const { frontmatter } = useData()
const route = useRoute()
const initZoom = () => {
// mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' }); // 默认
mediumZoom('.main img', { background: 'var(--vp-c-bg)' }) // 不显式添加{data-zoomable}的情况下为所有图像启用此功能
};
onMounted(() => {
initZoom()
// 禁止 ios 缩放屏幕
document.addEventListener('gesturestart', function (event) {
event.preventDefault()
})
// 禁止移动端IOS双击页面变大
let touchTime = 0
document.addEventListener('touchstart', function (event) {
if (event.touches.length > 1) {
event.preventDefault()
}
})
document.addEventListener(
'touchend',
function (event) {
//记录当前点击的时间与下一次时间的间隔
const nowTime = new Date()
if (nowTime.getTime() - touchTime <= 300) {
event.preventDefault()
}
touchTime = nowTime.getTime()
},
false
);
})
watch(
() => route.path,
() => nextTick(() => initZoom())
);
// giscus配置
giscusTalk({
repo: 'Aexiar/Aexiar.github.io', //仓库
repoId: 'R_kgDOK820xg', //仓库ID
category: 'Announcements', // 讨论分类
categoryId: 'DIC_kwDOK820xs4Cb8sS', //讨论分类ID
mapping: 'pathname',
inputPosition: 'bottom',
lang: 'zh-CN',
},
{
frontmatter, route
},
//默认值为true表示已启用此参数可以忽略
//如果为false则表示未启用
//您可以使用“comment:true”序言在页面上单独启用它
true
)
}
}