nimiq-vitepress-theme
Version:
Nimiq UI theme for VitePress
20 lines (19 loc) • 691 B
JavaScript
import { inBrowser } from "vitepress";
const HASH_RE = /#.*$/;
const HASH_OR_QUERY_RE = /[?#].*$/;
const INDEX_OR_EXT_RE = /(?:(^|\/)index)?\.(?:md|html)$/;
export function isActive(currentPath, matchPath) {
if (matchPath === void 0)
return false;
const normalizedCurrent = normalize(currentPath);
const normalizedMatch = normalize(matchPath);
if (!normalizedCurrent.startsWith(normalizedMatch))
return false;
const hashMatch = matchPath.match(HASH_RE);
if (hashMatch)
return (inBrowser ? location.hash : "") === hashMatch[0];
return true;
}
export function normalize(path) {
return decodeURI(path).replace(HASH_OR_QUERY_RE, "").replace(INDEX_OR_EXT_RE, "$1");
}