-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.typ
More file actions
69 lines (60 loc) · 1.87 KB
/
Copy pathlib.typ
File metadata and controls
69 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#let serve(paths) = {
for p in paths {
asset(p, read("assets/" + p, encoding: none))
}
}
#let wrapper(body, crumbs) = {
html.link(rel: "icon", type: "image/x-icon", href: "/favicon.ico")
html.link(rel: "stylesheet", href: "/styles.css")
html.nav(class: "crumbs", crumbs.join([/]))
html.hr()
body
html.br()
html.hr()
}
#let page(path, title: none, lbl: none, body) = context {
// Navigation system
let segs = path.split("/").map(s => s.replace(".html", ""))
let ancestors = segs.slice(0, segs.len() - 1)
let crumbs = (link(label("index"))[\~], )
for seg in ancestors {
crumbs.push(link(label(seg))[#seg])
}
// Render figures as SVG's on html export
show figure: it => {
if target() == "html" {
html.elem("figure", attrs: (class: "typst"), html.frame(it))
} else {
it
}
}
// Hack to show alignment in HTML, courtesy @t0mstone from the typst discord.
show align: it => context if std.target() == "html" {
let body = it.body
if it.alignment.x != none {
body = html.elem("flex-align", attrs: (axis: "x", align: repr(it.alignment.x)), body)
}
if it.alignment.y != none {
body = html.elem("flex-align", attrs: (axis: "y", align: repr(it.alignment.y)), body)
}
body
} else { it }
// Remove index.html from the ends of links.
// show link: it => {
// let dest = if type(it.dest) == label [ it.dest.name ] else if type(it.dest) == str
// if(type(it.dest) != str) {
// it
// } else if it.dest.ends-with("index.html") {
// link(it.dest.trim("index.html", at: end))[it.body]
// } else {
// it // Leave other links untouched
// }
// }
// Wrap it all up
let wrapped = wrapper(body, crumbs)
if label != none {
[#document(path, title: title, description: [Hello there], wrapped) #label(lbl)]
} else {
document(path, title: title, wrapped)
}
}