Skip to content

Commit 0359d6c

Browse files
committed
sphinx
1 parent 25f411a commit 0359d6c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

layouts/shortcodes/sphinx.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!-- layouts/shortcodes/sphinx_link.html -->
2+
{{/*
3+
Sphinx link shortcode expects the following context:
4+
0: directory and filename (e.g. "training/api-core-reference.html")
5+
1: type of link (e.g. "module", "submodule", "class", "function", "method")
6+
2: target syntax with ~prefix (e.g. "~determined.pytorch" for module, "~determined.pytorch.PyTorchTrial.train_batch" for method)
7+
3: optional link text (if not provided, the target syntax is used as link text)
8+
*/}}
9+
{{- $dir := index (.Params) 0 -}}
10+
{{- $type := index (.Params) 1 -}}
11+
{{- $targetWithPrefix := index (.Params) 2 -}}
12+
{{- $title := index (.Params) 3 -}}
13+
{{- $baseUrl := "UPDATE-THIS-VALUE" -}}
14+
{{- $target := strings.TrimPrefix "~" $targetWithPrefix -}}
15+
{{- $pathParts := split $target "." -}}
16+
{{/* the last %s is the module name; ensure the filename.rst matches the module or update this pattern to match your filename convention */}}
17+
{{- $fullUrl := printf "%s%s/%s.html" $baseUrl $dir (index $pathParts 1) -}}
18+
{{- $linkText := $title | default "" -}}
19+
{{- $anchor := "" -}}
20+
21+
{{- if or (eq $type "class") (eq $type "function") (eq $type "method") -}}
22+
{{- $anchor = printf "#%s" (delimit $pathParts ".") -}}
23+
{{- end -}}
24+
25+
{{- if eq $linkText "" -}}
26+
{{- if eq $type "module" -}}
27+
{{- $linkText = index $pathParts 1 -}}
28+
{{- else if eq $type "submodule" -}}
29+
{{- $linkText = index $pathParts 2 -}}
30+
{{- else -}}
31+
{{- $linkText = delimit (after 1 $pathParts) "." -}}
32+
{{- if or (eq $type "class") (eq $type "function") (eq $type "method") -}}
33+
{{- $linkText = printf "%s()" $linkText -}}
34+
{{- end -}}
35+
{{- end -}}
36+
{{- end -}}
37+
38+
<a href="{{- $fullUrl -}}{{- $anchor -}}" class="font-bold underline">{{- $linkText -}}</a>

0 commit comments

Comments
 (0)