@nolebase/integrations
Version:
A unconfig (unified configurations) for both VitePress and VitePress theme. Supporting all Nólëbase Integrations with default theme.
118 lines (112 loc) • 5.83 kB
JavaScript
'use strict';
const defu = require('defu');
const client = require('@nolebase/vitepress-plugin-enhanced-readabilities/client');
const client$1 = require('@nolebase/vitepress-plugin-highlight-targeted-heading/client');
const vue = require('vue');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
const defu__default = /*#__PURE__*/_interopDefaultCompat(defu);
function newArrayOfOrPush(object, property, item) {
if (object[property]) {
object[property].push(item);
return;
}
object[property] = [item];
}
function presetClient(options) {
const opts = defu__default(options, {
enhancedMark: true,
enhancedReadabilities: {
options: {
layoutSwitch: { defaultMode: client.LayoutMode.SidebarWidthAdjustableOnly },
spotlight: { defaultToggle: true }
}
},
gitChangelog: {
options: {
commitsRelativeTime: true
}
},
highlightTargetedHeading: true,
index: true,
inlineLinkPreview: true,
pageProperties: {
options: {
properties: {
"en": [
{ key: "tags", type: "tags", title: "Tags" },
{ key: "progress", type: "progress", title: "Progress" },
{ key: "createdAt", type: "datetime", title: "Created at", formatAsFrom: true, dateFnsLocaleName: "enUS" },
{ key: "updatedAt", type: "datetime", title: "Updated at", formatAsFrom: true, dateFnsLocaleName: "enUS" },
{ key: "wordsCount", type: "dynamic", title: "Word count", options: { type: "wordsCount" } },
{ key: "readingTime", type: "dynamic", title: "Reading time", options: { type: "readingTime", dateFnsLocaleName: "enUS" } }
],
"zh-CN": [
{ key: "tags", type: "tags", title: "\u6807\u7B7E" },
{ key: "progress", type: "progress", title: "\u8FDB\u5EA6" },
{ key: "createdAt", type: "datetime", title: "\u521B\u5EFA\u65F6\u95F4", formatAsFrom: true, dateFnsLocaleName: "zhCN" },
{ key: "updatedAt", type: "datetime", title: "\u66F4\u65B0\u65F6\u95F4", formatAsFrom: true, dateFnsLocaleName: "zhCN" },
{ key: "wordsCount", type: "dynamic", title: "\u5B57\u6570", options: { type: "wordsCount" } },
{ key: "readingTime", type: "dynamic", title: "\u9605\u8BFB\u65F6\u95F4", options: { type: "readingTime", dateFnsLocaleName: "zhCN" } }
]
}
}
},
thumbnailHash: true
});
return {
enhanceLayout() {
const slots = {};
if (opts.highlightTargetedHeading)
newArrayOfOrPush(slots, "doc-top", () => vue.h(client$1.NolebaseHighlightTargetedHeading));
if (opts.enhancedReadabilities) {
newArrayOfOrPush(slots, "nav-bar-content-after", () => vue.h(client.NolebaseEnhancedReadabilitiesMenu));
newArrayOfOrPush(slots, "nav-screen-content-after", () => vue.h(client.NolebaseEnhancedReadabilitiesScreenMenu));
}
return slots;
},
async enhanceApp({ app }) {
if (opts.enhancedReadabilities) {
const { NolebaseEnhancedReadabilitiesPlugin } = await import('@nolebase/vitepress-plugin-enhanced-readabilities/client');
await import('@nolebase/vitepress-plugin-enhanced-readabilities/client/style.css');
const enhancedReadabilitiesOptions = opts.enhancedReadabilities?.options ? [opts.enhancedReadabilities.options] : [];
app.use(NolebaseEnhancedReadabilitiesPlugin, ...enhancedReadabilitiesOptions);
}
if (opts.highlightTargetedHeading) {
const { NolebaseNolebaseHighlightTargetedHeadingPlugin } = await import('@nolebase/vitepress-plugin-highlight-targeted-heading/client');
await import('@nolebase/vitepress-plugin-highlight-targeted-heading/client/style.css');
app.use(NolebaseNolebaseHighlightTargetedHeadingPlugin);
}
if (opts.inlineLinkPreview) {
const { NolebaseInlineLinkPreviewPlugin } = await import('@nolebase/vitepress-plugin-inline-link-preview/client');
await import('@nolebase/vitepress-plugin-inline-link-preview/client/style.css');
const linkPreviewOptions = opts.inlineLinkPreview?.options ? [opts.inlineLinkPreview.options] : [];
app.use(NolebaseInlineLinkPreviewPlugin, ...linkPreviewOptions);
}
if (opts.gitChangelog) {
const { NolebaseGitChangelogPlugin } = await import('@nolebase/vitepress-plugin-git-changelog/client');
await import('@nolebase/vitepress-plugin-git-changelog/client/style.css');
const gitChangelogOptions = opts.gitChangelog?.options ? [opts.gitChangelog.options] : [];
app.use(NolebaseGitChangelogPlugin, ...gitChangelogOptions);
}
if (opts.pageProperties) {
const { NolebasePagePropertiesPlugin } = await import('@nolebase/vitepress-plugin-page-properties/client');
await import('@nolebase/vitepress-plugin-page-properties/client/style.css');
const pagePropertiesOptions = opts.pageProperties?.options ? [opts.pageProperties.options] : [];
app.use(NolebasePagePropertiesPlugin(), ...pagePropertiesOptions);
}
if (opts.enhancedMark)
await import('@nolebase/vitepress-plugin-enhanced-mark/client/style.css');
if (opts.thumbnailHash) {
const { NolebaseUnlazyImg } = await import('@nolebase/vitepress-plugin-thumbnail-hash/client');
await import('@nolebase/vitepress-plugin-thumbnail-hash/client/style.css');
app.component("NolebaseUnlazyImg", NolebaseUnlazyImg);
}
if (opts.index) {
const { NolebaseIndexPlugin } = await import('@nolebase/vitepress-plugin-index/client');
await import('@nolebase/vitepress-plugin-index/client/style.css');
app.use(NolebaseIndexPlugin);
}
}
};
}
exports.presetClient = presetClient;