Welcome to mirror list, hosted at ThFree Co, Russian Federation.

readfile.html « shortcodes « layouts - github.com/google/docsy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ce05aef32256a8a022e3632afbf424651f235c1f (plain)
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
{{/* Store ordinal, to be retrieved by parent element */}}
{{ if ge hugo.Version "0.93.0" }}
  {{ .Page.Store.Add "Ordinal" 1 }}
{{ end }}

{{/* Handle the "file" named parameter or a single unnamed parameter as the file
path */}}
{{ if .IsNamedParams }}
	{{ $.Scratch.Set "fparameter" ( .Get "file" ) }}
{{ else }}
	{{ $.Scratch.Set "fparameter" ( .Get 0 ) }}
{{ end }}


{{/* If the first character is "/", the path is absolute from the site's
`baseURL`. Otherwise, construct an absolute path using the current directory */}}

{{ if eq (.Scratch.Get "fparameter" | printf "%.1s") "/" }}
  {{ $.Scratch.Set "filepath" ($.Scratch.Get "fparameter") }}
{{ else }}
  {{ $.Scratch.Set "filepath" "/" }}
  {{ $.Scratch.Add "filepath" $.Page.File.Dir }}
  {{ $.Scratch.Add "filepath" ($.Scratch.Get "fparameter") }}
{{ end }}


{{/* If the file exists, read it and highlight it if it's code. Throw an error
if the file is not found */}}

{{ if fileExists ($.Scratch.Get "filepath") }}
  {{ if eq (.Get "code") "true" }}
    {{- highlight ($.Scratch.Get "filepath" | readFile | htmlUnescape |
    safeHTML ) (.Get "lang") "" -}}
  {{ else }}
    {{- $.Scratch.Get "filepath" | os.ReadFile | .Page.RenderString | safeHTML -}}
  {{ end }}
{{ else }}

<p style="color: #D74848"><b><i>The file <code>{{ $.Scratch.Get "filepath" }}</code> was not found.</i></b></p>

{{ end }}