mirror of https://github.com/jpanther/congo.git
🚸 Prevent image processing on external URLs
parent
dd3606d33d
commit
60a62e2b4b
|
@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Markdown images and `figure` shortcode fail to load resource when providing an external URL source
|
||||||
|
- HTML `figcaption` tags are output for Markdown images even when a caption is not provided
|
||||||
|
|
||||||
## [2.0.2] - 2022-02-05
|
## [2.0.2] - 2022-02-05
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
@ -99,14 +99,14 @@ You can see some additional Chart.js examples on the [charts samples]({{< ref "c
|
||||||
|
|
||||||
Congo includes a `figure` shortcode for adding images to content. The shortcode replaces the base Hugo functionality in order to provide additional performance benefits.
|
Congo includes a `figure` shortcode for adding images to content. The shortcode replaces the base Hugo functionality in order to provide additional performance benefits.
|
||||||
|
|
||||||
Images included using `figure` will be optimised using Hugo Pipes and scaled in order to provide images appropriate to different device resolutions.
|
When a provided image is a page resource, it will be optimised using Hugo Pipes and scaled in order to provide images appropriate to different device resolutions. If a URL to an external image is provided, it will be included as-is without any image processing by Hugo.
|
||||||
|
|
||||||
The `figure` shortcode accepts six parameters:
|
The `figure` shortcode accepts six parameters:
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
<!-- prettier-ignore-start -->
|
||||||
|Parameter|Description|
|
|Parameter|Description|
|
||||||
|---|---|
|
|---|---|
|
||||||
|`src`|**Required.** The filename of the image. This image must be a [page resource](https://gohugo.io/content-management/page-resources/) bundled with the page.|
|
|`src`|**Required.** The filename or URL of the image. When providing a filename, this image must be a [page resource](https://gohugo.io/content-management/page-resources/) bundled with the page.|
|
||||||
|`alt`|[Alternative text description](https://moz.com/learn/seo/alt-text) for the image.|
|
|`alt`|[Alternative text description](https://moz.com/learn/seo/alt-text) for the image.|
|
||||||
|`caption`|Markdown for the image caption, which will be displayed below the image.|
|
|`caption`|Markdown for the image caption, which will be displayed below the image.|
|
||||||
|`class`|Additional CSS classes to apply to the image.|
|
|`class`|Additional CSS classes to apply to the image.|
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
|
{{ $url := urls.Parse .Destination }}
|
||||||
{{ $altText := .Text }}
|
{{ $altText := .Text }}
|
||||||
{{ $caption := .Title }}
|
{{ $caption := .Title }}
|
||||||
{{ with $.Page.Resources.GetMatch (.Destination) }}
|
{{ if findRE "^https?" $url.Scheme }}
|
||||||
|
<figure>
|
||||||
|
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
|
||||||
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
||||||
|
</figure>
|
||||||
|
{{ else }}
|
||||||
|
{{ with $.Page.Resources.GetMatch ($url.String) }}
|
||||||
<figure>
|
<figure>
|
||||||
<img
|
<img
|
||||||
class="my-0 rounded-md"
|
class="my-0 rounded-md"
|
||||||
|
@ -12,8 +19,9 @@
|
||||||
src="{{ (.Resize "660x").RelPermalink }}"
|
src="{{ (.Resize "660x").RelPermalink }}"
|
||||||
alt="{{ $altText }}"
|
alt="{{ $altText }}"
|
||||||
/>
|
/>
|
||||||
<figcaption>{{ $caption | markdownify }}</figcaption>
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
||||||
</figure>
|
</figure>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ errorf `[CONGO] Markdown image error in "%s": Resource "%s" not found. Check the path is correct or remove the image from the content.` .Page.Path .Destination }}
|
{{ errorf `[CONGO] Markdown image error in "%s": Resource "%s" not found. Check the path is correct or remove the image from the content.` .Page.Path $url.String }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -1,11 +1,18 @@
|
||||||
{{ if .Get "default" }}
|
{{ if .Get "default" }}
|
||||||
{{ template "_internal/shortcodes/figure.html" . }}
|
{{ template "_internal/shortcodes/figure.html" . }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
|
{{ $url := urls.Parse (.Get "src") }}
|
||||||
{{ $altText := .Get "alt" }}
|
{{ $altText := .Get "alt" }}
|
||||||
{{ $caption := .Get "caption" }}
|
{{ $caption := .Get "caption" }}
|
||||||
{{ $href := .Get "href" }}
|
{{ $href := .Get "href" }}
|
||||||
{{ $class := .Get "class" }}
|
{{ $class := .Get "class" }}
|
||||||
{{ with $.Page.Resources.GetMatch (.Get "src") }}
|
{{ if findRE "^https?" $url.Scheme }}
|
||||||
|
<figure>
|
||||||
|
<img class="my-0 rounded-md" src="{{ $url.String }}" alt="{{ $altText }}" />
|
||||||
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
||||||
|
</figure>
|
||||||
|
{{ else }}
|
||||||
|
{{ with $.Page.Resources.GetMatch ($url.String) }}
|
||||||
<figure {{ with $class }}class="{{ . }}"{{ end }}>
|
<figure {{ with $class }}class="{{ . }}"{{ end }}>
|
||||||
{{ with $href }}<a href="{{ . }}">{{ end }}
|
{{ with $href }}<a href="{{ . }}">{{ end }}
|
||||||
<img
|
<img
|
||||||
|
@ -22,6 +29,7 @@
|
||||||
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
{{ with $caption }}<figcaption>{{ . | markdownify }}</figcaption>{{ end }}
|
||||||
</figure>
|
</figure>
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ errorf `[CONGO] Shortcode "figure" error in "%s": Resource "%s" not found. Check the path is correct or remove the shortcode.` .Page.Path (.Get "src") }}
|
{{ errorf `[CONGO] Shortcode "figure" error in "%s": Resource "%s" not found. Check the path is correct or remove the shortcode.` .Page.Path ($url.String) }}
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
Loading…
Reference in New Issue