🚸 Prevent scaling images smaller than article width

Fixes #394
pull/440/head
James Panther 2023-01-13 11:41:28 +11:00
parent 66209846d5
commit 138d2bf7bb
No known key found for this signature in database
GPG Key ID: D36F789E45745D17
3 changed files with 36 additions and 35 deletions

View File

@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed ### Changed
- Images smaller than the article width are no longer resized to fill the content area and will now simply align centre ([#394](https://github.com/jpanther/congo/pull/394))
- Upgrade to KaTeX v0.16.4 ([#414](https://github.com/jpanther/congo/pull/414)) - Upgrade to KaTeX v0.16.4 ([#414](https://github.com/jpanther/congo/pull/414))
- Upgrade to Mermaid v9.3.0 ([#419](https://github.com/jpanther/congo/pull/419)) - Upgrade to Mermaid v9.3.0 ([#419](https://github.com/jpanther/congo/pull/419))
- Upgrade to Chart.js v4.1.2 ([#420](https://github.com/jpanther/congo/pull/420), [#434](https://github.com/jpanther/congo/pull/434)) - Upgrade to Chart.js v4.1.2 ([#420](https://github.com/jpanther/congo/pull/420), [#434](https://github.com/jpanther/congo/pull/434))

View File

@ -3,8 +3,8 @@
{{ $caption := .Title }} {{ $caption := .Title }}
{{ if findRE "^https?" $url.Scheme }} {{ if findRE "^https?" $url.Scheme }}
<figure> <figure>
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ else }} {{ else }}
{{ $resource := "" }} {{ $resource := "" }}
@ -15,30 +15,26 @@
{{ end }} {{ end }}
{{ with $resource }} {{ with $resource }}
<figure> <figure>
{{ if eq .MediaType.SubType "svg" }}
<img <img
class="my-0 rounded-md" class="mx-auto my-0 rounded-md"
{{ if or (lt .Width 660) (eq .MediaType.SubType "svg") }}
src="{{ .RelPermalink }}" src="{{ .RelPermalink }}"
alt="{{ $altText }}"
/>
{{ else }} {{ else }}
<img
class="my-0 rounded-md"
srcset=" srcset="
{{ (.Resize "330x").RelPermalink }} 330w, {{ (.Resize "330x").RelPermalink }} 330w,
{{ (.Resize "660x").RelPermalink }} 660w, {{ (.Resize "660x").RelPermalink }} 660w,
{{ (.Resize "1024x").RelPermalink }} 1024w, {{ (.Resize "1024x").RelPermalink }} 1024w,
{{ (.Resize "1320x").RelPermalink }} 2x" {{ (.Resize "1320x").RelPermalink }} 2x"
src="{{ (.Resize "660x").RelPermalink }}" src="{{ (.Resize "660x").RelPermalink }}"
{{ end }}
alt="{{ $altText }}" alt="{{ $altText }}"
/> />
{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ else }} {{ else }}
<figure> <figure>
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" /> <img class="mx-auto my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }} {{ with $caption }}<figcaption class="text-center">{{ . | markdownify }}</figcaption>{{ end }}
</figure> </figure>
{{ end }} {{ end }}
{{ end }} {{ end }}

View File

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