diff --git a/package.json b/package.json index 5b5b85bd1..981c61422 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "MyRepos", + "name": "my-repos", "version": "1.0.0", "description": "Charles's personal knowledge repositories.", "main": "index.js", @@ -12,7 +12,10 @@ }, "devDependencies": { "vitepress": "^1.0.0-alpha.4", - "vue": "^3.2.37", - "fast-glob": "^3.2.11" + "vue": "^3.2.37" + }, + "dependencies": { + "fast-glob": "^3.2.11", + "element-plus": "^2.2.9" } } diff --git a/repos/.vitepress/config.ts b/repos/.vitepress/config.ts index aca091795..23a697f88 100644 --- a/repos/.vitepress/config.ts +++ b/repos/.vitepress/config.ts @@ -1,142 +1,21 @@ -import { defineConfig, type DefaultTheme } from 'vitepress' -import { sync } from "fast-glob" +import { defineConfig } from 'vitepress' +import { metaData } from './config/constants' +import { head } from './config/head' +import { themeConfig } from './config/theme' export default defineConfig({ - lang: 'zh-CN', - title: '查尔斯的知识库', - description: '个人知识库,记录 & 分享个人碎片化、结构化、体系化的知识内容。', + lang: metaData.lang, + title: metaData.title, + description: metaData.description, + + head, // 内标签配置 + themeConfig, // 主题配置 + lastUpdated: true, // 显示最后更新时间 - // 内标签配置 - head: [ - ['link', { rel: 'icon', href: '/favicon.ico' }] - ], // Markdown配置 markdown: { - theme: 'material-palenight', - // lineNumbers: true - }, - - // 主题配置 - themeConfig: { - logo: '/logo.jpg', - outlineTitle: '目录', // 右侧边栏的大纲标题文本 - // 编辑链接 - editLink: { - pattern: 'https://github.com/Charles7c/charles7c.github.io/edit/main/repos/:path', - text: '在 GitHub 上编辑此页面' - }, - lastUpdatedText: '最后更新', // 最后更新时间文本, 需配置 lastUpdated 为 true - docFooter: { - prev: '上一页', - next: '下一页' - }, - // 版权标识 - footer: { - message: 'Released under the MIT License.', - copyright: 'Copyright © 2019-present Charles7c' - }, - // 社交链接 - socialLinks: [ - { icon: 'github', link: 'https://github.com/Charles7c/charles7c.github.io' } - ], - // 全文搜索 - algolia: { - appId: 'DBZ0G9HBUY', - apiKey: '00cef480a543003d05d9808110ea5f65', - indexName: 'charles7c' - }, - - // 导航栏 - nav: nav(), - - // 侧边栏 - sidebar: { - '/issues/': getItems("issues"), - '/fragments/': getItems("fragments"), - '/about/': [ - { - items: [ - { text: '关于笔者', link: '/about/me' } - ] - } - ] - } + theme: 'one-dark-pro', // Shiki主题, 所有主题参见: https://github.com/shikijs/shiki/blob/main/docs/themes.md + lineNumbers: true // 启用行号 } -}) - -/** - * 获取导航栏 - */ -function nav() { - return [ - { - text: 'Bug万象集', - link: '/issues/index' - }, - { - text: '"杂碎"逆袭史', - link: '/fragments/index' - }, - { - text: '关于知识库', - link: '/about/index' - } - ] -} - -/** - * 获取侧边栏分组及分组下标题 - * - * @param path 扫描基础路径 - * @returns {DefaultTheme.SidebarGroup[]} - */ -function getItems (path: string) { - // 侧边栏分组数组 - let groups: DefaultTheme.SidebarGroup[] = [] - // 侧边栏分组下标题数组 - let items: DefaultTheme.SidebarItem[] = [] - - // 1.获取所有年份目录 - sync(`repos/${path}/*`, { - onlyDirectories: true, - objectMode: true, - }).forEach(({ name }) => { - let year = name - for (let i = 1; i <= 12; i++) { - let month = i < 10 ? `0${i}` : i - // 2.获取所有月份目录下的文章 - sync(`repos/${path}/${year}/${month}/*`, { - objectMode: true, - }).forEach(({ name }) => { - // 向前追加标题 - items.unshift({ - text: name, - link: `/${path}/${year}/${month}/${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.unshift({ - text: `${year}年${month}月 (${items.length}篇)`, - collapsible: true, - collapsed: true, - items: items - }) - } - - // 4.清空侧边栏分组下标题数组 - items = [] - } - }) - - // 5.将第一个侧边栏分组的标题展开 - groups[0].collapsed = false - return groups -} \ No newline at end of file +}) \ No newline at end of file diff --git a/repos/.vitepress/config/constants.ts b/repos/.vitepress/config/constants.ts new file mode 100644 index 000000000..6afd8d880 --- /dev/null +++ b/repos/.vitepress/config/constants.ts @@ -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` +} \ No newline at end of file diff --git a/repos/.vitepress/config/head.ts b/repos/.vitepress/config/head.ts new file mode 100644 index 000000000..d0d70a3f0 --- /dev/null +++ b/repos/.vitepress/config/head.ts @@ -0,0 +1,19 @@ +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', { 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 }] +] \ No newline at end of file diff --git a/repos/.vitepress/config/nav.ts b/repos/.vitepress/config/nav.ts new file mode 100644 index 000000000..c8109004d --- /dev/null +++ b/repos/.vitepress/config/nav.ts @@ -0,0 +1,19 @@ +import type { DefaultTheme } from 'vitepress' + +export const nav: DefaultTheme.Config['nav'] = [ + { + text: 'Bug万象集', + link: '/issues/index', + activeMatch: '/issues/' // 当前页面处于匹配路径下时, 对应导航菜单将突出显示 + }, + { + text: '"杂碎"逆袭史', + link: '/fragments/index', + activeMatch: '/fragments/' + }, + { + text: '关于知识库', + link: '/about/index', + activeMatch: '/about/', + } +] \ No newline at end of file diff --git a/repos/.vitepress/config/sidebar.ts b/repos/.vitepress/config/sidebar.ts new file mode 100644 index 000000000..61f412d5e --- /dev/null +++ b/repos/.vitepress/config/sidebar.ts @@ -0,0 +1,70 @@ +import type { DefaultTheme } from 'vitepress' +import { sync } from "fast-glob" + +export const sidebar: DefaultTheme.Config['sidebar'] = { + '/issues/': getItems("issues"), + '/fragments/': getItems("fragments"), + '/about/': [ + { + items: [ + { text: '关于笔者', link: '/about/me' } + ] + } + ] +} + +/** + * 获取侧边栏分组及分组下标题 + * + * @param path 扫描基础路径 + * @returns {DefaultTheme.SidebarGroup[]} + */ +function getItems (path: string) { + // 侧边栏分组数组 + let groups: DefaultTheme.SidebarGroup[] = [] + // 侧边栏分组下标题数组 + let items: DefaultTheme.SidebarItem[] = [] + + // 1.获取所有年份目录 + sync(`repos/${path}/*`, { + onlyDirectories: true, + objectMode: true, + }).forEach(({ name }) => { + let year = name + for (let i = 1; i <= 12; i++) { + let month = i < 10 ? `0${i}` : i + // 2.获取所有月份目录下的文章 + sync(`repos/${path}/${year}/${month}/*`, { + objectMode: true, + }).forEach(({ name }) => { + // 向前追加标题 + items.unshift({ + text: name, + link: `/${path}/${year}/${month}/${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.unshift({ + text: `${year}年${month}月 (${items.length}篇)`, + collapsible: true, + collapsed: true, + items: items + }) + } + + // 4.清空侧边栏分组下标题数组 + items = [] + } + }) + + // 5.将第一个侧边栏分组的标题展开 + groups[0].collapsed = false + return groups +} \ No newline at end of file diff --git a/repos/.vitepress/config/theme.ts b/repos/.vitepress/config/theme.ts new file mode 100644 index 000000000..a92d54de2 --- /dev/null +++ b/repos/.vitepress/config/theme.ts @@ -0,0 +1,35 @@ +import type { DefaultTheme } from 'vitepress' +import { nav } from './nav' +import { sidebar } from './sidebar' + +export const themeConfig: DefaultTheme.Config = { + logo: '/logo.jpg', + outlineTitle: '目录', // 右侧边栏的大纲标题文本 + lastUpdatedText: '最后更新', // 最后更新时间文本, 需配置 lastUpdated 为 true + docFooter: { + prev: '上一页', + next: '下一页' + }, + // 编辑链接 + editLink: { + pattern: 'https://github.com/Charles7c/charles7c.github.io/edit/main/repos/:path', + text: '在 GitHub 上编辑此页面' + }, + // 版权标识 + footer: { + message: 'Released under the MIT License.', + copyright: `Copyright © 2019-${new Date().getFullYear()} Charles7c` + }, + // 全文搜索 + algolia: { + appId: 'DBZ0G9HBUY', + apiKey: '00cef480a543003d05d9808110ea5f65', + indexName: 'charles7c' + }, + // 社交链接 + socialLinks: [ + { icon: 'github', link: 'https://github.com/Charles7c/charles7c.github.io' } + ], + nav, // 导航栏 + sidebar // 侧边栏 +} \ No newline at end of file diff --git a/repos/.vitepress/theme/custom.css b/repos/.vitepress/theme/custom.css new file mode 100644 index 000000000..8768db1e1 --- /dev/null +++ b/repos/.vitepress/theme/custom.css @@ -0,0 +1,5 @@ +.vp-doc h2 { + margin: 15px 0 16px; + padding-top: 10px; + border-top: none; +} \ No newline at end of file diff --git a/repos/.vitepress/theme/index.ts b/repos/.vitepress/theme/index.ts new file mode 100644 index 000000000..deac68a3b --- /dev/null +++ b/repos/.vitepress/theme/index.ts @@ -0,0 +1,9 @@ +import DefaultTheme from 'vitepress/theme' +import './custom.css' + +export default { + ...DefaultTheme, + enhanceApp({ app }) { + // register global components + } +} \ No newline at end of file