refactor: internal and external links
This commit is contained in:
parent
5aec4874b6
commit
f1c9fa5622
14 changed files with 388 additions and 125 deletions
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