Skip to content

Commit

Permalink
Merge pull request #774 from gethinode/develop
Browse files Browse the repository at this point in the history
Refactor download button
  • Loading branch information
markdumay authored Feb 15, 2024
2 parents 2b9a0aa + 22bfb75 commit 9d59c0b
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
42 changes: 18 additions & 24 deletions layouts/_default/single/panel-toc.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,36 @@
{{- $download := .Params.download -}}
{{- if and $download (not (fileExists (path.Join "static" $download))) -}}
{{- errorf "Cannot find download file for page '%s': %s" .File.Path $download -}}
{{- end -}}

{{- $toc := .Site.Params.navigation.toc -}}
{{ if $toc }}
{{- $includeToc := false -}}
{{- if .Site.Params.navigation.toc -}}
{{ $includeToc = true }}
{{ if isset .Params "includeToc" }}
{{ $toc = .Params.includeToc }}
{{ $includeToc = .Params.includeToc }}
{{ else }}
{{- with (index site.Params.pages .Type) -}}
{{ if isset . "includetoc" }}
{{ $toc = index . "includetoc" }}
{{ if ne (printf "%T" $toc) "bool" }}
{{ $includeToc = index . "includetoc" }}
{{ if ne (printf "%T" $includeToc) "bool" }}
{{ errorf "Expected bool value in site parameters: pages.%s.includeToc" $.Type }}
{{ end }}
{{ end }}
{{- end -}}
{{ end }}
{{ end }}

<div class="toc toc-sidebar mb-5 my-md-0 ps-xl-3 mb-lg-5 p-3 text-body-secondary sticky-top">
{{ with $download }}
{{ $title := (T "download" ) }}
{{ $lang := strings.TrimPrefix "." (path.Ext (path.BaseName .)) }}
{{ if and $lang (ne (string site.LanguageCode) $lang) }}
{{ range site.Languages }}
{{ if eq .LanguageCode $lang }}
{{ $title = printf "%s (%s)" (T "download") (T (printf "lang_%s" .LanguageCode)) }}
{{ end }}
{{ end }}
{{ end }}
<div class="mb-5 text-center">
{{ $attr := dict "download" (path.Base .) }}
{{ partial "assets/button.html" (dict "href" . "title" $title "color" "primary" "outline" "true" "icon" "fas download" "size" "sm" "attributes" $attr) }}
<div class="toc toc-sidebar mb-5 my-md-0 mb-lg-5 p-3 text-body-secondary sticky-top">
{{ if $download }}
<div class="mb-5 p-0">
{{ partial "assets/download.html" (dict
"download" $download
"outline" true
"size" "sm"
"order" "last"
) }}
</div>
{{ end }}

{{ if $toc }}
{{ partial "assets/toc.html" (dict "page" .) }}
{{ if $includeToc }}
{{ $index := partial "assets/toc.html" (dict "page" .) }}
{{ $index | safeHTML }}
{{ end -}}
</div>
38 changes: 38 additions & 0 deletions layouts/partials/assets/download.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{{- $download := partial "utilities/GetTargetPath.html" (dict "path" .download "page" page) -}}
{{- $color := .color | default "primary" -}}
{{- $outline := .outline | default true -}}
{{- $icon := .icon | default "fas download" -}}
{{- $size := .size | default "sm" -}}
{{- $justify := .justify -}}
{{- $class := .class -}}
{{- $minimal := .minimal | default false -}}

{{- if and $download (not (fileExists (path.Join "static" $download))) -}}
{{- errorf "Cannot find download file for page '%s': %s" page.File.Path $download -}}
{{- end -}}

{{ with $download }}
{{ $title := "" }}
{{ if not $minimal }}{{ $title = (T "download" ) }}{{ end }}
{{ $lang := strings.TrimPrefix "." (path.Ext (path.BaseName .)) }}
{{ if and $lang (ne (string site.LanguageCode) $lang) }}
{{ range site.Languages }}
{{ if eq .LanguageCode $lang }}
{{ $title = printf "%s (%s)" (T "download") (T (printf "lang_%s" .LanguageCode)) }}
{{ end }}
{{ end }}
{{ end }}
{{ $attr := dict "download" (path.Base .) }}
{{ partial "assets/button.html" (dict
"href" .
"title" $title
"color" $color
"outline" $outline
"icon" $icon
"size" $size
"justify" $justify
"class" $class
"attributes" $attr
) }}
{{ end }}

2 changes: 1 addition & 1 deletion layouts/partials/assets/sharing.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{- $sort := $page.Site.Params.sharing.sort | default "weight" -}}
{{- $list = sort $list $sort $order -}}

{{- $download := $page.Params.download -}}
{{- $download := partial "utilities/GetTargetPath.html" (dict "path" $page.Params.download "page" $page) -}}
{{- if and $download (not (fileExists (path.Join "static" $download))) -}}
{{- errorf "Cannot find download file for page '%s': %s" $page.File.Path $download -}}
{{- end -}}
Expand Down

0 comments on commit 9d59c0b

Please sign in to comment.