feat: add root_path config option (#14)

Fixes #12
This commit is contained in:
Aleksandr Mezin
2025-05-27 09:47:03 +03:00
committed by GitHub
parent 9bb5ffe0ae
commit 8a449ad181
6 changed files with 83 additions and 19 deletions

View File

@@ -51,17 +51,25 @@ const relativeLinksRule = {
}
}
if (hrefSrc == null) {
if (hrefSrc == null || hrefSrc.startsWith("#")) {
continue
}
const url = new URL(hrefSrc, pathToFileURL(params.name))
const isRelative =
url.protocol === "file:" &&
!hrefSrc.startsWith("/") &&
!hrefSrc.startsWith("#")
let url
if (!isRelative) {
if (hrefSrc.startsWith("/")) {
const rootPath = params.config["root_path"]
if (!rootPath) {
continue
}
url = new URL(`.${hrefSrc}`, pathToFileURL(`${rootPath}/`))
} else {
url = new URL(hrefSrc, pathToFileURL(params.name))
}
if (url.protocol !== "file:") {
continue
}