修复:启用评论组件

This commit is contained in:
2022-08-13 23:30:56 +08:00
parent 6a3c5bbdd6
commit abd80c6b77
135 changed files with 2234 additions and 128 deletions

View File

@@ -0,0 +1,10 @@
const site = 'https://blog.charles7c.top'
export const metaData = {
lang: 'zh-CN',
locale: 'zh_CN',
title: '查尔斯的知识库',
description: '个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。',
site,
image: `${site}/logo.jpg`
}

View File

@@ -0,0 +1,20 @@
import type { HeadConfig } from 'vitepress'
import { metaData } from './constants'
export const head: HeadConfig[] = [
['link', { rel: 'icon', href: '/favicon.ico' }],
['meta', { name: 'author', content: 'Charles7c' }],
['meta', { name: 'keywords', content: '查尔斯的知识库, 知识库, 博客, Charles7c' }],
['meta', { name: 'HandheldFriendly', content: 'True' }],
['meta', { name: 'MobileOptimized', content: '320' }],
['meta', { name: 'theme-color', content: '#3c8772' }],
['meta', { property: 'og:type', content: 'website' }],
['meta', { property: 'og:locale', content: metaData.locale }],
['meta', { property: 'og:title', content: metaData.title }],
['meta', { property: 'og:description', content: metaData.description }],
['meta', { property: 'og:site', content: metaData.site }],
['meta', { property: 'og:site_name', content: metaData.title }],
['meta', { property: 'og:image', content: metaData.image }]
]

View File

@@ -0,0 +1,15 @@
import type { MarkdownOptions } from 'vitepress'
export const markdown: MarkdownOptions = {
theme: 'one-dark-pro', // Shiki主题, 所有主题参见: https://github.com/shikijs/shiki/blob/main/docs/themes.md
lineNumbers: true, // 启用行号
// 在所有文档的<h1>标签后添加<ArticleMetadata/>组件
config: (md) => {
md.renderer.rules.heading_close = (tokens, idx, options, env, slf) => {
let htmlResult = slf.renderToken(tokens, idx, options, env, slf)
if (tokens[idx].tag === 'h1') htmlResult += `\n<ArticleMetadata v-if="$frontmatter?.aside ?? true" :article="$frontmatter" />`
return htmlResult
}
}
}

View File

@@ -0,0 +1,38 @@
import DefaultTheme from 'vitepress/theme'
export const nav: DefaultTheme.Config['nav'] = [
{
text: '我的分类',
items: [
{ text: 'Bug万象集', link: '/categories/issues/index', activeMatch: '/categories/issues/' },
{ text: '"杂碎"逆袭史', link: '/categories/fragments/index', activeMatch: '/categories/fragments/' },
{ text: '方案春秋志', link: '/categories/solutions/index', activeMatch: '/categories/solutions/' }
],
activeMatch: '/categories/'
},
{
text: '我的小课',
items: [
{ text: 'MyBatis快速入门', link: '/courses/mybatis/index', activeMatch: '/courses/mybatis/' }
],
activeMatch: '/courses/'
},
{
text: '我的标签',
link: '/tags',
activeMatch: '/tags'
},
{
text: '我的归档',
link: '/archives',
activeMatch: '/archives'
},
{
text: '关于',
items: [
{ text: '关于知识库', link: '/about/index', activeMatch: '/about/index.html' },
{ text: '关于我', link: '/about/me', activeMatch: '/about/me.html' }
],
activeMatch: '/about/' // // 当前页面处于匹配路径下时, 对应导航菜单将突出显示
}
]

View File

@@ -0,0 +1,135 @@
import DefaultTheme from 'vitepress/theme'
import { sync } from 'fast-glob'
export const sidebar: DefaultTheme.Config['sidebar'] = {
'/categories/issues/': getItemsByDate("categories/issues"),
'/categories/fragments/': getItemsByDate("categories/fragments"),
'/categories/solutions/': getItemsByDate("categories/solutions"),
'/courses/mybatis/': getItems("courses/mybatis")
}
/**
* 根据 某分类/YYYY/MM/dd/xxx.md 的目录格式, 获取侧边栏分组及分组下标题
*
* /categories/issues/2022/07/20/xxx.md
*
* @param path 扫描基础路径
* @returns {DefaultTheme.SidebarGroup[]}
*/
function getItemsByDate (path: string) {
// 侧边栏分组数组
let groups: DefaultTheme.SidebarGroup[] = []
// 侧边栏分组下标题数组
let items: DefaultTheme.SidebarItem[] = []
// 1.获取所有年份目录
sync(`docs/${path}/*`, {
onlyDirectories: true,
objectMode: true
}).forEach(({ name }) => {
let year = name
// 2.获取所有月份目录
sync(`docs/${path}/${year}/*`, {
onlyDirectories: true,
objectMode: true
}).forEach(({ name }) => {
let month = name
// 3.获取所有日期目录
sync(`docs/${path}/${year}/${month}/*`, {
onlyDirectories: true,
objectMode: true
}).forEach(({ name }) => {
let day = name
// 4.获取日期目录下的所有文章
sync(`docs/${path}/${year}/${month}/${day}/*`, {
onlyFiles: true,
objectMode: true
}).forEach(({ name }) => {
// 向前追加标题
items.unshift({
text: name,
link: `/${path}/${year}/${month}/${day}/${name}`
})
})
})
// 5.向前追加到分组
if (items.length > 0) {
// 去除标题名中的扩展名
for (let i = 0; i < items.length; i++) {
let text = items[i].text
items[i].text = text.replace('.md', '')
}
groups.unshift({
text: `${year}${month}月 (${items.length}篇)`,
collapsible: true,
collapsed: true,
items: items
})
}
// 6.清空侧边栏分组下标题数组
items = []
})
})
// 7.将第一个侧边栏分组的标题展开
groups[0].collapsed = false
return groups
}
/**
* 根据 某小课/序号-分组/序号-xxx.md 的目录格式, 获取侧边栏分组及分组下标题
*
* courses/mybatis/01-MyBatis基础/01-xxx.md
*
* @param path 扫描基础路径
* @returns {DefaultTheme.SidebarGroup[]}
*/
function getItems (path: string) {
// 侧边栏分组数组
let groups: DefaultTheme.SidebarGroup[] = []
// 侧边栏分组下标题数组
let items: DefaultTheme.SidebarItem[] = []
// 1.获取所有分组目录
sync(`docs/${path}/*`, {
onlyDirectories: true,
objectMode: true
}).forEach(({ name }) => {
let groupName = name
// 2.获取分组下的所有文章
sync(`docs/${path}/${groupName}/*`, {
onlyFiles: true,
objectMode: true
}).forEach(({ name }) => {
// 向前追加标题
items.push({
text: name,
link: `/${path}/${groupName}/${name}`
})
})
// 3.向前追加到分组
if (items.length > 0) {
// 去除标题名中的前缀和扩展名
for (let i = 0; i < items.length; i++) {
let text = items[i].text
items[i].text = text.replace('.md', '').substring(text.indexOf('-') + 1)
}
groups.push({
text: `${groupName.substring(groupName.indexOf('-') + 1)} (${items.length}篇)`,
collapsible: true,
collapsed: true,
items: items
})
}
// 4.清空侧边栏分组下标题数组
items = []
})
// 5.将第一个侧边栏分组的标题展开
groups[0].collapsed = false
return groups
}

View File

@@ -0,0 +1,62 @@
import DefaultTheme from 'vitepress/theme'
import { nav } from './nav'
import { sidebar } from './sidebar'
export const themeConfig: DefaultTheme.Config = {
nav, // 导航栏配置
sidebar, // 侧边栏配置
logo: '/logo.png',
outlineTitle: '目录', // 右侧边栏的大纲标题文本配置
lastUpdatedText: '最后更新', // 最后更新时间文本配置, 需先配置lastUpdated为true
// 文档页脚文本配置
docFooter: {
prev: '上一篇',
next: '下一篇'
},
// 编辑链接配置
editLink: {
pattern: 'https://github.com/Charles7c/charles7c.github.io/edit/main/repos/:path',
text: '不妥之处,敬请雅正'
},
// 全文搜索配置
algolia: {
appId: 'DBZ0G9HBUY',
apiKey: '00cef480a543003d05d9808110ea5f65',
indexName: 'charles7c'
},
// 导航栏右侧社交链接配置
socialLinks: [
{ icon: 'github', link: 'https://github.com/Charles7c/charles7c.github.io' }
],
// 自定义扩展: 页脚配置
footerConfig: {
showFooter: true, // 是否显示页脚
icpRecordCode: '津ICP备2022005864号-2', // ICP备案号
publicSecurityRecordCode: '津公网安备12011202000677号', // 联网备案号
copyright: `Copyright © 2019-${new Date().getFullYear()} Charles7c` // 版权信息
},
// 自定义扩展: 文章元数据配置
articleMetadataConfig: {
author: '查尔斯', // 文章全局默认作者名称
authorLink: '/about/me', // 点击作者名时默认跳转的链接
showPv: false // 是否显示文章阅读数, 需配置好相应后端API接口
},
// 自定义扩展: 评论配置
commentConfig: {
type: 'gitalk',
options: {
clientID: '1de126ce1fbdbe049709',
clientSecret: '035fe49874a43e5cefc28a99b7e40b1925319c62',
repo: 'charles7c.github.io-comments',
owner: 'Charles7c',
admin: ['Charles7c'],
language: 'zh-CN',
distractionFreeMode: false,
// 默认: https://cors-anywhere.azm.workers.dev/https://github.com/login/oauth/access_token
proxy: 'https://cors-server-ecru.vercel.app/github_access_token'
},
showComment: true // 是否显示评论
}
}