-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglossary.html
109 lines (103 loc) · 5.28 KB
/
glossary.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{{/*
This shortcode does A LOT of work. In prior incarnations, it was
three or four shortcodes. However, as I started normalizing and
overloading, it became clear that I could consolidate the basic logic.
Yes this does a lot of things, but in doing it this way, I have
consistent glossary referencing mechanisms.
Parameters:
@param key - required for lookup of glossary entry
Optional Parameters (in likely importance order):
@param abbr - include an abbreviation; if "t" use the glossary's abbr,
otherwise use the given value.
@param plural - use the pluralization (unless you provide the "title"
parameter)
@param title - use the given "title" for title
@param noIcon - when "t" do not render the linking icon to glossary
@param noTitle - do not render the title (you'll probably want the
abbr="t")
@param link - specify the given link (see implementation below)
@param tag - specify the tag to use for the title node; defaults to
either cite or span (based on logic below)
@param dfn - add a sidenote with a description; if "t" use the
predefined; otherwise use the given.
@param itemprop - sometimes, instead of a "mention" you'll want to use
this as the tag
*/}}
{{- $key := .Get "key" | upper }}
{{- $entry := index (where $.Site.Data.glossary "key" "eq" $key) 0 }}
{{- if isset $entry "key" }}
{{- $citedTitle := default $entry.title ( default $entry.mention_as ) }}
{{- $title := "" }}
{{- if .Get "title" }}
{{- $title = .Get "title" }}
{{- else if .Get "mention_as" }}
{{- $title = .Get "mention_as" }}
{{- else if .Get "plural" }}
{{- $title = $entry.plural_title }}
{{- else }}
{{- $title = $entry.title }}
{{- end }}
{{- if eq 0 (len $title ) }}{{- errorf "Missing title for key %s in file %s" (.Get "key") (.Page.Permalink) }}{{- end }}
{{- $scratchKey := printf "glossary-%s" $entry.key }}
{{- $titleTag := "span" }}
{{- if .Get "tag" }}{{- $titleTag = .Get "tag" }}{{- else }}{{- if and (or ($entry.cite) ($entry.offer)) (eq $title $citedTitle ) }}{{ $titleTag = "cite" }}{{- end }}{{- end }}
{{- if .Get "downcase" }}{{ $title = lower $title }}{{- end }}
{{- $abbrHTML := "" }}
{{- $abbrTitle := default $entry.title (.Get "title") }}
{{- with (or (.Get "abbr") (or (.Get "noTitle") $entry.no_title)) }}
{{- $abbr := "" }}
{{- if eq . "t" }}
{{- if $.Get "plural" }}
{{- with $entry.plural_abbr }}{{- $abbr = $entry.plural_abbr }}{{- else }}{{- errorf "Missing plural_abbr for %s in file %s" $key $.Page.Permalink }}{{- end }}
{{- with $entry.plural_title }}{{- $abbrTitle = $entry.plural_title }}{{- else }}{{- errorf "Missing plural_title for %s in file %s" $key $.Page.Permalink }}{{- end }}
{{- else }}
{{- $abbr = $entry.abbr }}
{{- end }}
{{- else }}
{{- $abbr = . }}
{{- end }}
{{- if $abbr }}{{- $abbrHTML = printf "<abbr title=\"%s\">%s</abbr>" $abbrTitle $abbr }}{{- else }}{{- warnf "Expected abbr for key %s in post %s" $key ($.Page.Permalink) }}{{- end }}
{{- end }}{{/* end with .Get "abbr" */}}
{{- if .Page.Scratch.Get $scratchKey }}
{{- if eq (len $abbrHTML) 0 }}{{ printf "<%s>%s</%s>" $titleTag $title $titleTag | safeHTML }}{{- else }}{{ $abbrHTML | safeHTML }}{{- end }}
{{- else }}
{{- .Page.Scratch.Set $scratchKey "t" }}
{{- $itemtype := default $entry.itemtype ("Thing") }}
{{- if eq $titleTag "cite" }}{{ $itemtype = "CreativeWork" }}{{- end }}
{{- $innerTitleHtml := $title }}
{{- $reflink := "" }}
{{- if (or (.Get "noIcon") $entry.no_icon) }}{{- else }}
{{- $reflink = printf " <small><a class=\"ref\" rel=\"tag opener\" aria-label=\"Other site-wide references of “%s”\" title=\"Other site-wide references of “%s”\" href=\"/site-map/glossary/#abbr-dfn-%s\">📖</a></small>" $title $title $entry.key | safeHTML }}
{{- end }}
{{- $dfnText := "" }}
{{- with .Get "dfn" }}
{{- $dfnInnerText := "" }}{{ if eq . "t" }}{{ with $entry.description }}{{- $dfnInnerText := . }}{{- end }}{{- else }}{{- $dfnInnerText = . }}{{- end }}
{{- if ne 0 (len $dfnInnerText) }}{{- $dfnText = printf "<span class=\"sidenote-number\"><small class=\"side\" role=\"note\">(i.e., <span>%s</span>)</small></span>" . | safeHTML }}{{- end }}{{- end }}
{{- with $entry.offer }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" . $title }}
{{- else }}
{{- with $entry.same_as }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" . $title }}
{{- else }}
{{- with $entry.url }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" . $title }}
{{- else }}
{{- with .Get "link" }}
{{- if and (eq . "same_as") (isset $entry "same_as") }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" $entry.same_as $title }}
{{- else if and (eq . "itemid") (isset $entry "itemid") }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" $entry.itemid $title }}
{{- else if eq "http" (substr . 0 4) }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" . $title }}
{{- else if isset $entry "itemid" }}
{{- $innerTitleHtml = printf "<a href=\"%s\">%s</a>" $entry.itemid $title }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if (or (.Get "noTitle") $entry.no_title) }}{{ $abbrHTML | safeHTML }}{{ $dfnText }}{{ $reflink }}{{- else }}
{{- printf "<%s>%s</%s>%s" $titleTag $innerTitleHtml $titleTag $dfnText | safeHTML }}
{{- if eq 0 (len $abbrHTML) }}{{ $reflink }}{{- else }} ({{ $abbrHTML | safeHTML }}{{ $reflink}}){{- end }}
{{- end }}{{- end }}
{{- else }}{{ errorf "Missing %s in file %s" (.Get "key") (.Page.Permalink) }}{{- end }}