♻️ Refactor figure shortcode to reduce repetition

pull/440/head
James Panther 2023-01-14 11:24:41 +11:00
parent 68e37ab7a5
commit 3bfc6ae439
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
2 changed files with 34 additions and 39 deletions

View File

@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Error when attempting to resize SVG assets in page bundles ([#427](https://github.com/jpanther/congo/pull/427)) - Error when attempting to resize SVG assets in page bundles ([#427](https://github.com/jpanther/congo/pull/427))
- Appearance switcher missing `aria-label` ([#438](https://github.com/jpanther/congo/pull/438)) - Appearance switcher missing `aria-label` ([#438](https://github.com/jpanther/congo/pull/438))
- Article links missing `alt` text and `aria-label` ([#439](https://github.com/jpanther/congo/pull/439)) - Article links missing `alt` text and `aria-label` ([#439](https://github.com/jpanther/congo/pull/439))
- Figure shortcode would not apply `class` or `href` attribtues in some cases
## [2.4.2] - 2022-11-22 ## [2.4.2] - 2022-11-22

View File

@ -6,43 +6,37 @@
{{ $caption := .Get "caption" }} {{ $caption := .Get "caption" }}
{{ $href := .Get "href" }} {{ $href := .Get "href" }}
{{ $class := .Get "class" }} {{ $class := .Get "class" }}
{{ if findRE "^https?" $url.Scheme }} <figure{{ with $class }} class="{{ . }}"{{ end }}>
<figure> {{ with $href }}<a href="{{ . }}">{{ end }}
<img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} class="mx-auto my-0 rounded-md"
</figure> alt="{{ $altText }}"
{{ else }} {{ if findRE "^https?" $url.Scheme }}
{{ $resource := "" }} src="{{ $url.String }}"
{{ if $.Page.Resources.GetMatch ($url.String) }} {{ else }}
{{ $resource = $.Page.Resources.GetMatch ($url.String) }} {{ $resource := "" }}
{{ else if resources.GetMatch ($url.String) }} {{ if $.Page.Resources.GetMatch ($url.String) }}
{{ $resource = resources.Get ($url.String) }} {{ $resource = $.Page.Resources.GetMatch ($url.String) }}
{{ end }} {{ else if resources.GetMatch ($url.String) }}
{{ with $resource }} {{ $resource = resources.Get ($url.String) }}
<figure {{ with $class }}class="{{ . }}"{{ end }}> {{ end }}
{{ with $href }}<a href="{{ . }}">{{ end }} {{ with $resource }}
<img {{ if or (lt .Width 660) (eq .MediaType.SubType "svg") }}
class="mx-auto my-0 rounded-md" src="{{ .RelPermalink }}"
{{ if or (lt .Width 660) (eq .MediaType.SubType "svg") }} {{ else }}
src="{{ .RelPermalink }}" srcset="
{{ else }} {{ (.Resize "330x").RelPermalink }} 330w,
srcset=" {{ (.Resize "660x").RelPermalink }} 660w,
{{ (.Resize "330x").RelPermalink }} 330w, {{ (.Resize "1024x").RelPermalink }} 1024w,
{{ (.Resize "660x").RelPermalink }} 660w, {{ (.Resize "1320x").RelPermalink }} 2x"
{{ (.Resize "1024x").RelPermalink }} 1024w, src="{{ (.Resize "660x").RelPermalink }}"
{{ (.Resize "1320x").RelPermalink }} 2x" {{ end }}
src="{{ (.Resize "660x").RelPermalink }}" {{ else }}
{{ end }} src="{{ $url.String }}"
alt="{{ $altText }}" {{ end }}
/> {{ end }}
{{ if $href }}</a>{{ end }} />
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }} {{ with $href }}</a>{{ end }}
</figure> {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
{{ else }} </figure>
<figure>
<img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
{{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure>
{{ end }}
{{ end }}
{{ end }} {{ end }}