Skip to content

Commit 27b4b44

Browse files
committed
DRAFT: add missing filter
1 parent 0f89cc9 commit 27b4b44

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Meta(meta)
2+
replace_base_domain = tostring(meta.replace_base_domain[1].text)
3+
replace_rel_path = tostring(meta.replace_rel_path[1].text)
4+
end
5+
6+
-- pandoc Link object: replace the .qmd in the target with .html
7+
function Link(link)
8+
-- replace .qmd with .html in target
9+
-- replace beginning with replace_base_domain, accounting for / and ./ in paths
10+
-- e.g. ./overview.qmd -> {replace_rel_path}/get-started/overview.html
11+
-- e.g. /index.qmd -> {replace_base_domain}/index.html
12+
-- e.g. https://example.com -> https://example.com
13+
if link.target:match("%.qmd$") then
14+
link.target = link.target:gsub("%.qmd$", ".html")
15+
if link.target:match("^%./") then
16+
link.target = link.target:gsub("^%./", replace_base_domain .. replace_rel_path .. "/")
17+
end
18+
if link.target:match("^/") then
19+
link.target = link.target:gsub("^/", replace_base_domain .. "/")
20+
end
21+
-- if target does not start with http, do same as above
22+
if not link.target:match("^http") then
23+
link.target = replace_base_domain .. replace_rel_path .. "/" .. link.target
24+
end
25+
end
26+
27+
return link
28+
end
29+
30+
return {
31+
{
32+
Meta = Meta
33+
},
34+
{
35+
Link = Link
36+
}
37+
}

0 commit comments

Comments
 (0)