mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-27 01:33:04 +00:00
attachments: fix incorrect links for defaultContentLanguageInSubdir=true #425
This commit is contained in:
parent
838f13db0f
commit
18abaaf4f8
18 changed files with 99 additions and 15 deletions
|
@ -124,7 +124,7 @@ disableHugoGeneratorInject = true
|
||||||
|
|
||||||
[Languages.pir]
|
[Languages.pir]
|
||||||
title = "Cap'n Hugo Relearrrn Theme"
|
title = "Cap'n Hugo Relearrrn Theme"
|
||||||
weight = 1
|
weight = 2
|
||||||
languageName = "Arrr! ☠ Pirrrates ☠"
|
languageName = "Arrr! ☠ Pirrrates ☠"
|
||||||
landingPageName = "<i class='fas fa-home'></i> Arrr! Home"
|
landingPageName = "<i class='fas fa-home'></i> Arrr! Home"
|
||||||
|
|
||||||
|
|
|
@ -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.<LANGCODE>.files` or `index.<LANGCODE>.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.
|
- {{% badge style="note" title=" " %}}Change{{% /badge %}} Absolute links prefixed with `http://` or `https://` are now opened in a separate browser tab.
|
||||||
|
|
||||||
|
|
|
@ -31,11 +31,9 @@ While the examples are using shortcodes with named parameter you are free to als
|
||||||
{{% /tab %}}
|
{{% /tab %}}
|
||||||
{{< /tabs >}}
|
{{< /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. For simple pages, attachments must be placed in a folder named like your page and ending with `.files`.
|
||||||
|
|
||||||
1. If your page is a Markdown file, attachments must be placed in a folder named like your page and ending with `.files`.
|
|
||||||
|
|
||||||
> * content
|
> * content
|
||||||
> * _index.md
|
> * _index.md
|
||||||
|
@ -43,17 +41,39 @@ Currently, it supports two implementations for pages
|
||||||
> * attachment.pdf
|
> * attachment.pdf
|
||||||
> * page.md
|
> * 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
|
> * content
|
||||||
> * _index.md
|
> * _index.md
|
||||||
> * page
|
> * page
|
||||||
> * index.md
|
> * index.md
|
||||||
> * **files**
|
> * **index.files**
|
||||||
> * attachment.pdf
|
> * 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
|
### Parameter
|
||||||
|
|
||||||
|
|
8
exampleSite/content/tests/attach/_index.en.md
Normal file
8
exampleSite/content/tests/attach/_index.en.md
Normal file
|
@ -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" %}}
|
5
exampleSite/content/tests/attach/_index.pir.md
Normal file
5
exampleSite/content/tests/attach/_index.pir.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
description = "Test'n Attachments Shorrrtcode"
|
||||||
|
title = "Attachments Shorrrtcode Test"
|
||||||
|
+++
|
||||||
|
{{< piratify >}}
|
|
@ -0,0 +1 @@
|
||||||
|
This is a small text
|
5
exampleSite/content/tests/attach/attach1/_index.en.md
Normal file
5
exampleSite/content/tests/attach/attach1/_index.en.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Branch Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -0,0 +1 @@
|
||||||
|
Harrr, nothn' to see herre
|
5
exampleSite/content/tests/attach/attach1/_index.pir.md
Normal file
5
exampleSite/content/tests/attach/attach1/_index.pir.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Brrranch Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -0,0 +1 @@
|
||||||
|
This is a small text
|
5
exampleSite/content/tests/attach/attach2/index.en.md
Normal file
5
exampleSite/content/tests/attach/attach2/index.en.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Leaf Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -0,0 +1 @@
|
||||||
|
Harrr, nothn' to see herre
|
5
exampleSite/content/tests/attach/attach2/index.pir.md
Normal file
5
exampleSite/content/tests/attach/attach2/index.pir.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Leaf Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -0,0 +1 @@
|
||||||
|
This is a small text
|
5
exampleSite/content/tests/attach/attach3.en.md
Normal file
5
exampleSite/content/tests/attach/attach3.en.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Page Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -0,0 +1 @@
|
||||||
|
Harrr, nothn' to see herre
|
5
exampleSite/content/tests/attach/attach3.pir.md
Normal file
5
exampleSite/content/tests/attach/attach3.pir.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
+++
|
||||||
|
title = "Attachments Page Test"
|
||||||
|
+++
|
||||||
|
|
||||||
|
{{% attachments /%}}
|
|
@ -17,19 +17,25 @@
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $sort := .sort | default "asc" }}
|
{{- $sort := .sort | default "asc" }}
|
||||||
{{- $pattern := .pattern | default "" }}
|
{{- $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 }}
|
{{- with $context }}
|
||||||
<div class="box attachments cstyle {{ $style }}">
|
<div class="box attachments cstyle {{ $style }}">
|
||||||
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title }}</div>
|
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title }}</div>
|
||||||
<ul class="box-content attachments-files">
|
<ul class="box-content attachments-files">
|
||||||
{{- $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 := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }}
|
||||||
{{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }}
|
{{- $fileLink = replace (replace $fileLink "\\" "/") "content/" "" }}
|
||||||
{{- $fileDir := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }}
|
{{- $fileDir := printf "%s/%s" (.Page.Language.ContentDir | default "content") .Page.File.Dir }}
|
||||||
{{- $fileDir = replace $fileDir "\\" "/" }}
|
{{- $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}}
|
{{- if findRE $pattern .Name}}
|
||||||
{{- $size := .Size }}
|
{{- $size := .Size }}
|
||||||
{{- $unit := "Byte-symbol" }}
|
{{- $unit := "Byte-symbol" }}
|
||||||
|
@ -42,7 +48,10 @@
|
||||||
{{- $unit = "Megabyte-symbol" }}
|
{{- $unit = "Megabyte-symbol" }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- $unitsymbol := $unit | T }}
|
{{- $unitsymbol := $unit | T }}
|
||||||
<li><a href="{{ (printf "%s%s/%s" $fileLink $filesName .Name) | relURL }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
|
{{- $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 }}
|
||||||
|
<li><a href="{{ $link }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Reference in a new issue