Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion exampleSite/content/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"%}})
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/_index.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"%}})
Expand Down
85 changes: 0 additions & 85 deletions exampleSite/content/shortcodes/attachments.en.md

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
85 changes: 0 additions & 85 deletions exampleSite/content/shortcodes/attachments.fr.md

This file was deleted.

61 changes: 61 additions & 0 deletions exampleSite/content/shortcodes/attachments/_index.en.md
Original file line number Diff line number Diff line change
@@ -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" /%}}
62 changes: 62 additions & 0 deletions exampleSite/content/shortcodes/attachments/_index.fr.md
Original file line number Diff line number Diff line change
@@ -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" /%}}
29 changes: 11 additions & 18 deletions layouts/shortcodes/attachments.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,26 @@
<i class="fas fa-paperclip" aria-hidden="true"></i>
{{with .Get "title"}}{{.}}{{else}}{{T "Attachments-label"}}{{end}}
</label>
{{if eq .Page.File.BaseFileName "index"}}
{{$.Scratch.Add "filesName" "files"}}
{{else}}
{{$.Scratch.Add "filesName" (printf "%s.files" .Page.File.BaseFileName)}}
{{end}}
<div class="attachments-files">
{{ 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")) }}
<li>
<a href="{{ (printf "%s%s/%s" $fileDir ($.Scratch.Get "filesName") .Name) | relURL }}" >
<a href="{{ .Permalink }}">
{{.Name}}
</a>
({{div .Size 1024 }} ko)
({{div (len .Content) 1024 }} kb)
</li>
{{end}}
{{else}}
<li>
<a href="{{ (printf "%s%s/%s" $fileDir ($.Scratch.Get "filesName") .Name) | relURL }}" >
{{.Name}}
</a>
({{div .Size 1024 }} ko)
</li>
{{ range ($.Page.Resources.Match "**") }}
<li>
<a href="{{ .Permalink }}">
{{.Name}}
</a>
({{div (len .Content) 1024 }} kb)
</li>
{{end}}
{{end}}
{{end}}
</div>
{{.Inner}}
</section>