diff --git a/exampleSite/config.toml b/exampleSite/config.toml index eb9992d7c4..11ac0a73d3 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -124,7 +124,7 @@ disableHugoGeneratorInject = true [Languages.pir] title = "Cap'n Hugo Relearrrn Theme" - weight = 1 + weight = 2 languageName = "Arrr! ☠ Pirrrates ☠" landingPageName = " Arrr! Home" diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 5239b661b3..5c0496125d 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -14,7 +14,13 @@ This document shows you what's new in the latest release. For a detailed list of --- -## 5.9.0 (not yet released) +## 5.9.0 (2022-12-23) + +- {{% badge style="note" title=" " %}}Change{{% /badge %}} The required folder name for the [`attachments` shortcode]({{% relref "shortcodes/attachments" %}}) was changed for leaf bundles. + + Previously, the attachments for leaf bundles in non-multilang setups were required to be in a `files` subdirectory. For page bundles and leaf bundles in multilang setups they were always required to be in a `_index..files` or `index..files` subdirectory accordingly. + + This added unnessessary complexity. So attachments for leaf bundles in non-multilang setups can now also reside in a `index.files` directory. Although the old `files` directory is now deprecated, if both directories are present, only the old `files` directory will be used for compatiblity. - {{% badge style="note" title=" " %}}Change{{% /badge %}} Absolute links prefixed with `http://` or `https://` are now opened in a separate browser tab. diff --git a/exampleSite/content/shortcodes/attachments.en.md b/exampleSite/content/shortcodes/attachments.en.md index 841f20babc..44164ce90b 100644 --- a/exampleSite/content/shortcodes/attachments.en.md +++ b/exampleSite/content/shortcodes/attachments.en.md @@ -31,11 +31,9 @@ While the examples are using shortcodes with named parameter you are free to als {{% /tab %}} {{< /tabs >}} -The shortcode lists files found in a specific folder. +The shortcode lists files found in a specific folder. The name of the folder depends on your page type (either branch bundle, leaf bundle or page). -Currently, it supports two implementations for pages - -1. If your page is a Markdown file, attachments must be placed in a folder named like your page and ending with `.files`. +1. For simple pages, attachments must be placed in a folder named like your page and ending with `.files`. > * content > * _index.md @@ -43,17 +41,39 @@ Currently, it supports two implementations for pages > * attachment.pdf > * page.md -2. If your page is a folder, attachments must be placed in a nested `files` folder. +2. If your page is a branch or leaf bundle, attachments must be placed in a nested `_index.files` or 'index.files' folder, accordingly. + + For branch bundles: > * content > * _index.md > * page > * index.md - > * **files** + > * **index.files** > * attachment.pdf -Be aware that if you use a multilingual website, you will need to have as many folders as languages. + For leaf bundles: + > * content + > * _index.md + > * page + > * _index.md + > * **_index.files** + > * attachment.pdf + +Be aware that if you use a multilingual website, you will need to have as many folders as languages and the language code must be part of the folder name. + +Eg. for a site in English and Piratish: + + > * content + > * _index.en.md + > * _index.pir.md + > * **page.en.files** + > * attachment.pdf + > * **page.pir.files** + > * attachment.pdf + > * page.en.md + > * page.pir.md ### Parameter diff --git a/exampleSite/content/tests/attach/_index.en.md b/exampleSite/content/tests/attach/_index.en.md new file mode 100644 index 0000000000..0b1bb6c3f3 --- /dev/null +++ b/exampleSite/content/tests/attach/_index.en.md @@ -0,0 +1,8 @@ ++++ +description = "Testing Attachments Shortcode" +title = "Attachments Shortcode Test" ++++ + +Our attachment shortcode is a source of pleasure... + +{{%children containerstyle="div" style="h2" description="true" %}} diff --git a/exampleSite/content/tests/attach/_index.pir.md b/exampleSite/content/tests/attach/_index.pir.md new file mode 100644 index 0000000000..eb54af9a5b --- /dev/null +++ b/exampleSite/content/tests/attach/_index.pir.md @@ -0,0 +1,5 @@ ++++ +description = "Test'n Attachments Shorrrtcode" +title = "Attachments Shorrrtcode Test" ++++ +{{< piratify >}} \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach1/_index.en.files/hugo.txt b/exampleSite/content/tests/attach/attach1/_index.en.files/hugo.txt new file mode 100644 index 0000000000..19b69f481f --- /dev/null +++ b/exampleSite/content/tests/attach/attach1/_index.en.files/hugo.txt @@ -0,0 +1 @@ +This is a small text \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach1/_index.en.md b/exampleSite/content/tests/attach/attach1/_index.en.md new file mode 100644 index 0000000000..0530692923 --- /dev/null +++ b/exampleSite/content/tests/attach/attach1/_index.en.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Branch Test" ++++ + +{{% attachments /%}} diff --git a/exampleSite/content/tests/attach/attach1/_index.pir.files/NoTreasure.txt b/exampleSite/content/tests/attach/attach1/_index.pir.files/NoTreasure.txt new file mode 100644 index 0000000000..f7b9fda214 --- /dev/null +++ b/exampleSite/content/tests/attach/attach1/_index.pir.files/NoTreasure.txt @@ -0,0 +1 @@ +Harrr, nothn' to see herre \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach1/_index.pir.md b/exampleSite/content/tests/attach/attach1/_index.pir.md new file mode 100644 index 0000000000..08f83be2ba --- /dev/null +++ b/exampleSite/content/tests/attach/attach1/_index.pir.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Brrranch Test" ++++ + +{{% attachments /%}} diff --git a/exampleSite/content/tests/attach/attach2/index.en.files/hugo.txt b/exampleSite/content/tests/attach/attach2/index.en.files/hugo.txt new file mode 100644 index 0000000000..19b69f481f --- /dev/null +++ b/exampleSite/content/tests/attach/attach2/index.en.files/hugo.txt @@ -0,0 +1 @@ +This is a small text \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach2/index.en.md b/exampleSite/content/tests/attach/attach2/index.en.md new file mode 100644 index 0000000000..67712af73c --- /dev/null +++ b/exampleSite/content/tests/attach/attach2/index.en.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Leaf Test" ++++ + +{{% attachments /%}} diff --git a/exampleSite/content/tests/attach/attach2/index.pir.files/NoTreasure.txt b/exampleSite/content/tests/attach/attach2/index.pir.files/NoTreasure.txt new file mode 100644 index 0000000000..f7b9fda214 --- /dev/null +++ b/exampleSite/content/tests/attach/attach2/index.pir.files/NoTreasure.txt @@ -0,0 +1 @@ +Harrr, nothn' to see herre \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach2/index.pir.md b/exampleSite/content/tests/attach/attach2/index.pir.md new file mode 100644 index 0000000000..67712af73c --- /dev/null +++ b/exampleSite/content/tests/attach/attach2/index.pir.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Leaf Test" ++++ + +{{% attachments /%}} diff --git a/exampleSite/content/tests/attach/attach3.en.files/hugo.txt b/exampleSite/content/tests/attach/attach3.en.files/hugo.txt new file mode 100644 index 0000000000..19b69f481f --- /dev/null +++ b/exampleSite/content/tests/attach/attach3.en.files/hugo.txt @@ -0,0 +1 @@ +This is a small text \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach3.en.md b/exampleSite/content/tests/attach/attach3.en.md new file mode 100644 index 0000000000..fda813697d --- /dev/null +++ b/exampleSite/content/tests/attach/attach3.en.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Page Test" ++++ + +{{% attachments /%}} diff --git a/exampleSite/content/tests/attach/attach3.pir.files/NoTreasure.txt b/exampleSite/content/tests/attach/attach3.pir.files/NoTreasure.txt new file mode 100644 index 0000000000..f7b9fda214 --- /dev/null +++ b/exampleSite/content/tests/attach/attach3.pir.files/NoTreasure.txt @@ -0,0 +1 @@ +Harrr, nothn' to see herre \ No newline at end of file diff --git a/exampleSite/content/tests/attach/attach3.pir.md b/exampleSite/content/tests/attach/attach3.pir.md new file mode 100644 index 0000000000..fda813697d --- /dev/null +++ b/exampleSite/content/tests/attach/attach3.pir.md @@ -0,0 +1,5 @@ ++++ +title = "Attachments Page Test" ++++ + +{{% attachments /%}} diff --git a/layouts/partials/shortcodes/attachments.html b/layouts/partials/shortcodes/attachments.html index f7cc0b23c0..17c035c91a 100644 --- a/layouts/partials/shortcodes/attachments.html +++ b/layouts/partials/shortcodes/attachments.html @@ -17,19 +17,25 @@ {{- end }} {{- $sort := .sort | default "asc" }} {{- $pattern := .pattern | default "" }} +{{- $defaultLanguage := (index $context.Site.Home.AllTranslations 0).Lang }} +{{- $defaultLanguagePage := index (where $context.Page.AllTranslations "Language.Lang" $defaultLanguage) 0 }} +{{- $defaultUrlPrefix := strings.TrimRight "/" $defaultLanguagePage.RelPermalink }} +{{- $urlPrefix := strings.TrimRight "/" $context.Page.RelPermalink }} {{- with $context }}
{{ if $icon }}{{ end }}{{ if and $icon $title }} {{ end }}{{ $title }}
    - {{- $filesName := "files" }} - {{- if ne .Page.File.BaseFileName "index" }} - {{- $filesName = printf "%s.files" .Page.File.BaseFileName }} - {{- end }} {{- $fileLink := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }} {{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }} {{- $fileDir := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }} {{- $fileDir = replace $fileDir "\\" "/" }} - {{- range sort (readDir (printf "%s%s" $fileDir $filesName) ) "Name" $sort }} + {{- $filesName := printf "%s.files" .Page.File.BaseFileName }} + {{- if and (eq .Page.File.BaseFileName "index") (fileExists (printf "%sfiles" $fileDir)) }} + {{- $c := "" }}{{/* backward compat to < 5.9.0 behavior */}} + {{- $filesName = "files" }} + {{- end }} + {{- $dir := printf "%s%s" $fileDir $filesName }} + {{- range sort (readDir $dir) "Name" $sort }} {{- if findRE $pattern .Name}} {{- $size := .Size }} {{- $unit := "Byte-symbol" }} @@ -42,7 +48,10 @@ {{- $unit = "Megabyte-symbol" }} {{- end }} {{- $unitsymbol := $unit | T }} -
  • {{.Name}} ({{$size}} {{$unitsymbol}})
  • + {{- $link := (printf "%s%s/%s" $fileLink $filesName .Name) | relLangURL }} + {{- $c := "" }}{{/* Hugo stores the attachments always in the default language subdirectory */}} + {{- $link = replace $link $urlPrefix $defaultUrlPrefix 1 }} +
  • {{.Name}} ({{$size}} {{$unitsymbol}})
  • {{- end }} {{- end }}