2024-07-23 08:08:36 +00:00
|
|
|
{{- /*
|
2024-04-02 19:36:21 +00:00
|
|
|
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.
|
2024-07-23 08:08:36 +00:00
|
|
|
*/ -}}
|
2024-04-02 19:36:21 +00:00
|
|
|
|
|
|
|
<!-- 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" ) -}}
|
|
|
|
|
2024-07-23 08:08:36 +00:00
|
|
|
{{- if ( strings.Contains $cite "#" ) -}}
|
|
|
|
{{- erroridf "cite-with-fragment" "Cite parameter includes fragment identifier, which probably isn't what you want." -}}
|
|
|
|
{{- $cite = delimit ( split $cite "#" ) "" -}}
|
|
|
|
{{- end -}}
|
2024-04-02 19:36:21 +00:00
|
|
|
|
2024-07-23 08:08:36 +00:00
|
|
|
<!-- Validation -->
|
2024-04-02 19:36:21 +00:00
|
|
|
|
|
|
|
{{- 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 -}}
|
|
|
|
|
2024-07-23 08:08:36 +00:00
|
|
|
<!-- TODO: check `.Params.cite` is URI -->
|
|
|
|
|
2024-04-02 19:36:21 +00:00
|
|
|
{{- 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 -}}
|
2024-07-23 08:08:36 +00:00
|
|
|
<i
|
|
|
|
lang="{{ $titleLang }}"
|
|
|
|
title="
|
|
|
|
{{- if $.Params.shortTitle -}}
|
|
|
|
{{- printf "%s [%s]" $title $titleTr | plainify -}}
|
|
|
|
{{- else -}}
|
|
|
|
{{- $titleTr | plainify -}}
|
|
|
|
{{- end -}}
|
|
|
|
"
|
|
|
|
>
|
2024-04-02 19:36:21 +00:00
|
|
|
{{- 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 -}}
|