Skip to content

Commit

Permalink
remoteImage shortcode has been rewritten to work with page frontmatte…
Browse files Browse the repository at this point in the history
…r/params
  • Loading branch information
wiseweb-works committed Jul 11, 2024
1 parent ccdc527 commit bb9ae81
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
1 change: 0 additions & 1 deletion config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ params:
comments: false
hidemeta: false
searchHidden: false
weblate.svg: "https://hosted.weblate.org/widgets/monal/-/multi-auto.svg"
defaultTheme: auto
DateFormat: "02.01.2006"
disableThemeToggle: false
Expand Down
9 changes: 4 additions & 5 deletions content/support.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
---
title: "Support"
date: 2022-03-12T10:01:54+01:00
resources:
- src: "https://hosted.weblate.org/widgets/monal/-/multi-auto.svg"
name: "weblate.svg"
title: "Detailed translation status"

params:
weblate.svg:
img_url: "https://hosted.weblate.org/widgets/monal/-/multi-auto.svg"
img_title: "Detailed translation status"
tags: []
author: "Monal"
---
Expand Down
22 changes: 10 additions & 12 deletions layouts/shortcodes/remoteImage.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{{ $paramName := .Get 0 }} <!-- Get the shortcode argument -->
{{ $paramValue := index .Site.Params $paramName }} <!-- Get the parameter value from the config file -->
{{ $paramValue := index .Page.Params (.Get 0) }} <!-- Retrieve the parameter value -->

{{ if $paramValue }} <!-- If the parameter value exists -->
{{ $image := resources.GetRemote $paramValue }} <!-- Fetch the image from the $Params link -->
{{ $alt := .Get "alt" }} <!-- Get the alt text from the shortcode parameters -->
{{ $title := cond (not (.Get "title")) $alt (.Get "title") }} <!-- Set the title to alt text if title is not provided -->
<img src="{{ $image.RelPermalink | absURL | safeURL }}" title="{{ $title | safeHTML }}"> <!-- Display the image -->
{{ else }} <!-- If the parameter value does not exist -->
{{ $image := resources.GetRemote (.Get 0) }} <!-- Fetch the image from the remote source via link -->
{{ $alt := .Get "alt" }} <!-- Get the alt text from the shortcode parameters -->
{{ $title := cond (not (.Get "title")) $alt (.Get "title") }} <!-- Set the title to alt text if title is not provided -->
<img src="{{ $image.RelPermalink | absURL | safeURL }}" title="{{ $title | safeHTML }}"> <!-- Display the image -->
{{ if $paramValue }}
{{ $image := resources.GetRemote $paramValue.img_url }} <!-- Get the remote image using the URL from the parameter value -->
{{ $imgTitle := cond (not $paramValue.img_title) (.Get "title") $paramValue.img_title }} <!-- Get the image title from the parameter value -->
<img src="{{ $image.RelPermalink | absURL | safeURL }}" title="{{ $imgTitle | safeHTML }}"> <!-- Serve the image with the title -->
{{ else }}
{{ $image := resources.GetRemote (.Get 0) }} <!-- Get the remote image using the first argument passed to the shortcode -->
{{ $alt := .Get "alt" }} <!-- Get the alt text from the shortcode arguments -->
{{ $imgTitle := cond (not ($alt)) (.Get "title") $alt }} <!-- Set the title to the argument title if it exists, otherwise use the alt text -->
<img src="{{ $image.RelPermalink | absURL | safeURL }}" title="{{ $imgTitle | safeHTML }}"> <!-- Output the image with the appropriate title -->
{{ end }}

0 comments on commit bb9ae81

Please sign in to comment.