fix: use correct baseurl in serve mode
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
import { i18n } from "../../i18n"
|
import { i18n } from "../../i18n"
|
||||||
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } from "../types"
|
||||||
|
|
||||||
const NotFound: QuartzComponent = ({ cfg }: QuartzComponentProps) => {
|
const NotFound: QuartzComponent = ({ cfg, ctx }: QuartzComponentProps) => {
|
||||||
// If baseUrl contains a pathname after the domain, use this as the home link
|
|
||||||
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
const url = new URL(`https://${cfg.baseUrl ?? "example.com"}`)
|
||||||
const baseDir = url.pathname
|
const baseDir = ctx.argv.serve ? "/" : url.pathname
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<article class="popover-hint">
|
<article class="popover-hint">
|
||||||
|
|||||||
@@ -337,7 +337,12 @@ export function renderPage(
|
|||||||
|
|
||||||
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
|
const lang = componentData.fileData.frontmatter?.lang ?? cfg.locale?.split("-")[0] ?? "en"
|
||||||
const direction = i18n(cfg.locale).direction ?? "ltr"
|
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 = (
|
const doc = (
|
||||||
<html lang={lang} dir={direction}>
|
<html lang={lang} dir={direction}>
|
||||||
<Head {...componentData} />
|
<Head {...componentData} />
|
||||||
|
|||||||
Reference in New Issue
Block a user