-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgitfx.html
52 lines (50 loc) · 2.12 KB
/
gitfx.html
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
{{ $file := .Get 0 }}
{{ if os.FileExists $file }}
<!-- for display code -->
{{ $extLang := dict ".py" "python"
".rb" "ruby"
".sh" "bash"
".go" "go"
".pl" "perl"
".js" "javascript"
".hs" "haskell"
".rs" "rust"
".exs" "elixir"
".php" "php" }}
{{ $code := os.ReadFile $file }}
{{ $lang := index $extLang (path.Ext $file) }}
{{ highlight $code $lang "" }}
<!-- for display code output -->
{{ $langCommentPrefix := dict "python" "#"
"ruby" "#"
"bash" "#"
"go" "//"
"perl" "#"
"javascript" "//"
"haskell" "--"
"rust" "//"
"elixir" "#"
"php" "//" }}
{{ $commentPrefix := index $langCommentPrefix $lang }}
{{ $routes := findRE (print $commentPrefix "\\s+GET .+") $code }}
<!-- you can customize highlight options -->
{{ $highlightOptions := "lineNos=false, style=manni" }}
{{ $outputFormatMap := dict ".html" "html"
".htm" "html"
".json" "json"
".xml" "xml"
".rss" "xml"
".yml" "yml"
".yaml" "yaml" }}
{{ range $routes }}
{{ $outputFile := strings.TrimLeft "/" (index (split . " ") 2) }}
{{ if os.FileExists $outputFile }}
{{ $outputFormat := "text" }}
{{ $ext := path.Ext $outputFile }}
{{ if isset $outputFormatMap $ext }}
{{ $outputFormat = index $outputFormatMap $ext }}
{{ end }}
{{ highlight (os.ReadFile $outputFile) $outputFormat $highlightOptions }}
{{ end }}
{{ end }}
{{ end }}