@callstack/rspress-theme
Version:
Callstack theme for Rspress docs
157 lines (156 loc) • 7.03 kB
JavaScript
;
const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
}();
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
pluginCallstackTheme: ()=>pluginCallstackTheme
});
const external_node_fs_namespaceObject = require("node:fs");
var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
const external_node_module_namespaceObject = require("node:module");
const external_node_path_namespaceObject = require("node:path");
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
const external_node_url_namespaceObject = require("node:url");
const { resolve } = (0, external_node_module_namespaceObject.createRequire)(__rslib_import_meta_url__);
const dirname = external_node_path_default().dirname((0, external_node_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__));
function excludeFalse(value) {
return false !== value;
}
function getThemeAssets() {
const assetsDirPath = external_node_path_default().join(dirname, '../assets');
const contents = external_node_fs_default().readdirSync(assetsDirPath);
return contents.map(external_node_path_default().parse).map(({ base, name })=>[
`@theme-assets/${name}`,
external_node_path_default().join(assetsDirPath, base)
]);
}
function getThemeAliases(existingThemeAlias) {
const ckThemeExportsPath = external_node_path_default().join(dirname, 'theme');
const rspressThemeDefaultPath = resolve('@rspress/theme-default', {
paths: [
resolve('rspress')
]
});
const aliases = {};
if (Array.isArray(existingThemeAlias)) {
const index = existingThemeAlias.indexOf(rspressThemeDefaultPath);
if (-1 !== index) {
aliases['@theme'] = existingThemeAlias.filter(excludeFalse).slice();
aliases['@theme'].splice(index, 0, ckThemeExportsPath);
} else aliases['@theme'] = existingThemeAlias.filter(excludeFalse).concat(ckThemeExportsPath);
} else aliases['@theme'] = ckThemeExportsPath;
aliases['@default-theme'] = rspressThemeDefaultPath;
aliases['rspress/theme'] = ckThemeExportsPath;
return aliases;
}
function getThemeAssetAlias(existingAssetAlias) {
const assetOverrides = getThemeAssets();
const aliases = {};
for (const [assetAlias, assetPath] of assetOverrides)if (Array.isArray(existingAssetAlias)) {
aliases[assetAlias] = existingAssetAlias.filter(excludeFalse);
aliases[assetAlias].push(assetPath);
} else if (existingAssetAlias) aliases[assetAlias] = [
existingAssetAlias,
assetPath
];
else aliases[assetAlias] = assetPath;
return aliases;
}
function getBuilderConfig(options) {
var _options_links, _options_links1, _options_links2;
return {
source: {
define: {
HOME_BANNER_LINK: JSON.stringify(null == (_options_links = options.links) ? void 0 : _options_links.homeBanner),
HOME_FOOTER_LINK: JSON.stringify(null == (_options_links1 = options.links) ? void 0 : _options_links1.homeFooter),
OUTLINE_CTA_LINK: JSON.stringify(null == (_options_links2 = options.links) ? void 0 : _options_links2.outlineCTA)
}
},
resolve: {
alias: (alias)=>{
const assetAliases = getThemeAssetAlias(alias['@theme-assets']);
Object.assign(alias, assetAliases);
const themeAssetsAlias = alias['@theme-assets'];
delete alias['@theme-assets'];
Object.assign(alias, {
'@theme-assets': themeAssetsAlias
});
const themeAliases = getThemeAliases(alias['@theme']);
Object.assign(alias, themeAliases);
}
}
};
}
function addThemeOverrides(themeConfig = {}) {
if (themeConfig.overview) {
if (!themeConfig.overview.filterNameText) themeConfig.overview.filterNameText = '';
} else themeConfig.overview = {
filterNameText: ''
};
if (!themeConfig.outlineTitle) themeConfig.outlineTitle = 'Contents';
if (!themeConfig.searchNoResultsText) themeConfig.searchNoResultsText = 'No results found, try something different than';
if (!themeConfig.searchSuggestedQueryText) themeConfig.searchSuggestedQueryText = '';
return themeConfig;
}
function normalizeOptions(options) {
var _options_links, _options_links1, _options_links2;
return {
links: {
homeBanner: (null == (_options_links = options.links) ? void 0 : _options_links.homeBanner) ?? 'https://callstack.com',
homeFooter: (null == (_options_links1 = options.links) ? void 0 : _options_links1.homeFooter) ?? 'https://callstack.com',
outlineCTA: (null == (_options_links2 = options.links) ? void 0 : _options_links2.outlineCTA) ?? 'https://callstack.com'
}
};
}
function pluginCallstackTheme(options = {}) {
const normalizedOptions = normalizeOptions(options);
return {
name: 'plugin-callstack-theme',
builderConfig: getBuilderConfig(normalizedOptions),
config: (config)=>{
config.themeConfig = addThemeOverrides(config.themeConfig);
return config;
},
globalStyles: external_node_path_default().join(external_node_path_default().dirname(dirname), 'styles/styles.css')
};
}
exports.pluginCallstackTheme = __webpack_exports__.pluginCallstackTheme;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"pluginCallstackTheme"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});