List 9 files published after the last 6 within the recommandations section.
{{ range first 9 ( after 6 (where site.RegularPages.ByPublishDate.Reverse "Section" "recommandations" )) }}
... some code
{{ end }}
{{ with .Params.Foo }}
<p class="typography-overline">Foo items separated by a , </p>
<p>{{ delimit . ", " }}</p>
{{ end }}
or enumerate in a JSON
{
"tags": [{{ range .Params.Tags }}{{. | jsonify}}{{end}}]
}
or save the first item of an array as a string in a JSON
{
"tags": "{{ range first 1 .Params.Tags }}{{.}}{{end}}"
}
{{ if gt (len .Params.Tags) 0 }} some content {{ end }}
Easy because WebAppManifest
is already defined.
In config.toml, set this output:
[outputs]
home = ["HTML", "JSON", "RSS", "WebAppManifest"]
In your /layouts
folder, add index.webmanifest
with following content:
{
"name": "{{ .Site.Title }}",
"short_name": "{{ .Site.Title }}",
"description": "{{ .Site.Params.Description }}",
"lang": "{{ .Site.LanguageCode }}",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "/?utm_source=pwa",
"scope": "/",
"orientation": "portrait",
"display": "minimal-ui",
"theme_color": "#4150f5",
"background_color": "#ffffff"
}
After compilation, you'll find a manifest.webmanifest
in your public
folder.
We have to create our own type, I call it API
.
In config.toml, set this output:
[outputs]
home = ["HTML", "JSON", "RSS", "WebAppManifest", "API"]
[outputFormats]
[outputFormats.API]
name = "API"
mediaType = "application/json"
baseName = "api"
isPlainText = true
Create a file in your layouts
folder: api.json
with following content.
[ {{- $i := 0 -}}
{{- range where .Site.RegularPages "Section" "ne" "" -}}
{{- if not .Params.noSearch -}}
{{- if gt $i 0 }},{{ end -}}
{"date":"{{ .Date.Unix }}", "url":"{{ .RelPermalink }}", "title":{{ .Title | jsonify }}, "summary":{{ .Params.Synonyms | jsonify }}, "content":{{ .Plain | htmlUnescape | jsonify }}, "tags":[ {{- $t := 0 }}{{- range .Param "tags" -}}{{ if gt $t 0 }},{{ end }}{{ . | jsonify }}{{ $t = add $t 1 }}{{ end -}} ], "section": {{ .Section | jsonify -}} }
{{- $i = add $i 1 -}}
{{- end -}}
{{- end -}} ]
After compilation, you'll find the generated api.json
in your public
folder.
A taxonomy specialites
is only used for building a menu (it may change in a near future).
[taxonomies]
specialite = "specialites"
tag = "tags"
[[cascade]]
[cascade._build]
list = 'never'
render = 'never'
[cascade._target]
kind = '{taxonomy,term}'
path = '{/specialites,/specialites/**}'