@logicflow/dumi-theme-simple
Version:
Simple website theme based on dumi2.
145 lines (141 loc) • 4.73 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/plugin/index.ts
var plugin_exports = {};
__export(plugin_exports, {
default: () => plugin_default
});
module.exports = __toCommonJS(plugin_exports);
var import_plugin_utils = require("dumi/plugin-utils");
var path = __toESM(require("path"));
var import_examples = require("./examples");
var import_rehypeObservable = __toESM(require("./rehypeObservable"));
var PAGES_DIR = (0, import_plugin_utils.winPath)(path.join(__dirname, "../pages"));
var MOCK_META = { frontmatter: { title: "mock-meta" }, texts: [], toc: [] };
var plugin_default = (api) => {
api.describe({ key: `dumi-theme:${require("../../package.json").name}` });
api.modifyDefaultConfig((memo) => {
memo.resolve.codeBlockMode = "passive";
memo.exportStatic.extraRoutePaths = (0, import_examples.getExamplePaths)();
memo.mfsu = false;
memo.jsMinifier = "terser";
memo.favicons = [
"https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original"
];
memo.extraRehypePlugins = [import_rehypeObservable.default];
return memo;
});
const pages = [
{
id: "dumi-theme-simple-homepage",
absPath: "/"
},
{
id: "dumi-theme-simple-en-homepage",
absPath: "/en/"
},
{
id: "dumi-theme-simple-zh-homepage",
absPath: "/zh/"
},
// Examples gallery page.
{
id: "dumi-theme-simple-example-list-zh",
absPath: "/examples",
file: `${PAGES_DIR}/Examples`
},
{
id: "dumi-theme-simple-example-list-lang",
absPath: "/:language/examples",
file: `${PAGES_DIR}/Examples`
},
// single example preview page.
{
id: "dumi-theme-simple-single-example-zh",
absPath: "/examples/:topic/:example",
file: `${PAGES_DIR}/Example`
},
{
id: "dumi-theme-simple-single-example-lang",
absPath: "/:language/examples/:topic/:example",
file: `${PAGES_DIR}/Example`
}
];
api.onGenerateFiles(() => {
api.writeTmpFile({
noPluginDir: true,
path: "theme-antv/ContextWrapper.tsx",
content: `
import React from 'react';
import { useOutlet, useSiteData } from 'dumi';
import { LogicFlowThemeContext } from '${(0, import_plugin_utils.winPath)(
path.join(__dirname, "../context")
)}';
export default function ThemeAntVContextWrapper() {
const outlet = useOutlet();
return (
<LogicFlowThemeContext.Provider
value={{
meta: ${JSON.stringify({
exampleTopics: (0, import_examples.getExamplesPageTopics)(
api.config.themeConfig.examples || [],
api.userConfig.themeConfig.showAPIDoc
)
})}
}}
>
{outlet}
</LogicFlowThemeContext.Provider>
);
}
`
});
});
api.addLayouts(() => ({
id: "theme-antv-context",
file: `${api.paths.absTmpPath}/theme-antv/ContextWrapper.tsx`
}));
api.modifyRoutes((routes) => {
pages.forEach((page) => {
routes[page.id] = {
id: page.id,
path: page.absPath.slice(1),
absPath: page.absPath,
file: page.file,
parentId: "DocLayout",
meta: MOCK_META
};
});
routes["404"].file = `${PAGES_DIR}/404`;
routes["404"].meta = MOCK_META;
return routes;
});
api.addTmpGenerateWatcherPaths(() => [
path.resolve(process.cwd(), "examples")
]);
};