tinymist/typ/templates/git.typ
Myriad-Dreamin 483de6f00d
build: generate docs with internal links (#1831)
* build: generate docs with internal links

* build: detect link kind
2025-06-22 15:28:27 +08:00

45 lines
905 B
Typst

#import "target.typ": sys-is-html-target, is-md-target
#let git-head = read("/.git/HEAD").trim()
#let git-head-branch = if git-head.starts-with("ref: refs/heads/") {
git-head.slice("ref: refs/heads/".len())
} else {
none
}
#let git-head-hash = if git-head.starts-with("ref: ") {
read("/.git/" + git-head.slice(5)).trim()
} else {
git-head
}
// todo: read it from somewhere
#let remote = "https://github.com/Myriad-Dreamin/tinymist"
#let github-link(path, body, kind: none, permalink: true) = {
if kind == none {
kind = if path.ends-with("/") { "tree" } else { "blob" }
}
let dest = if is-md-target {
path
} else {
remote
"/"
kind
"/"
if not permalink or git-head-branch == none {
git-head-branch
} else {
git-head-hash
}
"/"
if path.starts-with("/") {
path.slice(1)
} else {
path
}
}
link(dest, body)
}