refactor: internal and external links
This commit is contained in:
parent
5aec4874b6
commit
f1c9fa5622
14 changed files with 388 additions and 125 deletions
|
@ -78,58 +78,10 @@
|
|||
{{ define "main-body" }}
|
||||
<section class="site-content__body">
|
||||
{{- if ( or .Params.internal_links .Params.external_links ) -}}
|
||||
<section class="article__links">
|
||||
{{- with .Params.internal_links -}}
|
||||
<h3>Internal Links</h3>
|
||||
<ul>
|
||||
{{- range . -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
{{- if .src -}}
|
||||
{{- $src := $.Page.Resources.GetMatch .src -}}
|
||||
{{- if ( not $src ) -}}
|
||||
{{- errorf "No Page Resource found for src '%q' (%q).\n\n\tAvailable Page Resources are:\n\t\t%v" ( $.Get .src ) $.Page.File.Path $.Page.Resources -}}
|
||||
{{- end -}}
|
||||
<li><a href="{{ $src.RelPermalink }}">{{ .title | $.RenderString | safeHTML }}</a></li>
|
||||
{{- else -}}
|
||||
<li><a href="{{ .link }}">{{ .title | $.RenderString | safeHTML }}</a></li>
|
||||
{{- end -}}
|
||||
{{ else }}
|
||||
<li><a href="{{ . }}">Link</a></li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- partial "single/main-body/links.html" ( dict "pc" . "sc" $ ) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with .Params.external_links -}}
|
||||
<h3>External Links</h3>
|
||||
<ul>
|
||||
{{- range . -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
<li>
|
||||
<a
|
||||
href="{{ .link }}"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>{{ .title | safeHTML }}</a
|
||||
>
|
||||
</li>
|
||||
{{ else }}
|
||||
<li>
|
||||
<a
|
||||
href="{{ . }}"
|
||||
rel="noopener noreferrer"
|
||||
target="_blank"
|
||||
>Link</a
|
||||
>
|
||||
</li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- end -}}
|
||||
</section>
|
||||
{{- end -}}
|
||||
|
||||
{{ .Content }}
|
||||
{{- partial "single/main-body/content.html" ( dict "pc" . "sc" $ ) -}}
|
||||
</section>
|
||||
{{ end }}
|
||||
|
||||
|
|
|
@ -76,10 +76,7 @@
|
|||
{{ end }}
|
||||
|
||||
{{ define "main-body" }}
|
||||
<section
|
||||
class="site-content__body"
|
||||
itemprop="articleBody"
|
||||
>
|
||||
<section class="site-content__body">
|
||||
{{ with .Summary }}
|
||||
<section
|
||||
class="article-body__summary"
|
||||
|
@ -91,87 +88,22 @@
|
|||
{{ end }}
|
||||
|
||||
{{- if ( or .Params.internal_links .Params.external_links ) -}}
|
||||
<section class="article__links">
|
||||
{{- with .Params.internal_links -}}
|
||||
<h3>Internal Links</h3>
|
||||
<ul>
|
||||
{{- range . -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
<li><a href="{{ .link }}">{{ .title | safeHTML }}</a></li>
|
||||
{{ else }}
|
||||
<li><a href="{{ . }}">Link</a></li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- partial "single/main-body/links.html" ( dict "pc" . "sc" $ ) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with .Params.external_links -}}
|
||||
<h3>External Links</h3>
|
||||
<ul>
|
||||
{{- range . -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
<li><a href="{{ .link }}">{{ .title | safeHTML }}</a></li>
|
||||
{{ else }}
|
||||
<li><a href="{{ . }}">Link</a></li>
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
||||
{{- end -}}
|
||||
</section>
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<section
|
||||
class="e-content article-body__content"
|
||||
itemprop="articleBody"
|
||||
>
|
||||
{{ .Content }}
|
||||
</section>
|
||||
{{- partial "single/main-body/content.html" ( dict "pc" . "sc" $ ) -}}
|
||||
|
||||
{{ if fileExists ( path.Join $.Page.File.Dir "appendices.md" ) }}
|
||||
<section class="article-body__appendices">
|
||||
<h2
|
||||
class="subheading subheading--appendices"
|
||||
id="appendices"
|
||||
>
|
||||
Appendices
|
||||
</h2>
|
||||
{{ $file := path.Join $.Page.File.Dir "appendices.md" | readFile }}
|
||||
{{ $file | .RenderString }}
|
||||
</section>
|
||||
{{- partial "single/main-body/appendices.html" ( dict "pc" . "sc" $ ) -}}
|
||||
{{ end }}
|
||||
|
||||
{{ if fileExists ( path.Join $.Page.File.Dir "corrigendum.md" ) }}
|
||||
<section
|
||||
class="article-body__corrigendum"
|
||||
itemprop="correction"
|
||||
itemscope
|
||||
itemtype="https://schema.org/CorrectionComment"
|
||||
>
|
||||
<h2
|
||||
class="subheading subheading--corrigendum"
|
||||
id="corrigendum"
|
||||
>
|
||||
Corrigendum
|
||||
</h2>
|
||||
{{ $file := path.Join $.Page.File.Dir "corrigendum.md" | readFile }}
|
||||
{{ $file | .RenderString }}
|
||||
</section>
|
||||
{{- partial "single/main-body/appendices.html" ( dict "pc" . "sc" $ ) -}}
|
||||
{{ end }}
|
||||
</section>
|
||||
|
||||
{{ with .Page.Resources.Get "comments.md" }}
|
||||
<section class="site-content__comments">
|
||||
<h2
|
||||
class="subheading subheading--comments"
|
||||
id="comments"
|
||||
>
|
||||
Comments
|
||||
</h2>
|
||||
<ul class="comment__thread">
|
||||
{{ .RenderShortcodes }}
|
||||
</ul>
|
||||
</section>
|
||||
{{- partial "single/main-body/comments.html" ( dict "pc" . "sc" $ ) -}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
|
|
32
layouts/partials/single/main-body/appendices.html
Normal file
32
layouts/partials/single/main-body/appendices.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{{- /*
|
||||
Displays appendices for an item
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<section class="article-body__appendices">
|
||||
<h2
|
||||
class="subheading subheading--appendices"
|
||||
id="appendices"
|
||||
>
|
||||
Appendices
|
||||
</h2>
|
||||
{{ $file := path.Join $.sc.Page.File.Dir "appendices.md" | readFile }}
|
||||
{{ $file | .pc.RenderString }}
|
||||
</section>
|
33
layouts/partials/single/main-body/comments.html
Normal file
33
layouts/partials/single/main-body/comments.html
Normal file
|
@ -0,0 +1,33 @@
|
|||
{{- /*
|
||||
Displays comments for an item
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<section class="site-content__comments">
|
||||
<h2
|
||||
class="subheading subheading--comments"
|
||||
id="comments"
|
||||
>
|
||||
Comments
|
||||
</h2>
|
||||
<ul class="comment__thread">
|
||||
{{ .pc.RenderShortcodes }}
|
||||
</ul>
|
||||
</section>
|
28
layouts/partials/single/main-body/content.html
Normal file
28
layouts/partials/single/main-body/content.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{{- /*
|
||||
Displays main content for an item
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<section
|
||||
class="e-content article-body__content"
|
||||
itemprop="articleBody"
|
||||
>
|
||||
{{ .pc.Content }}
|
||||
</section>
|
37
layouts/partials/single/main-body/corrigendum.html
Normal file
37
layouts/partials/single/main-body/corrigendum.html
Normal file
|
@ -0,0 +1,37 @@
|
|||
{{- /*
|
||||
Displays corrigenda for an item
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<section
|
||||
class="article-body__corrigendum"
|
||||
itemprop="correction"
|
||||
itemscope
|
||||
itemtype="https://schema.org/CorrectionComment"
|
||||
>
|
||||
<h2
|
||||
class="subheading subheading--corrigendum"
|
||||
id="corrigendum"
|
||||
>
|
||||
Corrigendum
|
||||
</h2>
|
||||
{{ $file := path.Join $.sc.Page.File.Dir "corrigendum.md" | readFile }}
|
||||
{{ $file | .pc.RenderString }}
|
||||
</section>
|
36
layouts/partials/single/main-body/links.html
Normal file
36
layouts/partials/single/main-body/links.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
{{- /*
|
||||
Displays internal and external links for an item
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $params := . -}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset $params "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset $params "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" $params.sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<section class="article__links">
|
||||
{{- if $params.pc.Params.internal_links -}}
|
||||
{{- partial "single/main-body/links/internal-links.html" $params -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $params.pc.Params.external_links -}}
|
||||
{{- partial "single/main-body/links/external-links.html" $params -}}
|
||||
{{- end -}}
|
||||
</section>
|
40
layouts/partials/single/main-body/links/external-links.html
Normal file
40
layouts/partials/single/main-body/links/external-links.html
Normal file
|
@ -0,0 +1,40 @@
|
|||
{{- /*
|
||||
Displays a list of external links
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $params := . -}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset $params "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset $params "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" $params.sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<h3>External Links</h3>
|
||||
<ul>
|
||||
{{- range $params.pc.Params.external_links -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
{{ if ( isset . "name" ) }}
|
||||
{{- errorf "Name is set (%q)" $params.sc.Page.File.Dir -}}
|
||||
{{ end }}
|
||||
{{- partial "single/main-body/links/link/title-link.html" ( $params | merge ( dict "title" .title "link" .link ) ) }}
|
||||
{{ else }}
|
||||
{{- partial "single/main-body/links/link/basic-link.html" $params }}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
46
layouts/partials/single/main-body/links/internal-links.html
Normal file
46
layouts/partials/single/main-body/links/internal-links.html
Normal file
|
@ -0,0 +1,46 @@
|
|||
{{- /*
|
||||
Displays a list of internal links
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Variable assignment -->
|
||||
|
||||
{{- $params := . -}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset $params "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset $params "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" $params.sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<h3>Internal Links</h3>
|
||||
<ul>
|
||||
{{- range $params.pc.Params.internal_links -}}
|
||||
{{ if eq ( printf "%T" . ) "map[string]interface {}" }}
|
||||
{{ if ( isset . "name" ) }}
|
||||
{{- errorf "Name is set (%q)" $params.sc.Page.File.Dir -}}
|
||||
{{ end }}
|
||||
{{- if ( isset . "src" ) -}}
|
||||
{{- partial "single/main-body/links/link/page-resource-link.html" ( $params | merge ( dict "title" .title "src" .src ) ) }}
|
||||
{{- else if ( isset . "ref" ) -}}
|
||||
{{- partial "single/main-body/links/link/page-link.html" ( $params | merge ( dict "title" .title "ref" .ref ) ) }}
|
||||
{{- else -}}
|
||||
{{- partial "single/main-body/links/link/title-link.html" ( $params | merge ( dict "title" .title "link" .link ) ) }}
|
||||
{{- end -}}
|
||||
{{ else }}
|
||||
{{- partial "single/main-body/links/link/basic-link.html" $params }}
|
||||
{{ end }}
|
||||
{{- end -}}
|
||||
</ul>
|
23
layouts/partials/single/main-body/links/link/basic-link.html
Normal file
23
layouts/partials/single/main-body/links/link/basic-link.html
Normal file
|
@ -0,0 +1,23 @@
|
|||
{{- /*
|
||||
Displays an internal link without a title
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<li><a href="{{ . }}">Link</a></li>
|
35
layouts/partials/single/main-body/links/link/page-link.html
Normal file
35
layouts/partials/single/main-body/links/link/page-link.html
Normal file
|
@ -0,0 +1,35 @@
|
|||
{{- /*
|
||||
Displays an internal link from another Page on the site.
|
||||
|
||||
@params sc Site context
|
||||
@params ref Page ref
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Variable assignment -->
|
||||
{{- $page := $.sc.GetPage .ref -}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not $page ) -}}
|
||||
{{- errorf "No Page found for ref '%q' (%q)." .ref $.sc.Page.File.Path -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<li>
|
||||
<a href="{{ $page.RelPermalink }}"
|
||||
>{{- default $page.Title $page.Params.markup_title | $page.Page.RenderString -}}
|
||||
</a>
|
||||
</li>
|
|
@ -0,0 +1,37 @@
|
|||
{{- /*
|
||||
Displays an internal link from a page resource
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
@params src Page resource source
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Variable assignment -->
|
||||
{{- $src := $.sc.Page.Resources.GetMatch .src -}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not $src ) -}}
|
||||
{{- errorf "No Page Resource found for src '%q' (%q).\n\n\tAvailable Page Resources are:\n\t\t%v" .src $.sc.Page.File.Path $.sc.Page.Resources -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<li>
|
||||
<a href="{{ $src.RelPermalink }}"
|
||||
>{{ .title | $.sc.RenderString | safeHTML }}
|
||||
(<code>.{{- delimit ( last 1 ( split $src.RelPermalink "." ) ) "" -}}</code>)</a
|
||||
>
|
||||
</li>
|
32
layouts/partials/single/main-body/links/link/title-link.html
Normal file
32
layouts/partials/single/main-body/links/link/title-link.html
Normal file
|
@ -0,0 +1,32 @@
|
|||
{{- /*
|
||||
Displays an internal link with a title
|
||||
|
||||
@params pc Page context
|
||||
@params sc Site context
|
||||
@params link Link URL
|
||||
*/
|
||||
-}}
|
||||
|
||||
|
||||
<!-- Validation -->
|
||||
|
||||
{{- if ( not ( isset . "sc" ) ) -}}
|
||||
{{- errorf "No site context received" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( not ( isset . "pc" ) ) -}}
|
||||
{{- errorf "No page context received (%q)" .sc.Page.File.Dir -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if ( or ( not ( isset . "title" ) ) ( eq .title "" ) ) -}}
|
||||
{{- warnf "No title found (%q)" $.sc.Page.File.Path -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not ( hasPrefix .link "http" ) -}}
|
||||
{{- warnf "Link '%q' is not a URL, did you mean to use 'src'? (%q)" .link $.sc.Page.File.Path -}}
|
||||
{{- end -}}
|
||||
|
||||
|
||||
<!-- Rendering -->
|
||||
|
||||
<li><a href="{{ .link }}">{{ .title | $.sc.RenderString | safeHTML }}</a></li>
|
Loading…
Add table
Add a link
Reference in a new issue