fix: expose base path via data-basepath attribute on body

Compute the base path from cfg.baseUrl and set it as a data attribute on
<body> so client-side scripts can resolve links correctly when Quartz is
deployed to a subdirectory (e.g., user.github.io/repository).
This commit is contained in:
saberzero1 2026-03-18 11:51:06 +01:00
parent 75aef3b0a9
commit 1b999a792f
No known key found for this signature in database

View File

@ -266,10 +266,11 @@ export function renderPage(
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
const direction = i18n(cfg.locale).direction ?? "ltr"
const basePath = cfg.baseUrl ? new URL(`https://${cfg.baseUrl}`).pathname.replace(/\/$/, "") : ""
const doc = (
<html lang={lang} dir={direction}>
<Head {...componentData} />
<body data-slug={slug}>
<body data-slug={slug} data-basepath={basePath}>
{frame.css && <style dangerouslySetInnerHTML={{ __html: frame.css }} />}
<div id="quartz-root" class="page" data-frame={frame.name}>
<Body {...componentData}>