@alauda/doom
Version:
Doctor Doom making docs.
18 lines (17 loc) • 1.17 kB
JavaScript
import { addLeadingSlash, normalizePosixPath, removeTrailingSlash, } from '@rspress/shared';
import { UNVERSIONED, UNVERSIONED_PREFIX } from "./constants.js";
export const removeBothEndsSlashes = (str) => str?.replace(/^\/|\/$/g, '') || '';
export const getPdfName = (lang, userBase, title) => `/${removeBothEndsSlashes(userBase) || title || 'exported'}-${lang}.pdf`;
export const isExplicitlyUnversioned = (version) => version === UNVERSIONED || !!version?.startsWith(UNVERSIONED_PREFIX);
export const isUnversioned = (version) => !version || isExplicitlyUnversioned(version);
export const getUnversionedVersion = (version) => {
if (!version || version === UNVERSIONED) {
return;
}
return version.startsWith(UNVERSIONED_PREFIX)
? version.slice(UNVERSIONED_PREFIX.length)
: version;
};
export const normalizeSlash = (url) => removeTrailingSlash(addLeadingSlash(normalizePosixPath(url)));
export const withoutBase = (path, base) => addLeadingSlash(path).replace(normalizeSlash(base), '');
export const matchNavbar = (item, currentPathname, base) => new RegExp(item.activeMatch || item.link).test(withoutBase(currentPathname, base));