UNPKG

nimiq-vitepress-theme

Version:

Nimiq UI theme for VitePress

19 lines (18 loc) 737 B
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); const hashMatch = matchPath.match(HASH_RE); if (hashMatch) { return normalizedCurrent === normalizedMatch && (inBrowser ? location.hash : "") === hashMatch[0]; } return normalizedCurrent === normalizedMatch; } export function normalize(path) { return decodeURI(path).replace(HASH_OR_QUERY_RE, "").replace(INDEX_OR_EXT_RE, "$1").replace(/^\//, "").replace(/\/$/, ""); }