dumi-theme-lobehub
Version:
dumi-theme-lobehub is a documentation site theme package designed for dumi2. It provides a more beautiful and user-friendly development and reading experience based on @lobehub/ui
115 lines • 5.48 kB
JavaScript
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { merge } from 'lodash-es';
import { initialThemeConfig } from "../initialState";
var themeConfig = function themeConfig(s) {
return merge(initialThemeConfig, s.siteData.themeConfig);
};
var siteTitle = function siteTitle(s) {
return themeConfig(s).title;
};
var siteDesc = function siteDesc(s) {
return themeConfig(s).description;
};
var github = function github(s) {
var _themeConfig$socialLi;
return ((_themeConfig$socialLi = themeConfig(s).socialLinks) === null || _themeConfig$socialLi === void 0 ? void 0 : _themeConfig$socialLi.github) || '';
};
var discord = function discord(s) {
var _themeConfig$socialLi2;
return ((_themeConfig$socialLi2 = themeConfig(s).socialLinks) === null || _themeConfig$socialLi2 === void 0 ? void 0 : _themeConfig$socialLi2.discord) || '';
};
var giscus = function giscus(s) {
return themeConfig(s).giscus;
};
var analytics = function analytics(s) {
return themeConfig(s).analytics;
};
var metadata = function metadata(s) {
return themeConfig(s).metadata;
};
var logo = function logo(s) {
var logo = themeConfig(s).logo;
if (!logo) return logo || '';
if (logo.startsWith('http')) return logo;
return logo;
};
var token = function token(s) {
var fm = s.routeMeta.frontmatter;
return merge({}, fm.token, s.siteData.themeConfig.siteToken);
};
var activePath = function activePath(s) {
if (s.location.pathname === '/') return '/';
var item = s.navData.filter(function (index) {
return index.link !== '/';
}).find(function (index) {
return s.location.pathname.startsWith(String(index.activePath || index.link));
});
return (item === null || item === void 0 ? void 0 : item.activePath) || (item === null || item === void 0 ? void 0 : item.link) || '';
};
var tocAnchorItem = function tocAnchorItem(s) {
var _s$tabMeta, _s$tabMeta2;
var _s$routeMeta = s.routeMeta,
toc = _s$routeMeta.toc,
frontmatter = _s$routeMeta.frontmatter;
if ((_s$tabMeta = s.tabMeta) !== null && _s$tabMeta !== void 0 && _s$tabMeta.toc) toc = s.tabMeta.toc;
if ((_s$tabMeta2 = s.tabMeta) !== null && _s$tabMeta2 !== void 0 && _s$tabMeta2.frontmatter) frontmatter = s.tabMeta.frontmatter;
var shouldKeepWith = function shouldKeepWith(depth) {
if (!frontmatter.tocDepth) return true;
if (typeof frontmatter.tocDepth === 'number' && frontmatter.tocDepth > depth - 1) return true;
};
return toc.reduce(function (result, item) {
if (item.depth === 2 && shouldKeepWith(2)) {
result.push(_objectSpread({}, item));
} else if (item.depth === 3 && shouldKeepWith(3)) {
var parent = result.at(-1);
if (parent) {
parent.children = parent.children || [];
parent.children.push(_objectSpread({}, item));
}
}
return result;
}, []);
};
var flattenSidebar = function flattenSidebar(s) {
var _s$sidebar;
return ((_s$sidebar = s.sidebar) === null || _s$sidebar === void 0 ? void 0 : _s$sidebar.map(function (index) {
return index.children;
}).flat()) || [];
};
var contentBottom = function contentBottom(s) {
var dataFlatten = flattenSidebar(s);
var path = s.location.pathname;
var currentIndex = dataFlatten.findIndex(function (item) {
return item.link === path;
});
return {
currentIndex: currentIndex,
next: dataFlatten[currentIndex + 1],
prev: dataFlatten[currentIndex - 1]
};
};
var hostname = function hostname(s) {
return s.siteData.hostname;
};
export var siteSelectors = {
activePath: activePath,
analytics: analytics,
contentBottom: contentBottom,
discord: discord,
flattenSidebar: flattenSidebar,
giscus: giscus,
github: github,
hostname: hostname,
logo: logo,
metadata: metadata,
siteDesc: siteDesc,
siteTitle: siteTitle,
themeConfig: themeConfig,
tocAnchorItem: tocAnchorItem,
token: token
};