refactor: citations
This commit is contained in:
parent
de341f4191
commit
810805f9ab
6 changed files with 76 additions and 54 deletions
|
@ -1,6 +1,9 @@
|
|||
{{- /*
|
||||
Renders a work citation with semantic markup, called using the `cite` shortcode.
|
||||
|
||||
@params sc Site context.
|
||||
@params pc Page context.
|
||||
|
||||
@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.
|
||||
|
@ -9,18 +12,27 @@
|
|||
@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.
|
||||
|
||||
For works cited that form part of a series (optional):
|
||||
@params itemtypeSeries The Schema.org `itemtype` value for the work series. Default 'CreativeWork'. Optional.
|
||||
@params titleSeries Title of the work series to display. Optional.
|
||||
@params citeSeries URI for work series. Optional.
|
||||
@params titleSeriesLang Language code of a foreign-language work series' title. Optional.
|
||||
@params titleSeriesTr English translation of a foreign-language work series' title. Optional.
|
||||
@params numberSeries The number or code of the quoted work within its series. Optional.
|
||||
*/ -}}
|
||||
|
||||
<!-- Optional parameter overrides (for nested citations) -->
|
||||
{{- $citeText := default .Params.cite ( .Scratch.Get "cite" ) }}
|
||||
|
||||
{{- $citeText := .Params.cite }}
|
||||
{{- $replacedCite := replaceRE `^([a-z]+?://)?(www)?` "" $citeText }}
|
||||
{{- $startOfCite := delimit ( findRE `^([a-z]+?://)?(www)?` $citeText 1 ) "" }}
|
||||
{{- $cite := replaceRE `^` $startOfCite ( trim ( $replacedCite | .Page.RenderString ) "\r\n" ) -}}
|
||||
{{- $cite := replaceRE `^` $startOfCite ( trim ( $replacedCite | .pc.Page.RenderString ) "\r\n" ) -}}
|
||||
|
||||
{{- $title := trim ( default .Params.title ( .Scratch.Get "title" ) | .Page.RenderString ) "\r\n" -}}
|
||||
{{- $titleLang := default .Params.titleLang ( .Scratch.Get "titleLang" ) -}}
|
||||
{{- $titleTr := default .Params.titleTr ( .Scratch.Get "titleTr" ) -}}
|
||||
{{- $itemtype := default .Params.itemtype ( .Scratch.Get "itemtype" ) -}}
|
||||
{{- $title := trim ( .Params.title | .pc.Page.RenderString ) "\r\n" -}}
|
||||
{{- $titleLang := .Params.titleLang -}}
|
||||
{{- $titleTr := .Params.titleTr -}}
|
||||
{{- $itemtype := .Params.itemtype -}}
|
||||
|
||||
{{- if ( strings.Contains $cite "#" ) -}}
|
||||
{{- erroridf "cite-with-fragment" "Cite parameter includes fragment identifier, which probably isn't what you want." -}}
|
||||
|
@ -35,8 +47,8 @@
|
|||
|
||||
<!-- TODO: check `.Params.href` is URI or 'asCite' -->
|
||||
|
||||
{{- if ( and $itemtype ( not ( in $.Site.Data.itemtypes $itemtype ) ) ) -}}
|
||||
{{- erroridf "invalid-itemtype" "Invalid Schema.org type value %q for %q" $itemtype $title -}}
|
||||
{{- if ( and $itemtype ( not ( in .sc.Site.Data.itemtypes $itemtype ) ) ) -}}
|
||||
{{- erroridf "invalid-itemtype" "Invalid Schema.org type value '%s' for %s (%q)\r\n%q" $itemtype .Params.title .sc.Page.File.Dir .Params -}}
|
||||
{{- end -}}
|
||||
|
||||
<!-- TODO: check `.Params.cite` is URI -->
|
||||
|
@ -47,9 +59,15 @@
|
|||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $hasCitedWork := ( isset .Params "title" ) }}
|
||||
{{- $hasCitedSeries := ( isset .Params "titleSeries" ) -}}
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
{{- $itemType := default "CreativeWork" $itemtype -}}
|
||||
{{- if ( or ( in $.Site.Data.itemtypes $itemType ) ( eq .Params.suppress "true" ) ) -}}
|
||||
{{- if ( or ( in .sc.Site.Data.itemtypes $itemType ) ( eq .Params.suppress "true" ) ) -}}
|
||||
{{- with .Params.href -}}
|
||||
<a href="{{- if eq . "asCite" -}}{{- $cite -}}{{- else -}}{{- . -}}{{- end -}}">
|
||||
{{- end -}}
|
||||
|
@ -89,6 +107,28 @@
|
|||
{{- with .Params.href -}}
|
||||
</a>
|
||||
{{- end -}}
|
||||
|
||||
{{- if $hasCitedSeries }}
|
||||
(<span itemprop="partOfSeries">
|
||||
{{- partial "cite.html" (
|
||||
dict
|
||||
"sc" $.sc
|
||||
"pc" $.pc
|
||||
"Params" (
|
||||
dict
|
||||
"cite" .Params.citeSeries
|
||||
"title" .Params.titleSeries
|
||||
"titleLang" .Params.titleSeriesLang
|
||||
"titleTr" .Params.titleSeriesTr
|
||||
"itemtype" .Params.itemtypeSeries
|
||||
"href" .Params.hrefSeries
|
||||
)
|
||||
) -}}
|
||||
</span>
|
||||
{{- with .Params.seasonNumber }}, S<span itemprop="partOfSeason">{{ . }}</span>{{- end -}}
|
||||
{{- with .Params.episodeNumber }}, E<span itemprop="episodeNumber">{{ . }}</span>{{- end -}}
|
||||
)
|
||||
{{- end -}}
|
||||
{{- else -}}
|
||||
{{- erroridf "invalid-schema-type" "Invalid Schema.org type value %q for %q" $itemType $title -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue