优化:由于若干问题,暂时隐藏文章阅读数及评论组件
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
"vitepress": "^1.0.0-alpha.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@element-plus/icons-vue": "^2.0.6",
|
||||
"blueimp-md5": "^2.19.0",
|
||||
"dayjs": "^1.11.4",
|
||||
"element-plus": "^2.2.9",
|
||||
|
@@ -39,7 +39,8 @@ export const themeConfig: DefaultTheme.Config = {
|
||||
// 自定义扩展: 文章元数据配置
|
||||
articleMetadataConfig: {
|
||||
author: '查尔斯', // 文章全局默认作者名称
|
||||
authorLink: '/about/me' // 点击作者名时默认跳转的链接
|
||||
authorLink: '/about/me', // 点击作者名时默认跳转的链接
|
||||
showPv: false // 是否显示文章阅读数, 需配置好相应后端API接口
|
||||
},
|
||||
// 自定义扩展: 评论配置
|
||||
commentConfig: {
|
||||
@@ -47,14 +48,15 @@ export const themeConfig: DefaultTheme.Config = {
|
||||
options: {
|
||||
clientID: '1de126ce1fbdbe049709',
|
||||
clientSecret: '97e359a006ba7b0d8e9d9bf38b83de59eb69ecba',
|
||||
repo: 'https://github.com/Charles7c/charles7c.github.io-comments',
|
||||
repo: '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'
|
||||
// 默认: https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token
|
||||
// 感谢: https://prohibitorum.top/2022/07/26/%E8%A7%A3%E5%86%B3-Gitalk-%E6%97%A0%E6%B3%95%E8%8E%B7%E5%8F%96-Github-Token-%E9%97%AE%E9%A2%98/
|
||||
proxy: 'https://cors-server-ecru.vercel.app/github_access_token'
|
||||
},
|
||||
hideComments: false // 全局隐藏评论,默认 false
|
||||
hideComments: true // 全局隐藏评论,默认 false
|
||||
}
|
||||
}
|
@@ -1,24 +0,0 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const createBaseInstance = () => {
|
||||
const instance = axios.create({
|
||||
baseURL: 'http://62.234.119.173/blog',
|
||||
timeout: 3000
|
||||
})
|
||||
instance.interceptors.request.use(handleRequest, handleError)
|
||||
instance.interceptors.response.use(handleResponse, handleError)
|
||||
return instance
|
||||
}
|
||||
export const request = createBaseInstance()
|
||||
|
||||
function handleError(e) {
|
||||
throw e
|
||||
}
|
||||
|
||||
function handleRequest(request) {
|
||||
return request;
|
||||
}
|
||||
|
||||
function handleResponse(response) {
|
||||
return response.data
|
||||
}
|
@@ -1,3 +0,0 @@
|
||||
export * from './interface'
|
||||
|
||||
export { default } from './interface'
|
@@ -1,17 +0,0 @@
|
||||
import { request } from './config'
|
||||
|
||||
export const getPv = (id, call) => {
|
||||
request.get(`/pv/${id}`, {}).then(result => {
|
||||
call(process(result))
|
||||
})
|
||||
}
|
||||
|
||||
function process(result) {
|
||||
if (result.code === 1) {
|
||||
return result.data
|
||||
} else {
|
||||
console.log("系统异常:", result)
|
||||
}
|
||||
}
|
||||
|
||||
export default { getPv }
|
@@ -14,7 +14,7 @@
|
||||
</span>
|
||||
<time class="meta-content" :datetime="isoDatetime" :title="toDate">{{ datetime }}</time>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<div class="meta-item" v-if="theme.articleMetadataConfig?.showPv ?? false">
|
||||
<span class="meta-icon pv">
|
||||
<svg role="img" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg"><title>阅读数</title><path d="M942.2 486.2C847.4 286.5 704.1 186 512 186c-192.2 0-335.4 100.5-430.2 300.3-7.7 16.2-7.7 35.2 0 51.5C176.6 737.5 319.9 838 512 838c192.2 0 335.4-100.5 430.2-300.3 7.7-16.2 7.7-35 0-51.5zM512 766c-161.3 0-279.4-81.8-362.7-254C232.6 339.8 350.7 258 512 258c161.3 0 279.4 81.8 362.7 254C791.5 684.2 673.4 766 512 766z"></path><path d="M508 336c-97.2 0-176 78.8-176 176s78.8 176 176 176 176-78.8 176-176-78.8-176-176-176z m0 288c-61.9 0-112-50.1-112-112s50.1-112 112-112 112 50.1 112 112-50.1 112-112 112z"></path></svg>
|
||||
</span>
|
||||
@@ -29,7 +29,6 @@ import { useData } from 'vitepress'
|
||||
import dayjs from 'dayjs'
|
||||
import 'dayjs/locale/zh-cn'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import md5 from 'blueimp-md5'
|
||||
|
||||
// 获取发布时间
|
||||
const { page, theme, frontmatter } = useData()
|
||||
@@ -41,13 +40,6 @@ const datetime = date.value.toLocaleString('zh', {year: 'numeric', month: 'numer
|
||||
dayjs.extend(relativeTime)
|
||||
dayjs.locale('zh-cn')
|
||||
const toDate = dayjs().to(dayjs(frontmatter.value.date))
|
||||
|
||||
onMounted(() => {
|
||||
// 记录并获取文章阅读数
|
||||
$api.getPv(md5(page.value.relativePath), function(data) {
|
||||
document.getElementById("pv").innerText = data
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
@@ -66,7 +58,7 @@ onMounted(() => {
|
||||
font-size: 14px;
|
||||
}
|
||||
.meta-item:not(:last-child) {
|
||||
margin-right: 1.25rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
.meta-icon, meta-content {
|
||||
display: inline-block;
|
||||
|
@@ -1,22 +1,18 @@
|
||||
<template>
|
||||
<div v-if="!globalHideComments" id="comment-container"></div>
|
||||
<div id="comment-container"></div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted } from 'vue'
|
||||
import { useData } from 'vitepress'
|
||||
import md5 from 'blueimp-md5'
|
||||
import Gitalk from 'gitalk'
|
||||
import '../styles/gitalk.css'
|
||||
|
||||
const { theme, frontmatter } = useData()
|
||||
const { page, theme, frontmatter } = useData()
|
||||
const commentConfig = theme.value.commentConfig
|
||||
const globalHideComments = commentConfig.hideComments ?? false
|
||||
|
||||
onMounted(() => {
|
||||
if (globalHideComments) {
|
||||
return
|
||||
}
|
||||
|
||||
switch (commentConfig.type) {
|
||||
case 'gitalk':
|
||||
renderGitalk(commentConfig.options)
|
||||
@@ -38,10 +34,9 @@ function renderGitalk(options) {
|
||||
repo: options.repo,
|
||||
owner: options.owner,
|
||||
admin: options.admin,
|
||||
id: decodeURI(window.location.pathname),
|
||||
id: md5(page.value.relativePath),
|
||||
language: options.language,
|
||||
distractionFreeMode: options.distractionFreeMode,
|
||||
pagerDirection: options.pagerDirection,
|
||||
proxy: options.pagerDirection
|
||||
}
|
||||
|
||||
@@ -50,16 +45,6 @@ function renderGitalk(options) {
|
||||
|
||||
/*
|
||||
// 感谢: dingqianwen/my-blog
|
||||
// 访问量 如果不存在此标签,则进行创建
|
||||
if (!document.getElementsByClassName('browse—count')[0]) {
|
||||
let element = document.getElementsByClassName('page-meta')[0];
|
||||
let newElement = document.createElement('div');
|
||||
newElement.className = 'meta-item contributors browse—count';
|
||||
$api.pvIncr(md5(value.path), function (data) {
|
||||
newElement.innerHTML = `<span class="meta-item-label">浏览: </span><span class="meta-item-info">${data.toLocaleString('en-US')}</span>`;
|
||||
element.appendChild(newElement)
|
||||
})
|
||||
}
|
||||
// 如果点赞,先判断有没有登录
|
||||
let $gc = $('#gitalk-container');
|
||||
$gc.on('click', '.gt-comment-like', function () {
|
||||
|
@@ -3,7 +3,7 @@
|
||||
<div class="container">
|
||||
<p class="recordNo">
|
||||
<span class="icon">
|
||||
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M778.24 163.84c-76.8-40.96-165.888-61.44-269.312-61.44s-192.512 20.48-269.312 61.44h-133.12l23.552 337.92c8.192 113.664 67.584 217.088 162.816 280.576l215.04 144.384 215.04-144.384c96.256-63.488 155.648-166.912 163.84-280.576l23.552-337.92H778.24z m47.104 333.824c-7.168 94.208-56.32 181.248-135.168 233.472l-181.248 120.832L327.68 731.136c-78.848-53.248-129.024-139.264-135.168-233.472L173.056 225.28h136.192v-26.624c58.368-23.552 124.928-34.816 199.68-34.816s141.312 12.288 199.68 34.816V225.28H844.8l-19.456 272.384z"></path><path d="M685.056 328.704v-46.08H455.68c2.048-4.096 6.144-9.216 11.264-15.36 5.12-7.168 9.216-12.288 11.264-15.36L419.84 240.64c-31.744 46.08-75.776 87.04-133.12 123.904 4.096 4.096 10.24 11.264 18.432 21.504l17.408 17.408c23.552-15.36 45.056-31.744 63.488-50.176 26.624 25.6 49.152 43.008 67.584 51.2-46.08 15.36-104.448 27.648-175.104 35.84 2.048 5.12 6.144 13.312 9.216 24.576 4.096 11.264 6.144 19.456 7.168 24.576l39.936-7.168v218.112H389.12V680.96h238.592v19.456h54.272V481.28H348.16c60.416-12.288 114.688-27.648 163.84-46.08 49.152 19.456 118.784 34.816 210.944 46.08 5.12-17.408 10.24-34.816 17.408-51.2-62.464-4.096-116.736-12.288-161.792-24.576 38.912-20.48 74.752-46.08 106.496-76.8z m-150.528 194.56h94.208v41.984h-94.208v-41.984z m0 78.848h94.208v41.984h-94.208v-41.984z m-144.384-78.848h94.208v41.984H390.144v-41.984z m0 78.848h94.208v41.984H390.144v-41.984zM424.96 326.656h182.272c-26.624 22.528-57.344 41.984-94.208 57.344-31.744-15.36-61.44-34.816-88.064-57.344z"></path></svg>
|
||||
<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><title>备案号</title><path d="M778.24 163.84c-76.8-40.96-165.888-61.44-269.312-61.44s-192.512 20.48-269.312 61.44h-133.12l23.552 337.92c8.192 113.664 67.584 217.088 162.816 280.576l215.04 144.384 215.04-144.384c96.256-63.488 155.648-166.912 163.84-280.576l23.552-337.92H778.24z m47.104 333.824c-7.168 94.208-56.32 181.248-135.168 233.472l-181.248 120.832L327.68 731.136c-78.848-53.248-129.024-139.264-135.168-233.472L173.056 225.28h136.192v-26.624c58.368-23.552 124.928-34.816 199.68-34.816s141.312 12.288 199.68 34.816V225.28H844.8l-19.456 272.384z"></path><path d="M685.056 328.704v-46.08H455.68c2.048-4.096 6.144-9.216 11.264-15.36 5.12-7.168 9.216-12.288 11.264-15.36L419.84 240.64c-31.744 46.08-75.776 87.04-133.12 123.904 4.096 4.096 10.24 11.264 18.432 21.504l17.408 17.408c23.552-15.36 45.056-31.744 63.488-50.176 26.624 25.6 49.152 43.008 67.584 51.2-46.08 15.36-104.448 27.648-175.104 35.84 2.048 5.12 6.144 13.312 9.216 24.576 4.096 11.264 6.144 19.456 7.168 24.576l39.936-7.168v218.112H389.12V680.96h238.592v19.456h54.272V481.28H348.16c60.416-12.288 114.688-27.648 163.84-46.08 49.152 19.456 118.784 34.816 210.944 46.08 5.12-17.408 10.24-34.816 17.408-51.2-62.464-4.096-116.736-12.288-161.792-24.576 38.912-20.48 74.752-46.08 106.496-76.8z m-150.528 194.56h94.208v41.984h-94.208v-41.984z m0 78.848h94.208v41.984h-94.208v-41.984z m-144.384-78.848h94.208v41.984H390.144v-41.984z m0 78.848h94.208v41.984H390.144v-41.984zM424.96 326.656h182.272c-26.624 22.528-57.344 41.984-94.208 57.344-31.744-15.36-61.44-34.816-88.064-57.344z"></path></svg>
|
||||
</span>
|
||||
<span class="content">
|
||||
<a href="https://beian.miit.gov.cn/" target="_blank">{{ theme.footerConfig.recordNo }}</a>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<Layout>
|
||||
<template #doc-after>
|
||||
<Comment />
|
||||
<Comment v-if="!(theme.commentConfig?.hideComments ?? false)" />
|
||||
</template>
|
||||
<template #layout-bottom>
|
||||
<Copyright v-if="(theme.footerConfig?.showFooter ?? true) && (frontmatter?.showFooter ?? true)" />
|
||||
|
@@ -2,8 +2,6 @@ import DefaultTheme from 'vitepress/theme'
|
||||
import MyLayout from "./components/MyLayout.vue"
|
||||
import ElementPlus from 'element-plus'
|
||||
import "element-plus/dist/index.css"
|
||||
import * as ElIcons from '@element-plus/icons-vue'
|
||||
import api from './api/index'
|
||||
import ArticleMetadata from './components/ArticleMetadata.vue'
|
||||
import './styles/vars.css'
|
||||
import './styles/custom.css'
|
||||
@@ -11,18 +9,10 @@ import './styles/custom.css'
|
||||
export default {
|
||||
...DefaultTheme,
|
||||
Layout: MyLayout,
|
||||
enhanceApp({ app, router }) {
|
||||
// 全局注册ElementPlus的所有图标
|
||||
for (const [key, elIcon] of Object.entries(ElIcons)) {
|
||||
app.component(key, elIcon)
|
||||
}
|
||||
enhanceApp({ app }) {
|
||||
// 全局注册ElementPlus
|
||||
app.use(ElementPlus)
|
||||
|
||||
// 全局挂载api接口
|
||||
if (typeof window !== 'undefined') {
|
||||
window.$api = api
|
||||
}
|
||||
app.component('ArticleMetadata', ArticleMetadata)
|
||||
}
|
||||
}
|
@@ -14,7 +14,7 @@ hero:
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Get Started
|
||||
link: /categories/issues/
|
||||
link: /categories/issues/index.html
|
||||
- theme: alt
|
||||
text: View on GitHub
|
||||
link: https://github.com/Charles7c/charles7c.github.io
|
||||
|
Reference in New Issue
Block a user