@142vip/vuepress
Version:
VuePress使用的最佳实践,基于vuepress-theme-hope的封装
279 lines (273 loc) • 6.82 kB
JavaScript
import { navbar, sidebar, hopeTheme } from 'vuepress-theme-hope';
import viteBundler from '@vuepress/bundler-vite';
import path from 'node:path';
import process from 'node:process';
function getVuepressDefaultViteBundler() {
return viteBundler({
viteOptions: {
build: {
chunkSizeWarningLimit: 4096
}
},
vuePluginOptions: {}
});
}
function defineVipVuepressConfig(config) {
if (config.lang == null) {
config.lang = "zh-CN";
}
if (config.bundler == null) {
config.bundler = getVuepressDefaultViteBundler();
}
if (config.head == null) {
config.head = [
["link", { rel: "icon", href: "favicon.ico" }]
];
}
if (config.shouldPrefetch == null) {
config.shouldPrefetch = false;
}
return config;
}
function defineVipNavbarConfig(options) {
return navbar(options);
}
function defineVipSidebarConfig(options) {
return sidebar(options);
}
const VUEPRESS_DEFAULT_DOCS_DIR = "docs";
const slimSearchCNLocals = {
placeholder: "\u8BF7\u8F93\u5165\u9700\u8981\u641C\u7D22\u7684\u5173\u952E\u5B57",
search: "\u641C\u7D22\u6587\u6863",
searching: "\u641C\u7D22\u4E2D",
cancel: "\u53D6\u6D88",
select: "\u9009\u62E9",
navigate: "\u5207\u6362",
exit: "\u5173\u95ED",
loading: "\u6B63\u5728\u52AA\u529B\u641C\u7D22\u4E2D...",
queryHistory: "\u641C\u7D20\u6587\u5B57\u5386\u53F2",
resultHistory: "\u641C\u7D22\u7ED3\u679C",
emptyHistory: "\u6CA1\u6709\u641C\u7D22\u5386\u53F2",
emptyResult: "\u65E0\u6CD5\u627E\u5230\u76F8\u5173\u7ED3\u679C",
defaultTitle: "\u641C\u7D22\u6587\u6863",
autocomplete: "\u81EA\u52A8\u8865\u9F50"
};
const baseThemePluginOptions = {
// comment:{
// provider: "Artalk",
// server:"https://test.142vip.cn/",
// site:'JavaScriptCollection',
// },
// 公告 参考:https://theme-hope.vuejs.press/zh/guide/feature/notice.html
// notice: [
// {
// path: '/',
// title: '在线浏览',
// content: '网站无法访问时,建议通过科学上网访问备用网络',
// actions: [
// {
// text: '尝鲜版',
// link: 'https://142vip.github.io/JavaScriptCollection',
// type: 'default',
// },
// {
// text: '稳定版',
// link: 'https://code.142vip.cn',
// type: 'primary',
// },
// ],
// fullscreen: false,
// },
// ],
// 阅读时间
readingTime: {
wordPerMinute: 100
},
// 水印
watermark: {
enabled: false
},
copyright: false,
// 开启博客功能
blog: false,
// 图片增强,参考:https://ecosystem.vuejs.press/zh/plugins/markdown/markdown-image.html
// markdownImage: markdownImagePlugin({
// // 启用 figure
// figure: true,
// // 启用图片懒加载
// lazyload: true,
// // 启用图片标记
// mark: true,
// // 启用图片大小
// size: true,
// }),
copyCode: {
showInMobile: true
},
// 不自动生成README目录
catalog: false,
// 参考:https://theme-hope.vuejs.press/zh/guide/markdown/components.html
// components: {
// components: [
// 'Badge',
// 'BiliBili',
// 'CodePen',
// 'PDF',
// 'StackBlitz',
// 'VidStack',
// 'Share',
// 'XiGua',
// ],
// },
slimsearch: {
// 参考:https://ecosystem.vuejs.press/zh/plugins/search/slimsearch.html
locales: {
"/": slimSearchCNLocals
}
},
nprogress: true,
// 开发环境,开启git记录
git: true
};
const baseThemeOptions = {
// 多语言配置
// locales: {
// '/': {
// lang: 'zh-CN',
// },
// },
// navbarIcon: false,
// 在深色模式和浅色模式之间切换
darkmode: "toggle",
// 支持全屏
// fullscreen: true,
// 纯净模式
// pure: true,
// 博客配置
// blog: {
// name: '测试',
// avatar: '',
// description: '',
// intro: '',
// roundAvatar: true,
// timeline: "时间轴的顶部文字",
// // articleInfo: "",
// medias: {
// "BiliBili": "https://space.bilibili.com/350937042?spm_id_from=333.1007.0.0"
// }
// },
// 打印按钮
print: false,
hostname: "https://142vip.cn",
// 默认作者,https://theme-hope.vuejs.press/zh/config/theme/basic.html#author
// author: OPEN_SOURCE_AUTHOR,
favicon: "/favicon.ico",
logo: "/favicon.icon",
// 导航栏布局
navbarLayout: {
start: ["Brand"],
center: [],
end: ["Links", "Language", "Search", "Outlook", "Repo"]
},
pageInfo: [
"Author",
"Original",
"Date",
"Category",
"Tag",
"ReadingTime"
],
docsDir: "docs",
docsBranch: "next",
// 主题布局选项
// docsRepo: RepoAddress,
// repo: '142vip/JavaScriptCollection',
repoLabel: "GitHub",
// 是否在导航栏内显示仓库链接,默认为 `true`
repoDisplay: true,
// https://ecosystem.vuejs.press/zh/plugins/development/git.html#changelog
changelog: true,
contributors: "content",
// 主题色选择器
themeColor: true,
// 是否显示外部链接图标
externalLinkIcon: false,
// 设置页脚
displayFooter: true,
// footer: getFooterHtml({
// name: '',
// version: '',
// }),
// copyright: getCopyRightText(''),
// 插件配置
plugins: baseThemePluginOptions,
// 文档配置
markdown: {
// 支持任务列表
tasklist: true,
playground: {
presets: ["ts", "vue"]
},
sub: true,
sup: true,
vPre: true,
vuePlayground: true,
// 文件导入配置别名
include: true,
// mermaid
mermaid: true,
// 自定义对齐
align: true,
tabs: true,
codeTabs: true,
highlighter: {
// 参考:https://shiki.tmrs.site/languages
langs: [
"ts",
"js",
"vue",
"json",
"json5",
"jsonc",
"jsx",
"lua",
"diff",
"c",
"c++",
"dockerfile",
"nginx",
"proto",
"java",
"javascript",
"typescript",
"yaml",
"text",
"graphql",
"http",
"python",
"xml"
]
}
}
};
function getVipHopeTheme(userConfig) {
return hopeTheme({
...baseThemeOptions,
...userConfig,
plugins: {
...baseThemePluginOptions,
...userConfig.plugins
}
});
}
function handleImportCodePath(pathArray, cwd) {
return (str) => {
for (const [oldPath, newPath] of pathArray) {
if (str.includes(oldPath)) {
return str.replace(oldPath, path.resolve(cwd ?? process.cwd(), newPath));
}
}
return str;
};
}
export { VUEPRESS_DEFAULT_DOCS_DIR, baseThemePluginOptions, defineVipNavbarConfig, defineVipSidebarConfig, defineVipVuepressConfig, getVipHopeTheme, handleImportCodePath };