From ad685b8d4eaecb5bb4db4e4a20ae75f2fdbdfa67 Mon Sep 17 00:00:00 2001 From: saberzero1 Date: Tue, 26 May 2026 12:56:18 +0200 Subject: [PATCH] fix: use correct baseurl in serve mode --- quartz/components/pages/404.tsx | 5 ++--- quartz/components/renderPage.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/quartz/components/pages/404.tsx b/quartz/components/pages/404.tsx index 622a18d..c69b21a 100644 --- a/quartz/components/pages/404.tsx +++ b/quartz/components/pages/404.tsx @@ -1,10 +1,9 @@ import { i18n } from "../../i18n" import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types" -const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => { - // If baseUrl contains a pathname after the domain, use this as the home link +const NotFound: QuartzComponent = ({ cfg, ctx }: QuartzComponentProps) => { const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`) - const baseDir = url.pathname + const baseDir = ctx.argv.serve ? "/" : url.pathname return (
diff --git a/quartz/components/renderPage.tsx b/quartz/components/renderPage.tsx index 5387912..e314551 100644 --- a/quartz/components/renderPage.tsx +++ b/quartz/components/renderPage.tsx @@ -337,7 +337,12 @@ 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(/\/$/, "") : "" + // During local dev (--serve), the dev server serves from root without the + // baseUrl subpath, so basePath must be empty to avoid broken links. + const basePath = + componentData.ctx.argv.serve || !cfg.baseUrl + ? "" + : new URL(`https://${cfg.baseUrl}`).pathname.replace(/\/$/, "") const doc = (