fix(assets): pdf page linking support. (#1025)

* github-slugger pdf workaround

* Skip sluggifying on pdf file extension

* Account for pdf files without anchor

* Address feedback
This commit is contained in:
Emile Bangma 2024-03-25 00:23:25 +01:00 committed by GitHub
parent 0a2b52f618
commit d75928ad5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -168,6 +168,9 @@ export function resolveRelative(current: FullSlug, target: FullSlug | SimpleSlug
export function splitAnchor(link: string): [string, string] { export function splitAnchor(link: string): [string, string] {
let [fp, anchor] = link.split("#", 2) let [fp, anchor] = link.split("#", 2)
if (fp.endsWith(".pdf")) {
return [fp, anchor === undefined ? "" : `#${anchor}`]
}
anchor = anchor === undefined ? "" : "#" + slugAnchor(anchor) anchor = anchor === undefined ? "" : "#" + slugAnchor(anchor)
return [fp, anchor] return [fp, anchor]
} }