Introduce expandable image shortcode, improve portable links logic
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
{{- $destination := .Destination -}}
|
||||
{{- $url := urls.Parse .Destination -}}
|
||||
|
||||
{{- $isRemote := gt (len $url.Host) 0 -}}
|
||||
{{- $isFragment := strings.HasPrefix .Destination "#" -}}
|
||||
|
||||
{{- if and (not $isRemote) (not $isFragment) -}}
|
||||
{{- $path := strings.TrimPrefix "./" $url.Path -}}
|
||||
{{- $path = strings.TrimPrefix "/assets/" $path -}}
|
||||
|
||||
{{- with (.Page.Resources.Get $path) -}}
|
||||
{{- $destination = .RelPermalink -}}
|
||||
{{- else with (resources.Get $path) -}}
|
||||
{{- $destination = .RelPermalink -}}
|
||||
{{- else -}}
|
||||
{{- warnf "Image reference '%s' not found in '%s'" .Destination .Page.Permalink -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $url.RawQuery -}}
|
||||
{{- $destination = print $destination "?" . -}}
|
||||
{{- end -}}
|
||||
{{- with $url.Fragment -}}
|
||||
{{- $destination = print $destination "#" . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- return $destination -}}
|
||||
@@ -0,0 +1,29 @@
|
||||
{{- $destination := .Destination -}}
|
||||
{{- $url := urls.Parse .Destination -}}
|
||||
|
||||
{{- $isRemote := gt (len $url.Host) 0 -}}
|
||||
{{- $isFragment := strings.HasPrefix .Destination "#" -}}
|
||||
|
||||
{{- if and (not $isRemote) (not $isFragment) -}}
|
||||
{{- $path := strings.TrimPrefix "./" $url.Path -}}
|
||||
{{- $path = strings.TrimSuffix ".md" $path -}}
|
||||
{{- $path = strings.TrimSuffix "/_index" $path -}}
|
||||
|
||||
{{- with (.Page.GetPage $path) -}}
|
||||
{{- $destination = .RelPermalink -}}
|
||||
{{- else with (.Page.Resources.Get $path) -}}
|
||||
{{- $destination = .RelPermalink -}}
|
||||
{{- else with (resources.Get $path) -}}
|
||||
{{- $destination = .RelPermalink -}}
|
||||
{{- else -}}
|
||||
{{- warnf "Reference '%s' not found in '%s'" .Destination .Page.Permalink -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $url.RawQuery -}}
|
||||
{{- $destination = print $destination "?" . -}}
|
||||
{{- end -}}
|
||||
{{- with $url.Fragment -}}
|
||||
{{- $destination = print $destination "#" . -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- return $destination -}}
|
||||
@@ -10,8 +10,8 @@
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li>
|
||||
{{ $local := or (.Page) (strings.HasPrefix .URL "/") }}
|
||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if not $local }}target="_blank" rel="noopener"{{ end }}>
|
||||
{{ $isRemote := not (or (.Page) (strings.HasPrefix .URL "/")) }}
|
||||
<a href="{{ .URL }}" {{ with .Params.class }}class="{{ . }}"{{ end }} {{ if $isRemote }}target="_blank" rel="noopener"{{ end }}>
|
||||
{{- .Pre -}}
|
||||
{{ with .Page }}
|
||||
{{ partial "docs/title" .Page }}
|
||||
|
||||
Reference in New Issue
Block a user