Rewrite Markdown live links to either push or patch (#1429)

This commit is contained in:
Jonatan Kłosko 2022-09-22 15:51:18 +02:00 committed by GitHub
parent b20ac022a8
commit 61ee3c79dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -65,7 +65,7 @@ class Markdown {
.use(rehypeSanitize, sanitizeSchema()) .use(rehypeSanitize, sanitizeSchema())
.use(rehypeKatex) .use(rehypeKatex)
.use(rehypeMermaid) .use(rehypeMermaid)
.use(rehypeExternalLinks) .use(rehypeExternalLinks, { baseUrl: this.baseUrl })
.use(rehypeStringify) .use(rehypeStringify)
.process(this.content) .process(this.content)
.then((file) => String(file)) .then((file) => String(file))
@ -224,7 +224,10 @@ function rehypeExternalLinks(options) {
const url = node.properties.href; const url = node.properties.href;
if (isInternalUrl(url)) { if (isInternalUrl(url)) {
node.properties["data-phx-link"] = "redirect"; node.properties["data-phx-link"] =
options.baseUrl && url.startsWith(options.baseUrl)
? "patch"
: "redirect";
node.properties["data-phx-link-state"] = "push"; node.properties["data-phx-link-state"] = "push";
} else if (isAbsoluteUrl(url)) { } else if (isAbsoluteUrl(url)) {
node.properties.target = "_blank"; node.properties.target = "_blank";