🚸 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
- 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 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))

View File

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

View File

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