-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #774 from gethinode/develop
Refactor download button
- Loading branch information
Showing
3 changed files
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters