bglug.it/layouts/_default/single.html
paspo 146ae02f84 visualizzazione licenza post/evento (#223)
Visualizzazione della licenza indicata nel front-matter di un post/evento.
Supporta markdown.

Esempio:
```markdown
license: "[CC-BY-SA](https://rickroll.it)"
```

rif. #209

Reviewed-on: BgLUG/bglug.it#223
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
2024-09-13 21:42:06 +00:00

93 lines
3.4 KiB
HTML

{{ define "main" }}
<header>
<h2>{{ .Title }}</h2>
<p>{{ .Description }}</p>
{{- with .Params.author -}}
di {{ . | markdownify }}<br/>
{{- end -}}
{{ if .Site.Params.show_post_dates | default true }}
{{- with .Date }}<time>{{ . | time.Format ":date_medium" }}</time>{{ end }}
{{ end }}
{{- with .Params.license -}}
<div class="license">{{ T "license" }}: {{ . | markdownify }}</div>
{{ end }}
{{ partial "tags.html" . }}
</header>
{{- if or .Params.image .Params.featured }}
{{- $maxHeight := 600 -}}
{{- $ratio := 2.33 -}}
{{ $rasters := slice "jpeg" "png" }}
{{- $img := "#" -}}
{{- if .Params.image -}}
{{/* se è stata definita un'immagine featured */}}
{{- $img = .Page.Resources.GetMatch .Params.image -}}
{{- end -}}
{{- if .Params.featured -}}
{{/* se è stata definita un'immagine featured */}}
{{- $img = .Page.Resources.GetMatch .Params.featured -}}
{{- end -}}
<span class="image featured"><figure>
{{- if in $rasters $img.MediaType.SubType -}}
{{- if gt $img.Height $maxHeight -}}
{{- $img = $img.Resize (printf "x%d webp q50" $maxHeight) -}}
{{- end -}}
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" {{- if ge (mul $img.Height $ratio) $img.Width -}}style="width: auto;" {{- end -}}/>
{{ else }}
<img src="{{ $img.RelPermalink }}" alt="{{ .Params.image_alt }}" />
{{- end -}}
{{- with .Params.image_caption -}}
<figcaption style="max-width: {{- $img.Width -}}px;">{{- . | markdownify -}}</figcaption>
{{- end -}}
</figure></span>
{{ end }}
{{- .Content }}
{{ if (findRE "<pre" .Content 1) }}
<script>
function addCopyButtons(clipboard) {
document.querySelectorAll('pre > code').forEach(function (codeBlock) {
var button = document.createElement('button');
button.className = 'copy-code-button';
button.type = 'button';
button.innerText = 'Copy';
button.addEventListener('click', function () {
clipboard.writeText(codeBlock.innerText).then(function () {
/* Chrome doesn't seem to blur automatically,
leaving the button in a focused state. */
button.blur();
button.innerText = 'Copied!';
setTimeout(function () {
button.innerText = 'Copy';
}, 2000);
}, function (error) {
button.innerText = 'Error';
});
});
var pre = codeBlock.parentNode;
if (pre.parentNode.classList.contains('highlight')) {
var highlight = pre.parentNode;
highlight.parentNode.insertBefore(button, highlight);
} else {
pre.parentNode.insertBefore(button, pre);
}
});
}
if (navigator && navigator.clipboard) {
addCopyButtons(navigator.clipboard);
}
</script>
{{ end }}
{{ end }}