summaryrefslogtreecommitdiffstats
path: root/docs/_vendor/github.com/gohugoio/gohugoioTheme/layouts/shortcodes/readfile.html
blob: de8083443f07992d286d5c53b5bcfc446b5e2ce0 (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
{{- $highlight := or (.Get "highlight") "" }}

{{- $markdown := false }}
{{- if in (slice "false" false 0) (.Get "markdown") }}
  {{- $markdown = false }}
{{- else if in (slice "true" true 1) (.Get "markdown") }}
  {{- $markdown = true }}
{{- end }}

{{- with .Get "file" }}
  {{- if os.FileExists . }}
    {{- with os.ReadFile . }}
      {{- $content := trim . "\n\r" }}
      {{- if $markdown }}
        {{- $content | markdownify }}
      {{- else if $highlight }}
        {{- highlight $content $highlight }}
      {{- else }}
        {{- $content | safeHTML }}
      {{- end }}
    {{- else }}
      {{- errorf "The %q shortcode was unable to read %q. See %s" $.Name . $.Position }}
    {{- end }}
  {{- else }}
    {{- errorf "The %q shortcode was unable to find %q. See %s" $.Name . $.Position }}
  {{- end }}
{{- else }}
  {{- errorf "The %q shortcode requires a 'file' parameter. See %s" $.Name $.Position }}
{{- end }}