diff --git a/exampleSite/content/_index.en.md b/exampleSite/content/_index.en.md index a36357957cf..566741d8dd3 100644 --- a/exampleSite/content/_index.en.md +++ b/exampleSite/content/_index.en.md @@ -18,7 +18,7 @@ This theme is a partial porting of the [Learn theme](http://learn.getgrav.org/) * **Unlimited menu levels** * **Automatic next/prev buttons to navigate through menu entries** * [Image resizing, shadow...]({{%relref "cont/markdown.en.md#images" %}}) -* [Attachments files]({{%relref "shortcodes/attachments.en.md" %}}) +* [Attachments files]({{%relref "shortcodes/attachments/_index.en.md" %}}) * [List child pages]({{%relref "shortcodes/children/_index.md" %}}) * [Mermaid diagram]({{%relref "shortcodes/mermaid.en.md" %}}) (flowchart, sequence, gantt) * [Customizable look and feel and themes variants]({{%relref "basics/style-customization/_index.md"%}}) diff --git a/exampleSite/content/_index.fr.md b/exampleSite/content/_index.fr.md index 40b2dc35215..72a547e7fa9 100644 --- a/exampleSite/content/_index.fr.md +++ b/exampleSite/content/_index.fr.md @@ -18,7 +18,7 @@ Ce thème est un portage partiel du [thème Learn](http://learn.getgrav.org/) de * **Nombre de niveau infini dans le menu** * **Boutons suivant/précédent automatiquement générés pour naviguer entre les items du menu** * [Taille d'image, ombres...]({{%relref "cont/markdown.fr.md#images" %}}) -* [Fichiers joints]({{%relref "shortcodes/attachments.fr.md" %}}) +* [Fichiers joints]({{%relref "shortcodes/attachments/_index.fr.md" %}}) * [Lister les pages filles]({{%relref "shortcodes/children/_index.md" %}}) * [Diagrammes Mermaid]({{%relref "shortcodes/mermaid.fr.md" %}}) (flowchart, sequence, gantt) * [Style configurable and variantes de couleurs]({{%relref "basics/style-customization/_index.md"%}}) diff --git a/exampleSite/content/shortcodes/attachments.en.md b/exampleSite/content/shortcodes/attachments.en.md deleted file mode 100644 index 8a2429cf304..00000000000 --- a/exampleSite/content/shortcodes/attachments.en.md +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: Attachments -description : "The Attachments shortcode displays a list of files attached to a page." ---- - -The Attachments shortcode displays a list of files attached to a page. - -{{% attachments /%}} - -## Usage - -The shortcurt lists files found in a **specific folder**. -Currently, it support two implementations for pages - -1. If your page is a markdown file, attachements must be placed in a **folder** named like your page and ending with **.files**. - - > * content - > * _index.md - > * page.files - > * attachment.pdf - > * page.md - -2. If your page is a **folder**, attachements must be placed in a nested **'files'** folder. - - > * content - > * _index.md - > * page - > * index.md - > * files - > * attachment.pdf - -Be aware that if you use a multilingual website, you will need to have as many folders as languages. - -That's all! - -### Parameters - -| Parameter | Default | Description | -|:--|:--|:--| -| title | "Attachments" | List's title | -| style | "" | Choose between "orange", "grey", "blue" and "green" for nice style | -| pattern | ".*" | A regular expressions, used to filter the attachments by file name.

The **pattern** parameter value must be [regular expressions](https://en.wikipedia.org/wiki/Regular_expression). - -For example: - -* To match a file suffix of 'jpg', use **.*jpg** (not *.jpg). -* To match file names ending in 'jpg' or 'png', use **.*(jpg|png)** - -### Examples - -#### List of attachments ending in pdf or mp4 - - - {{%/*attachments title="Related files" pattern=".*(pdf|mp4)"/*/%}} - -renders as - -{{%attachments title="Related files" pattern=".*(pdf|mp4)"/%}} - -#### Colored styled box - - {{%/*attachments style="orange" /*/%}} - -renders as - -{{% attachments style="orange" /%}} - - - {{%/*attachments style="grey" /*/%}} - -renders as - -{{% attachments style="grey" /%}} - - {{%/*attachments style="blue" /*/%}} - -renders as - -{{% attachments style="blue" /%}} - - {{%/*attachments style="green" /*/%}} - -renders as - -{{% attachments style="green" /%}} diff --git a/exampleSite/content/shortcodes/attachments.fr.files/BachGavotteShort.mp3 b/exampleSite/content/shortcodes/attachments.fr.files/BachGavotteShort.mp3 deleted file mode 100644 index 94e3d0e539c..00000000000 Binary files a/exampleSite/content/shortcodes/attachments.fr.files/BachGavotteShort.mp3 and /dev/null differ diff --git a/exampleSite/content/shortcodes/attachments.fr.files/Carroll_AliceAuPaysDesMerveilles.pdf b/exampleSite/content/shortcodes/attachments.fr.files/Carroll_AliceAuPaysDesMerveilles.pdf deleted file mode 100644 index 97377e99b17..00000000000 Binary files a/exampleSite/content/shortcodes/attachments.fr.files/Carroll_AliceAuPaysDesMerveilles.pdf and /dev/null differ diff --git a/exampleSite/content/shortcodes/attachments.fr.files/adivorciarsetoca00cape.pdf b/exampleSite/content/shortcodes/attachments.fr.files/adivorciarsetoca00cape.pdf deleted file mode 100644 index e589c73e97e..00000000000 Binary files a/exampleSite/content/shortcodes/attachments.fr.files/adivorciarsetoca00cape.pdf and /dev/null differ diff --git a/exampleSite/content/shortcodes/attachments.fr.files/hugo.png b/exampleSite/content/shortcodes/attachments.fr.files/hugo.png deleted file mode 100644 index 48acf346c9e..00000000000 Binary files a/exampleSite/content/shortcodes/attachments.fr.files/hugo.png and /dev/null differ diff --git a/exampleSite/content/shortcodes/attachments.fr.files/movieselectricsheep-flock-244-32500-2.mp4 b/exampleSite/content/shortcodes/attachments.fr.files/movieselectricsheep-flock-244-32500-2.mp4 deleted file mode 100644 index 9f1fe564563..00000000000 Binary files a/exampleSite/content/shortcodes/attachments.fr.files/movieselectricsheep-flock-244-32500-2.mp4 and /dev/null differ diff --git a/exampleSite/content/shortcodes/attachments.fr.md b/exampleSite/content/shortcodes/attachments.fr.md deleted file mode 100644 index c24093915cf..00000000000 --- a/exampleSite/content/shortcodes/attachments.fr.md +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: Attachments (Pièces jointes) -description : "The Attachments shortcode displays a list of files attached to a page." ---- - -Le shortcode *Attachments* affiche une liste de pièces jointes d'une page. - -{{% attachments /%}} - -## Utilisation - -Le shortcode affiche la liste de fichiers trouvés dans un **dossier spécifique** -A l'heure actuelle, il supporte deux implémentations - -1. Si votre page est un fichier Markdown, les pièces jointes doivent être placée dans un **dossier** nommé comme le nom de la page et suffixé par **.files**. - - > * content - > * _index.md - > * page.files - > * attachment.pdf - > * page.md - -2. Si votre page est un **dossier**, les pièces jointes doivent être placées dans un dossier fils **'files'**. - - > * content - > * _index.md - > * page - > * index.md - > * files - > * attachment.pdf - -Attention, si votre site est multi-langue, vous devrez avec autant de dossier qu'il y a de langues. - -C'est tout ! - -### Paramètres - -| Paramètre | Défaut | Description | -|:--|:--|:--| -| title | "Pièces jointes" | Titre de la liste | -| style | "" | Choisir entre "orange", "grey", "blue" et "green" pour un style plus sympa | -| pattern | ".*" | Une expression régulière, utilisée pour filtrer les pièces jointes par leur nom de fichier.

Le paramètre **pattern** doit être une [expression régulière](https://en.wikipedia.org/wiki/Regular_expression). - -Par exemple: - -* Pour trouver les fichiers avec le suffixe 'jpg', utilisez **.*jpg** (pas *.jpg). -* Pour trouver les fichiers avec les suffixe 'jpg' ou 'png', utilisez **.*(jpg|png)** - -### Exemples - -#### Lister les pièces jointes de type pdf ou mp4 - - - {{%/*attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/*/%}} - -s'affiche comme - -{{%attachments title="Fichiers associés" pattern=".*(pdf|mp4)"/%}} - -#### Modifier le style - - {{%/*attachments style="orange" /*/%}} - -s'affiche comme - -{{% attachments style="orange" /%}} - - - {{%/*attachments style="grey" /*/%}} - -s'affiche comme - -{{% attachments style="grey" /%}} - - {{%/*attachments style="blue" /*/%}} - -s'affiche comme - -{{% attachments style="blue" /%}} - - {{%/*attachments style="green" /*/%}} - -s'affiche comme - -{{% attachments style="green" /%}} \ No newline at end of file diff --git a/exampleSite/content/shortcodes/attachments.en.files/BachGavotteShort.mp3 b/exampleSite/content/shortcodes/attachments/BachGavotteShort.mp3 similarity index 100% rename from exampleSite/content/shortcodes/attachments.en.files/BachGavotteShort.mp3 rename to exampleSite/content/shortcodes/attachments/BachGavotteShort.mp3 diff --git a/exampleSite/content/shortcodes/attachments.en.files/Carroll_AliceAuPaysDesMerveilles.pdf b/exampleSite/content/shortcodes/attachments/Carroll_AliceAuPaysDesMerveilles.pdf similarity index 100% rename from exampleSite/content/shortcodes/attachments.en.files/Carroll_AliceAuPaysDesMerveilles.pdf rename to exampleSite/content/shortcodes/attachments/Carroll_AliceAuPaysDesMerveilles.pdf diff --git a/exampleSite/content/shortcodes/attachments/_index.en.md b/exampleSite/content/shortcodes/attachments/_index.en.md new file mode 100644 index 00000000000..dd77b8729f5 --- /dev/null +++ b/exampleSite/content/shortcodes/attachments/_index.en.md @@ -0,0 +1,61 @@ +--- +title: Attachments +description : "The Attachments shortcode displays a list of files attached to a page." +--- + +The Attachments shortcode displays a list of files attached to a page. + +{{% attachments /%}} + +## Usage + +The shortcurt lists files/resources found in the [page bundle](https://gohugo.io/content-management/page-bundles/). + +### Parameters + +| Parameter | Default | Description | +|:--|:--|:--| +| title | "Attachments" | List's title | +| style | "" | Choose between "orange", "grey", "blue" and "green" for nice style | +| pattern | ".*" | A glob pattern, used to filter the attachments by file name. The `pattern` parameter value must be a [glob pattern](https://github.com/gobwas/glob/blob/master/readme.md). + +For example: + +* To match a file suffix of 'jpg', use `*.jpg`. +* To match file names ending in 'jpg' or 'png', use `*.{jpg,png}` + +### Examples + +#### List of attachments ending in pdf or mp4 + + {{%/*attachments title="Related files" pattern="*.{pdf,mp4}"/*/%}} + +renders as + +{{%attachments title="Related files" pattern="*.{pdf,mp4}"/%}} + +#### Colored styled box + + {{%/*attachments style="orange" /*/%}} + +renders as + +{{% attachments style="orange" /%}} + + {{%/*attachments style="grey" /*/%}} + +renders as + +{{% attachments style="grey" /%}} + + {{%/*attachments style="blue" /*/%}} + +renders as + +{{% attachments style="blue" /%}} + + {{%/*attachments style="green" /*/%}} + +renders as + +{{% attachments style="green" /%}} diff --git a/exampleSite/content/shortcodes/attachments/_index.fr.md b/exampleSite/content/shortcodes/attachments/_index.fr.md new file mode 100644 index 00000000000..d44823c4be8 --- /dev/null +++ b/exampleSite/content/shortcodes/attachments/_index.fr.md @@ -0,0 +1,62 @@ +--- +title: Attachments (Pièces jointes) +description : "The Attachments shortcode displays a list of files attached to a page." +--- + +Le shortcode *Attachments* affiche une liste de pièces jointes d'une page. + +{{% attachments /%}} + +## Utilisation + +Le shortcode affiche la liste de fichiers trouvés dans un [page bundle](https://gohugo.io/content-management/page-bundles/). + +### Paramètres + +| Paramètre | Défaut | Description | +|:--|:--|:--| +| title | "Pièces jointes" | Titre de la liste | +| style | "" | Choisir entre "orange", "grey", "blue" et "green" pour un style plus sympa | +| pattern | ".*" | Une expression glob, utilisée pour filtrer les pièces jointes par leur nom de fichier. Le paramètre `pattern` doit être une [glob pattern](https://github.com/gobwas/glob/blob/master/readme.md). + +Par exemple: + +* Pour trouver les fichiers avec le suffixe 'jpg', utilisez `*.jpg`. +* Pour trouver les fichiers avec les suffixe 'jpg' ou 'png', utilisez `*.{jpg,png}` + +### Exemples + +#### Lister les pièces jointes de type pdf ou mp4 + + + {{%/*attachments title="Fichiers associés" pattern="*.{jpg,mp4}"/*/%}} + +s'affiche comme + +{{%attachments title="Fichiers associés" pattern="*.{jpg,mp4}"/%}} + +#### Modifier le style + + {{%/*attachments style="orange" /*/%}} + +s'affiche comme + +{{% attachments style="orange" /%}} + + {{%/*attachments style="grey" /*/%}} + +s'affiche comme + +{{% attachments style="grey" /%}} + + {{%/*attachments style="blue" /*/%}} + +s'affiche comme + +{{% attachments style="blue" /%}} + + {{%/*attachments style="green" /*/%}} + +s'affiche comme + +{{% attachments style="green" /%}} diff --git a/exampleSite/content/shortcodes/attachments.en.files/adivorciarsetoca00cape.pdf b/exampleSite/content/shortcodes/attachments/adivorciarsetoca00cape.pdf similarity index 100% rename from exampleSite/content/shortcodes/attachments.en.files/adivorciarsetoca00cape.pdf rename to exampleSite/content/shortcodes/attachments/adivorciarsetoca00cape.pdf diff --git a/exampleSite/content/shortcodes/attachments.en.files/hugo.png b/exampleSite/content/shortcodes/attachments/hugo.png similarity index 100% rename from exampleSite/content/shortcodes/attachments.en.files/hugo.png rename to exampleSite/content/shortcodes/attachments/hugo.png diff --git a/exampleSite/content/shortcodes/attachments.en.files/movieselectricsheep-flock-244-32500-2.mp4 b/exampleSite/content/shortcodes/attachments/movieselectricsheep-flock-244-32500-2.mp4 similarity index 100% rename from exampleSite/content/shortcodes/attachments.en.files/movieselectricsheep-flock-244-32500-2.mp4 rename to exampleSite/content/shortcodes/attachments/movieselectricsheep-flock-244-32500-2.mp4 diff --git a/layouts/shortcodes/attachments.html b/layouts/shortcodes/attachments.html index 1725fc46406..1fe81640dda 100644 --- a/layouts/shortcodes/attachments.html +++ b/layouts/shortcodes/attachments.html @@ -4,33 +4,26 @@ {{with .Get "title"}}{{.}}{{else}}{{T "Attachments-label"}}{{end}} - {{if eq .Page.File.BaseFileName "index"}} - {{$.Scratch.Add "filesName" "files"}} - {{else}} - {{$.Scratch.Add "filesName" (printf "%s.files" .Page.File.BaseFileName)}} - {{end}}
- {{ range (readDir (printf "./content/%s%s" .Page.File.Dir ($.Scratch.Get "filesName")) ) }} - {{ $fileDir := replace $.Page.File.Dir "\\" "/" }} {{if ($.Get "pattern")}} - {{if (findRE ($.Get "pattern") .Name)}} + {{ range ($.Page.Resources.Match ($.Get "pattern")) }}
  • - + {{.Name}} - ({{div .Size 1024 }} ko) + ({{div (len .Content) 1024 }} kb)
  • {{end}} {{else}} -
  • - - {{.Name}} - - ({{div .Size 1024 }} ko) -
  • + {{ range ($.Page.Resources.Match "**") }} +
  • + + {{.Name}} + + ({{div (len .Content) 1024 }} kb) +
  • + {{end}} {{end}} - {{end}}
    {{.Inner}} -