Shared utility functions for Quartz community plugins.
npm install @quartz-community/utilsOr using GitHub:
npm install github:quartz-community/utilsimport {
simplifySlug,
getFullSlug,
joinSegments,
removeAllChildren,
classNames,
} from "@quartz-community/utils";
// Path utilities
const slug = simplifySlug("folder/index"); // "folder/"
const currentSlug = getFullSlug(window); // e.g., "blog/my-post"
const path = joinSegments("a", "b", "c"); // "a/b/c"
// DOM utilities
removeAllChildren(document.getElementById("container")!);
// Language utilities
const classes = classNames("btn", isActive && "active", null); // "btn active"Path manipulation utilities for Quartz slugs:
simplifySlug(slug)- Remove/indexsuffix from slugsgetFullSlug(window)- Get current page slug from document body datasetgetFullSlugFromUrl()- Get current page slug from URL pathnamejoinSegments(...segments)- Join path segments with proper slash handlingresolvePath(path)- Ensure path starts with/endsWith(str, suffix)- Check if path ends with suffixtrimSuffix(str, suffix)- Remove suffix from pathstripSlashes(str, onlyPrefix?)- Remove leading/trailing slashesgetFileExtension(path)- Get file extensionisFolderPath(path)- Check if path represents a foldergetAllSegmentPrefixes(path)- Get all path prefixes
DOM manipulation utilities:
removeAllChildren(element)- Remove all child nodes from an elementregisterEscapeHandler(container, callback)- Register Escape key and click-outside handlersnormalizeRelativeURLs(document, baseUrl)- Convert relative URLs to absolute
Language/general utilities:
classNames(...classes)- Combine CSS class names, filtering falsy values
The package exports TypeScript types for type-safe slug handling:
import type { FullSlug, SimpleSlug, RelativeURL } from "@quartz-community/utils";MIT