diff options
author | it-gro <13005925+it-gro@users.noreply.github.com> | 2021-09-05 11:52:21 +0300 |
---|---|---|
committer | it-gro <13005925+it-gro@users.noreply.github.com> | 2021-09-05 11:52:21 +0300 |
commit | e621fe255a43ea8ac5f9ba97366ee2797459dab7 (patch) | |
tree | d2473f9449915afae885b2904bc84e6ec649795e | |
parent | 9c479a4ef1f8aab7170ac8328d095fd5a2ef853d (diff) |
Get rid of scratch
-rw-r--r-- | layouts/shortcodes/highlightfile.html | 19 | ||||
-rw-r--r-- | layouts/shortcodes/readfile.html | 57 |
2 files changed, 52 insertions, 24 deletions
diff --git a/layouts/shortcodes/highlightfile.html b/layouts/shortcodes/highlightfile.html index 7520860..20bb0af 100644 --- a/layouts/shortcodes/highlightfile.html +++ b/layouts/shortcodes/highlightfile.html @@ -3,11 +3,18 @@ Highlights file and provides download link. File should be located either in the same directory or full path should be specified. --> -{{- $src := (.Get "file") -}} -{{/* {{- $lang := .Get "language" | default ("python") }} */}} +{{- $src := .Get "file" }} +{{- $lang := .Get "language" | default ("python") }} +{{- $opt := .Get "opt" | default ("linenos=table") }} +{{- $theme := .Get "theme" | default ("") }} -{{- $lang := .Get "language" | default ("python") }} -{{- $opt := .Get "opt" | default ("linenos=table") }} +{{- if eq $theme "default" -}} + {{ $theme = (default "w3-theme-l3" ($.Site.Param `colorShortcodeHighlightfile`) ) }} +{{- end -}} + +{{- if in $theme "w3-theme" -}} + <div class="w3-container {{ $theme }}" > +{{- end -}} {{- if in $src "/" -}} {{ $filelink := (strings.TrimPrefix "/static" $src ) }} @@ -37,3 +44,7 @@ File should be located either in the same directory or full path should be speci {{ highlight (trim (readFile (printf "content/%s" $file)) "\n") $lang $opt}} {{- end -}} + +{{- if in $theme "w3-theme" -}} + </div> +{{- end -}} diff --git a/layouts/shortcodes/readfile.html b/layouts/shortcodes/readfile.html index 507b7eb..8b6f535 100644 --- a/layouts/shortcodes/readfile.html +++ b/layouts/shortcodes/readfile.html @@ -2,40 +2,57 @@ inspired by https://github.com/gohugoio/hugo/blob/master/docs/layouts/shortcodes/readfile.html */}} -{{- $.Scratch.Set `theFile` `.` }} -{{- $.Scratch.Set `theMarkdownify` `` }} -{{- $.Scratch.Set `theHighlightLang` `md` }} +{{- $myFile := `.` }} +{{- $myMarkdownify := `` }} +{{- $myHighlightLang := `md` }} +{{- $myTheme := `` }} {{- if .IsNamedParams -}} - {{- $.Scratch.Set `theFile` (.Get `file`) }} - {{- $.Scratch.Set `theMarkdownify` (.Get `md` ) }} - {{- $.Scratch.Set `theHighlightLang` (.Get `hll` ) }} + {{- $myFile = default ($myFile ) (.Get `file` ) }} + {{- $myMarkdownify = default ($myMarkdownify ) (.Get `md` ) }} + {{- $myHighlightLang = default ($myHighlightLang ) (.Get `hll` ) }} + {{- $myTheme = default ($myTheme ) (.Get `theme` ) }} {{- else -}} - {{- $myPos := 0}} {{- if gt (len .Params) $myPos }} {{- $.Scratch.Set `theFile` (.Get $myPos) }} {{- end -}} - {{- $myPos := 1}} {{- if gt (len .Params) $myPos }} {{- $.Scratch.Set `theMarkdownify` (.Get $myPos) }} {{- end -}} - {{- $myPos := 2}} {{- if gt (len .Params) $myPos }} {{- $.Scratch.Set `theHighlightLang` (.Get $myPos) }} {{- end -}} + {{- $myPos := 0}} {{- if gt (len .Params) $myPos }} {{- $myFile = .Get $myPos }} {{- end -}} + {{- $myPos := 1}} {{- if gt (len .Params) $myPos }} {{- $myMarkdownify = .Get $myPos }} {{- end -}} + {{- $myPos := 2}} {{- if gt (len .Params) $myPos }} {{- $myHighlightLang = .Get $myPos }} {{- end -}} + {{- $myPos := 3}} {{- if gt (len .Params) $myPos }} {{- $myTheme = .Get $myPos }} {{- end -}} {{- end -}} +{{- if eq $myTheme "default" -}} + {{ $myTheme = (default "w3-theme-l3" ($.Site.Param `colorShortcodeReadfile`) ) }} +{{- end -}} + +{{- if in $myTheme "w3-theme" -}} +<div class="w3-container {{ $myTheme }}" > +{{- end -}} + + {{- if or $.Site.Params.debug (findRE `\bdebug-shortcode(s|-readfile)\b` $.Site.Params.traceFlags) -}} <br/> -"theFile" : {{- $.Scratch.Get `theFile` }} <br/> -"theMarkdownify" : {{- $.Scratch.Get `theMarkdownify` }} <br/> -"theHighlight" : {{- $.Scratch.Get `theHighlight` }} <br/> +"myFile" : {{- $myFile }} <br/> +"myMarkdownify" : {{- $myMarkdownify }} <br/> +"myHighlightLang" : {{- $myHighlightLang }} <br/> +"myTheme" : {{- $myTheme }} <br/> {{- end -}} -{{- if (findRE `((\.)|(\\\.))$` ($.Scratch.Get `theFile`) ) -}} +{{- if (findRE `((\.)|(\\\.))$` $myFile ) -}} <pre class="w3-code notranslate"> - {{- printf "%s" ($.Scratch.Get `theFile`) -}} - {{- range readDir ($.Scratch.Get `theFile`) }} + {{- printf "%s" $myFile -}} + {{- range readDir $myFile }} {{- printf "\n%s %s %10s %s" .Mode (.ModTime.Format "2006-01-02") (cond .Mode.IsDir "" (string .Size) ) .Name }} {{- end }} </pre> {{- else }} - {{- if eq ($.Scratch.Get `theMarkdownify`) "true" -}} - {{- ($.Scratch.Get `theFile`) | readFile | markdownify -}} - {{- else if ($.Scratch.Get `theHighlightLang`) -}} - {{- highlight (($.Scratch.Get `theFile`) | readFile) ($.Scratch.Get `theHighlightLang`) "" -}} + {{- if eq ($myMarkdownify) "true" -}} + {{- $myFile | readFile | markdownify -}} + {{- else if $myHighlightLang -}} + {{- highlight ($myFile | readFile) $myHighlightLang "" -}} {{- else -}} - {{- ($.Scratch.Get `theFile`) | readFile | safeHTML }} + {{- $myFile | readFile | safeHTML }} {{- end -}} {{- end -}} + +{{- if in $myTheme "w3-theme" -}} +</div> +{{- end -}} |