Skip to content

Commit

Permalink
fix shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
miethe committed Aug 11, 2023
1 parent 0b4af63 commit 066f573
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 157 deletions.
41 changes: 41 additions & 0 deletions layouts/shortcodes/readfile.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,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 a compile error or print an error on the page 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 if eq (.Get "draft") "true" }}

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

{{ else }}{{- errorf "Shortcode %q: file %q not found at %s" .Name ($.Scratch.Get "filepath") .Position -}}{{ end }}
32 changes: 0 additions & 32 deletions layouts/shortcodes/tab.html

This file was deleted.

125 changes: 0 additions & 125 deletions layouts/shortcodes/tabs.html

This file was deleted.

0 comments on commit 066f573

Please sign in to comment.