Omphaloskepsis-2/layouts/partials/cite.html.tmpl
2024-04-02 20:36:21 +01:00

78 lines
2.9 KiB
Cheetah

<!--
Renders a work citation with semantic markup, called using the `cite` shortcode.
@params cite URI for work. Optional.
@params citeStyle Force a citation style. Optional.
@params href URI for citation, or 'asCite' to use value of `cite`. Optional.
@params schemaType The Schema.org `itemtype` value. Default 'CreativeWork'.
@params shortTitle Abbreviated display title. Optional.
@params title Title of the work to display.
@params titleLang Language code of a foreign-language work's title. Optional.
@params titleTr English translation of a foreign-language work's title. Optional.
-->
<!-- Optional parameter overrides (for nested citations) -->
{{- $cite := default .Params.cite ( .Scratch.Get "cite" ) -}}
{{- $title := default .Params.title ( .Scratch.Get "title" ) -}}
{{- $titleLang := default .Params.titleLang ( .Scratch.Get "titleLang" ) -}}
{{- $titleTr := default .Params.titleTr ( .Scratch.Get "titleTr" ) -}}
{{- $schemaType := default .Params.schemaType ( .Scratch.Get "schemaType" ) -}}
<!-- Validation -->
<!-- TODO: check `.Params.cite` is URI -->
{{- if ( and ( isset .Params "citeStyle" ) ( not ( in ( slice "inherit" "enquote" "normal" ) .Params.citeStyle ) ) ) -}}
{{- erroridf "invalid-citeStyle" "Invalid `citeStyle` value %q for %q" .Params.citeStyle $title -}}
{{- end -}}
<!-- TODO: check `.Params.href` is URI or 'asCite' -->
{{- if ( and $schemaType ( not ( in $.Site.Data.itemtypes $schemaType ) ) ) -}}
{{- erroridf "invalid-schemaType" "Invalid Schema.org type value %q for %q" $schemaType $title -}}
{{- end -}}
{{- if ( or $titleLang $titleTr ) -}}
{{- if ( not ( and $titleLang $titleTr ) ) -}}
{{- erroridf "invalid-foreign-title" "Must have both title translation and language set for foreign language title %q" $title -}}
{{- end -}}
{{- end -}}
<!-- Rendering -->
{{- $itemType := default "CreativeWork" $schemaType -}}
{{- if ( or ( in $.Site.Data.itemtypes $itemType ) ( eq .Params.suppress "true" ) ) -}}
{{- with .Params.href -}}
<a href="{{ if eq . "asCite" }}{{ $cite }}{{ else }}{{ . }}{{ end }}">
{{- end -}}
<cite
class="cite{{ with .Params.citeStyle }} cite--{{ . }}{{ end }}"
itemscope
itemprop="citation"
itemtype="https://schema.org/{{- $itemType -}}"
{{- if $titleLang -}}
lang="{{- $titleLang -}}"
title="{{- $titleTr -}}"
{{- end -}}>
{{- with $cite -}}
<meta itemprop="url" content="{{ . }}">
{{- end -}}
<span itemprop="name">
{{- if $titleLang -}}
<i lang="{{ $titleLang }}" title="{{ $titleTr }}">
{{- end -}}
{{- ( default $title .Params.shortTitle ) | markdownify | safeHTML -}}
{{- if $titleLang -}}
</i>
{{- end -}}
</span>{{- /**/ -}}
</cite>
{{- with .Params.href -}}
</a>
{{- end -}}
{{- else -}}
{{- erroridf "invalid-schema-type" "Invalid Schema.org type value %q for %q" $itemType $title -}}
{{- end -}}