github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/docs/themes/hugo-theme-relearn/layouts/partials/shortcodes/attachments.html (about)

     1  {{- $page := .page }}
     2  {{- if and (not $page) .context }}
     3    {{- $page = .context }}
     4    {{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'attachments' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
     5  {{- end }}
     6  {{ warnf "%q: DEPRECATED shortcode `attachments` found, use `resources` instead; see https://mcshelby.github.io/hugo-theme-relearn/shortcodes/attachments#migration" $page.File.Filename }}
     7  {{- $color := .color | default "" }}
     8  {{- $content := .content }}
     9  {{- $style := .style | default "default" }}
    10  {{- if and (not $color) (eq (len $color) 0) }}
    11    {{- $style = .style | default "transparent" }}
    12  {{- end }}
    13  {{- $title := .title }}
    14  {{- if not $title }}
    15    {{- if eq $style "info" }}{{ $title = $style | T }}{{ end }}
    16    {{- if eq $style "warning" }}{{ $title = $style | T }}{{ end }}
    17    {{- if eq $style "note" }}{{ $title = $style | T }}{{ end }}
    18    {{- if eq $style "tip" }}{{ $title = $style | T }}{{ end }}
    19  {{- end }}
    20  {{- $title = trim ($title | default ("Attachments-label" | T)) " " }}
    21  {{- $icon := .icon | default "" }}
    22  {{- if and (not $icon) (eq (len $icon) 0) }}
    23    {{- $icon = "paperclip" }}
    24    {{- if eq $style "info" }}{{ $icon = default "info-circle" }}{{ end }}
    25    {{- if eq $style "warning" }}{{ $icon = default "exclamation-triangle" }}{{ end }}
    26    {{- if eq $style "note" }}{{ $icon = default "exclamation-circle" }}{{ end }}
    27    {{- if eq $style "tip" }}{{ $icon = default "lightbulb" }}{{ end }}
    28  {{- end }}
    29  {{- $icon = trim $icon " " }}
    30  {{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
    31    {{- $icon = printf "fa-fw fas fa-%s" $icon }}
    32  {{- end }}
    33  {{- $sort := .sort | default "asc" }}
    34  {{- $pattern := .pattern | default "" }}
    35  {{- $defaultUrlPrefix := strings.TrimRight "/" $page.RelPermalink }}
    36  {{- if .IsTranslated -}}
    37    {{- $defaultLanguage := (index $page.Site.Home.AllTranslations 0).Language.Lang }}
    38    {{- $defaultLanguagePage := index (where $page.AllTranslations "Language.Lang" $defaultLanguage) 0 }}
    39    {{- $defaultUrlPrefix = strings.TrimRight "/" $defaultLanguagePage.RelPermalink }}
    40  {{- end }}
    41  {{- $urlPrefix := strings.TrimRight "/" $page.RelPermalink }}
    42  {{- with $page }}
    43  {{- if ne .BundleType "leaf" }}
    44    {{- warnf "%q: UNSUPPORTED usage of 'attachments' shortcode found while using Hugo >= 0.112.0, use a leaf bundle instead; see https://mcshelby.github.io/hugo-theme-relearn/shortcodes/attachments/index.html#single-language" $page.File.Filename }}
    45  {{- end }}
    46  <div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}>
    47    <div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | .RenderString }}</div>
    48    <ul class="box-content attachments-files">
    49    {{- $fileDir := path.Dir (strings.TrimPrefix (path.Clean hugo.WorkingDir) (path.Clean .File.Filename)) }}
    50    {{- $fileDir = printf "%s/" (path.Clean (strings.TrimPrefix "/" $fileDir)) }}
    51    {{- $fileLink := $fileDir }}
    52    {{- $fileLink = strings.TrimPrefix "content/" $fileLink }}
    53    {{- $filesName := printf "%s.files" .File.BaseFileName }}
    54    {{- if and (eq .File.BaseFileName "index") (fileExists (printf "%sfiles" $fileDir)) }}
    55      {{- $c := "" }}{{/* backward compat to < 5.9.0 behavior */}}
    56      {{- $filesName = "files" }}
    57    {{- end }}
    58    {{- $dir := printf "%s%s" $fileDir $filesName }}
    59    {{- if fileExists $dir }}
    60      {{- range sort (readDir $dir) "Name" $sort }}
    61        {{- if findRE $pattern .Name}}
    62          {{- $size := .Size }}
    63          {{- $unit := "Byte-symbol" }}
    64          {{- if ge $size 1024 }}
    65            {{- $size = div $size 1024 }}
    66            {{- $unit = "Kilobyte-symbol" }}
    67          {{- end }}
    68          {{- if ge $size 1024 }}
    69            {{- $size = div $size 1024 }}
    70            {{- $unit = "Megabyte-symbol" }}
    71          {{- end }}
    72          {{- $unitsymbol := $unit | T }}
    73          {{- $link := (printf "%s%s/%s" $fileLink $filesName .Name) | relLangURL }}
    74          {{- $c := "" }}{{/* Hugo stores the attachments always in the default language subdirectory */}}
    75          {{- $link = replace $link $urlPrefix $defaultUrlPrefix 1 }}
    76        <li><a href="{{ $link }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
    77        {{- end }}
    78      {{- end }}
    79    {{- end }}
    80    </ul>
    81    {{- $content }}
    82  </div>
    83  {{- end }}