mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-31 00:47:13 +00:00
link: adjust to Hugo's build-in code #858
- resolve render hook destination with leading ./ - adjust variable naming - remove special case for section resources borrowed from https://www.veriphor.com/articles/link-and-image-render-hooks/
This commit is contained in:
parent
833ccac2d2
commit
db38203826
1 changed files with 5 additions and 8 deletions
|
@ -4,8 +4,7 @@
|
|||
{{- $page = .context }}
|
||||
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'link' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }}
|
||||
{{- end }}
|
||||
{{- $url := .url }}
|
||||
{{- if strings.HasPrefix $url "HAHAHUGOSHORTCODE" }}
|
||||
{{- if strings.HasPrefix .url "HAHAHUGOSHORTCODE" }}
|
||||
{{- warnf "%q: WARNING you must call the ref / relref shortcode with '%% %%' instead of '< >' to work correctly for the anchor target attribute" $page.File.Filename }}
|
||||
{{- end }}
|
||||
{{- $attributes := dict }}
|
||||
|
@ -14,9 +13,8 @@
|
|||
{{- $attributes = $attributes | merge (dict "title" ($title | transform.HTMLEscape)) }}
|
||||
{{- $content := .content }}
|
||||
{{- $target := .target | default "" }}
|
||||
{{- $u := urls.Parse $url }}
|
||||
{{- $u := urls.Parse .url -}}
|
||||
{{- $href := $u.String }}
|
||||
{{- $path := $u.Path }}
|
||||
{{- if $u.IsAbs }}
|
||||
{{- $attributes = merge $attributes (dict "rel" "external") }}
|
||||
{{- $target = "_blank" }}
|
||||
|
@ -26,12 +24,12 @@
|
|||
{{- $attributes = $attributes | merge (dict "target" $target) }}
|
||||
{{- else }}
|
||||
{{- $linkPage := "" }}
|
||||
{{- $path := strings.TrimPrefix "./" $u.Path }}
|
||||
{{- if $path }}
|
||||
{{- with or
|
||||
($page.Page.GetPage $path)
|
||||
($page.Page.GetPage (strings.TrimRight "/" $path))
|
||||
($page.Page.Resources.Get $path)
|
||||
(and (ne $page.Page.BundleType "leaf") ($page.Page.CurrentSection.Resources.Get $path))
|
||||
(resources.Get $path)
|
||||
}}
|
||||
{{- $linkPage = . }}
|
||||
|
@ -50,7 +48,6 @@
|
|||
(.GetPage $suffix)
|
||||
(.GetPage (strings.TrimRight "/" $suffix))
|
||||
(.Resources.Get $suffix)
|
||||
(and (ne .BundleType "leaf") (.CurrentSection.Resources.Get $suffix))
|
||||
(resources.Get $suffix)
|
||||
}}
|
||||
{{- $linkPage = . }}
|
||||
|
@ -81,9 +78,9 @@
|
|||
{{- end }}
|
||||
{{- else }}
|
||||
{{- if eq $page.Site.Params.link.errorlevel "warning" }}
|
||||
{{- warnf "%q: link '%s' is not a page but linked anyways" $page.File.Filename $url }}
|
||||
{{- warnf "%q: link '%s' is not a page or a resource but linked anyways" $page.File.Filename .url }}
|
||||
{{- else if eq $page.Site.Params.link.errorlevel "error" }}
|
||||
{{- errorf "%q: link '%s' is not a page" $page.File.Filename $url }}
|
||||
{{- errorf "%q: link '%s' is not a page or a resource" $page.File.Filename .url }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
|
Loading…
Add table
Reference in a new issue