No description
Find a file
saberzero1 81189f697c
chore: commit dist/ and remove prepare script
With build tools (tsup, typescript) moved to devDependencies, the prepare
script can no longer build when npm fetches this package from GitHub (npm
does not install devDependencies for git dependencies). Commit the pre-built
dist/ output so GitHub-based installs work without a build step.
2026-03-14 21:30:17 +01:00
.github/workflows Initial commit 2026-02-09 12:28:32 +01:00
dist chore: commit dist/ and remove prepare script 2026-03-14 21:30:17 +01:00
src feat: add htmlToJsx wrapper for safe HAST-to-JSX rendering 2026-03-08 19:25:27 +01:00
test feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
.eslintrc.json Initial commit 2026-02-09 12:28:32 +01:00
.gitignore chore: commit dist/ and remove prepare script 2026-03-14 21:30:17 +01:00
.prettierrc Initial commit 2026-02-09 12:28:32 +01:00
CHANGELOG.md Initial commit 2026-02-09 12:28:32 +01:00
LICENSE Initial commit 2026-02-09 12:28:32 +01:00
package-lock.json feat: add htmlToJsx wrapper for safe HAST-to-JSX rendering 2026-03-08 19:25:27 +01:00
package.json chore: commit dist/ and remove prepare script 2026-03-14 21:30:17 +01:00
README.md feat: migrate to shared utility library 2026-02-09 12:38:53 +01:00
tsconfig.json Initial commit 2026-02-09 12:28:32 +01:00
tsup.config.ts feat: add htmlToJsx wrapper for safe HAST-to-JSX rendering 2026-03-08 19:25:27 +01:00
vitest.config.ts Initial commit 2026-02-09 12:28:32 +01:00

@quartz-community/utils

Shared utility functions for Quartz community plugins.

Installation

npm install @quartz-community/utils

Or using GitHub:

npm install github:quartz-community/utils

Usage

import {
  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"

Modules

Path (@quartz-community/utils/path)

Path manipulation utilities for Quartz slugs:

  • simplifySlug(slug) - Remove /index suffix from slugs
  • getFullSlug(window) - Get current page slug from document body dataset
  • getFullSlugFromUrl() - Get current page slug from URL pathname
  • joinSegments(...segments) - Join path segments with proper slash handling
  • resolvePath(path) - Ensure path starts with /
  • endsWith(str, suffix) - Check if path ends with suffix
  • trimSuffix(str, suffix) - Remove suffix from path
  • stripSlashes(str, onlyPrefix?) - Remove leading/trailing slashes
  • getFileExtension(path) - Get file extension
  • isFolderPath(path) - Check if path represents a folder
  • getAllSegmentPrefixes(path) - Get all path prefixes

DOM (@quartz-community/utils/dom)

DOM manipulation utilities:

  • removeAllChildren(element) - Remove all child nodes from an element
  • registerEscapeHandler(container, callback) - Register Escape key and click-outside handlers
  • normalizeRelativeURLs(document, baseUrl) - Convert relative URLs to absolute

Lang (@quartz-community/utils/lang)

Language/general utilities:

  • classNames(...classes) - Combine CSS class names, filtering falsy values

Types

The package exports TypeScript types for type-safe slug handling:

import type { FullSlug, SimpleSlug, RelativeURL } from "@quartz-community/utils";

License

MIT