From d332b54c94c8446236ccbbdce752c3bf4137d72b Mon Sep 17 00:00:00 2001 From: Aakash Nand <14219201+aakashnand@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:02:40 +0900 Subject: [PATCH 1/3] Fetch feature image from url --- layouts/_default/single.html | 5 +++++ layouts/partials/article-link/simple.html | 2 ++ layouts/partials/hero/background.html | 3 +++ layouts/partials/hero/big.html | 13 +++++++++++-- layouts/partials/hero/thumbAndBackground.html | 2 ++ layouts/partials/home/background.html | 4 ++-- 6 files changed, 25 insertions(+), 4 deletions(-) diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 026954c7..dd915162 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,5 +1,10 @@ {{ define "main" }} {{ .Scratch.Set "scope" "single" }} +
{{ if .Params.showHero | default (.Site.Params.article.showHero | default false) }} diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index 8c994825..b0c423b0 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -40,6 +40,8 @@ {{- $images := $.Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} + {{- $url:= .Params.featureimage -}} + {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} {{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} {{- with $featured -}} diff --git a/layouts/partials/hero/background.html b/layouts/partials/hero/background.html index ec3a9db9..0ce96d59 100644 --- a/layouts/partials/hero/background.html +++ b/layouts/partials/hero/background.html @@ -4,6 +4,9 @@ {{- $featured := $images.GetMatch "*background*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- $url:= .Params.featureimage -}} +{{if or $.Site.Params.list.showHero $.Site.Params.term.showHero $.Site.Params.taxonomy.showHero}} {{ $url = default $.Site.Params.homepage.homepageImage $.Site.Params.defaultBackgroundImage }} {{end}} +{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} {{- if not $featured }}{{ with .Site.Params.defaultBackgroundImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} {{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or diff --git a/layouts/partials/hero/big.html b/layouts/partials/hero/big.html index cbdce5d5..89bb1759 100644 --- a/layouts/partials/hero/big.html +++ b/layouts/partials/hero/big.html @@ -3,16 +3,25 @@ {{- $images := .Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- $url:= .Params.featureimage -}} +{{- $caption:= .Params.featureimagecaption -}} +{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} {{- $alt := .Page.Title -}} {{- with .Page.Params.alt }}{{ $alt = . }}{{ end -}} {{- with $featured -}} {{ if $disableImageOptimization }} {{ with . }} - {{ $alt }} +
+ {{ $alt }} +
{{ $caption | markdownify }}
+
{{ end }} {{ else }} {{ with .Resize "1200x" }} - {{ $alt }} +
+ {{ $alt }} +
{{ $caption | markdownify }}
+
{{ end }} {{ end }} {{- end -}} \ No newline at end of file diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index 1e4114ca..7704345d 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -7,6 +7,8 @@ {{- if not $background }}{{ $background = $images.GetMatch "*feature*" }}{{ end -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{- $url:= .Params.featureimage -}} +{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} {{- if not $featured }}{{ $featured = $images.GetMatch "*background*" }}{{ end -}} {{- if not $featured }}{{ with .Site.Params.defaultBackgroundImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} diff --git a/layouts/partials/home/background.html b/layouts/partials/home/background.html index c5e9ea81..66af2cb8 100644 --- a/layouts/partials/home/background.html +++ b/layouts/partials/home/background.html @@ -6,8 +6,8 @@
{{ $homepageImage := "" }} - {{ with .Site.Params.defaultBackgroundImage }}{{ $homepageImage = resources.Get . }}{{ end }} - {{ with .Site.Params.homepage.homepageImage }}{{ $homepageImage = resources.Get . }}{{ end }} + {{ with .Site.Params.defaultBackgroundImage }} {{ $homepageImage = resources.Get . }} {{if not $homepageImage}} {{ $homepageImage = resources.GetRemote . }} {{ end }} {{ end }} + {{ with .Site.Params.homepage.homepageImage }} {{ $homepageImage = resources.Get . }} {{if not $homepageImage}} {{ $homepageImage = resources.GetRemote . }} {{ end }} {{ end }} {{ if not (eq $homepageImage "") }}
Date: Mon, 5 Feb 2024 23:32:48 +0900 Subject: [PATCH 2/3] Add documentation for external image usage --- exampleSite/content/docs/configuration/index.md | 2 +- exampleSite/content/docs/front-matter/index.md | 2 ++ layouts/_default/single.html | 5 ----- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/exampleSite/content/docs/configuration/index.md b/exampleSite/content/docs/configuration/index.md index 1594ef56..26116149 100644 --- a/exampleSite/content/docs/configuration/index.md +++ b/exampleSite/content/docs/configuration/index.md @@ -200,7 +200,7 @@ Many of the article defaults here can be overridden on a per article basis by sp | Name | Default | Description | | ------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `homepage.layout` | `"profile"` | The layout of the homepage. Valid values are `page`, `profile`, `hero`, `card`, `background`, or `custom`. When set to `custom`, you must provide your own layout by creating a `/layouts/partials/home/custom.html` file. Refer to the [Homepage Layout]({{< ref "homepage-layout" >}}) section for more details. | -| `homepage.homepageImage` | _Not set_ | Image to be used in `hero` and `card` layouts. Refer to the [Homepage Layout]({{< ref "homepage-layout" >}}) section for more details. | +| `homepage.homepageImage` | _Not set_ | Image to be used in `hero` and `card` layouts. Can be set as local image from asset directory or external image url. Refer to the [Homepage Layout]({{< ref "homepage-layout" >}}) section for more details. | | `homepage.showRecent` | `false` | Whether or not to display the recent articles list on the homepage. | | `homepage.showRecentItems` | 5 | How many articles to display if showRecent is true. If variable is set to 0 or if it isn't defined the system will default to 5 articles. | | `homepage.showMoreLink` | `false` | Whether or not to display a show more link at the end of your posts that takes the user to a predefined place. | diff --git a/exampleSite/content/docs/front-matter/index.md b/exampleSite/content/docs/front-matter/index.md index 1826212c..22f0cf98 100644 --- a/exampleSite/content/docs/front-matter/index.md +++ b/exampleSite/content/docs/front-matter/index.md @@ -28,6 +28,8 @@ Front matter parameter default values are inherited from the theme's [base confi | `showAuthor` | `article.showAuthor` | Whether or not the author box for the default author is displayed in the article footer. | | `authors` | _Not set_ | Array of values for authors, if set it overrides `showAuthor` settings for page or site. Used on the multiple authors feature, check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature. | | `showAuthorsBadges` | `article.showAuthorsBadges` | Whether the `authors` taxonomies are are displayed in the article or list header. This requires the setup of `multiple authors` and the `authors` taxonomy. Check [this page]({{< ref "multi-author" >}}) for more details on how to configure that feature. | +| `featureimage` | _Not set_ | External URL for feature image +| `featureimagecaption` | _Not set_ | Caption for feature image. Only displayed in heroStyle `big` | `showHero` | `article.showHero` | Whether the thumbnail image will be shown as a hero image within the article page. | | `heroStyle` | `article.heroStyle` | Style to display the hero image, valid options are: `basic`, `big`, `background`, `thumbAndBackground`. | | `showBreadcrumbs` | `article.showBreadcrumbs` or `list.showBreadcrumbs` | Whether the breadcrumbs are displayed in the article or list header. | diff --git a/layouts/_default/single.html b/layouts/_default/single.html index dd915162..026954c7 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -1,10 +1,5 @@ {{ define "main" }} {{ .Scratch.Set "scope" "single" }} -
{{ if .Params.showHero | default (.Site.Params.article.showHero | default false) }} From 19520b44816895382476fb9eb347dc9ecf190bbd Mon Sep 17 00:00:00 2001 From: Aakash Nand <14219201+aakashnand@users.noreply.github.com> Date: Sat, 10 Feb 2024 23:04:54 +0900 Subject: [PATCH 3/3] Ensure featureimage is present before calling resources.GetRemote Also added ability to set author image as external url and updated relevant documentation in configuration --- .../content/docs/configuration/index.md | 2 +- layouts/partials/article-link/simple.html | 2 ++ layouts/partials/author-extra.html | 23 +++++++++++------- layouts/partials/author.html | 23 +++++++++++------- layouts/partials/hero/background.html | 2 ++ layouts/partials/hero/basic.html | 4 ++++ layouts/partials/hero/big.html | 13 +++++++--- layouts/partials/hero/thumbAndBackground.html | 2 ++ layouts/partials/home/background.html | 24 ++++++++++++------- layouts/partials/home/hero.html | 23 +++++++++++------- layouts/partials/home/profile.html | 14 ++++++++++- 11 files changed, 95 insertions(+), 37 deletions(-) diff --git a/exampleSite/content/docs/configuration/index.md b/exampleSite/content/docs/configuration/index.md index 26116149..55ffc084 100644 --- a/exampleSite/content/docs/configuration/index.md +++ b/exampleSite/content/docs/configuration/index.md @@ -137,7 +137,7 @@ The default file can be used as a template to create additional languages, or re | Name | Default | Description | | ----------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `author.name` | _Not set_ | The author's name. This will be displayed in article footers, and on the homepage when the profile layout is used. | -| `author.image` | _Not set_ | Path to the image file of the author. The image should be a 1:1 aspect ratio and placed in the site's `assets/` folder. | +| `author.image` | _Not set_ | Path to the image file of the author. The image should be a 1:1 aspect ratio. The image can be placed in the site's `assets/` folder or can be external url. | | `author.headline` | _Not set_ | A Markdown string containing the author's headline. It will be displayed on the profile homepage under the author's name. | | `author.bio` | _Not set_ | A Markdown string containing the author's bio. It will be displayed in article footers. | | `author.links` | _Not set_ | The links to display alongside the author's details. The config file contains example links which can simply be uncommented to enable. The order that the links are displayed is determined by the order they appear in the array. Custom links can be added by providing corresponding SVG icon assets in `assets/icons/`. | diff --git a/layouts/partials/article-link/simple.html b/layouts/partials/article-link/simple.html index b0c423b0..bb1768ea 100644 --- a/layouts/partials/article-link/simple.html +++ b/layouts/partials/article-link/simple.html @@ -40,8 +40,10 @@ {{- $images := $.Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} + {{ if .Params.featureimage }} {{- $url:= .Params.featureimage -}} {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} + {{ end }} {{- if not $featured }}{{ with .Site.Params.defaultFeaturedImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ if .Params.hideFeatureImage }}{{ $featured = false }}{{ end }} {{- with $featured -}} diff --git a/layouts/partials/author-extra.html b/layouts/partials/author-extra.html index 4e81d07e..a15a63c1 100644 --- a/layouts/partials/author-extra.html +++ b/layouts/partials/author-extra.html @@ -1,14 +1,21 @@ {{ $disableImageOptimization := .Site.Params.disableImageOptimization | default false }}
{{ with .data.image }} - {{ $authorImage := resources.Get . }} - {{ if $authorImage }} - {{ if not $disableImageOptimization }} - {{ $authorImage = $authorImage.Fill "192x192" }} - {{ end }} - - {{ end }} + {{ $authorImage := resources.Get . }} + {{ if $authorImage }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "192x192" }} + {{ end }} + + {{ else }} + {{ $authorImage := resources.GetRmeote . }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "192x192" }} + {{ end }} + + {{ end }} {{ end }}
{{ $link := .link}} diff --git a/layouts/partials/author.html b/layouts/partials/author.html index 466d279e..50bc2cc3 100644 --- a/layouts/partials/author.html +++ b/layouts/partials/author.html @@ -1,14 +1,21 @@ {{ $disableImageOptimization := .Site.Params.disableImageOptimization | default false }}
{{ with .Site.Author.image }} - {{ $authorImage := resources.Get . }} - {{ if $authorImage }} - {{ if not $disableImageOptimization }} - {{ $authorImage = $authorImage.Fill "192x192" }} - {{ end }} - {{ $.Site.Author.name | default - {{ end }} + {{ $authorImage := resources.Get . }} + {{ if $authorImage }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "192x192" }} + {{ end }} + {{ $.Site.Author.name | default + {{ else }} + {{ $authorImage := resources.GetRemote . }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "192x192" }} + {{ end }} + {{ $.Site.Author.name | default + {{ end }} {{ end }}
{{ with .Site.Author.name | markdownify | emojify }} diff --git a/layouts/partials/hero/background.html b/layouts/partials/hero/background.html index 0ce96d59..f72015fe 100644 --- a/layouts/partials/hero/background.html +++ b/layouts/partials/hero/background.html @@ -4,9 +4,11 @@ {{- $featured := $images.GetMatch "*background*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "*feature*" }}{{ end -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{ if .Params.featureimage }} {{- $url:= .Params.featureimage -}} {{if or $.Site.Params.list.showHero $.Site.Params.term.showHero $.Site.Params.taxonomy.showHero}} {{ $url = default $.Site.Params.homepage.homepageImage $.Site.Params.defaultBackgroundImage }} {{end}} {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} +{{ end }} {{- if not $featured }}{{ with .Site.Params.defaultBackgroundImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} {{ $shouldBlur := $.Params.layoutBackgroundBlur | default (or diff --git a/layouts/partials/hero/basic.html b/layouts/partials/hero/basic.html index 11377928..00cc1b3c 100644 --- a/layouts/partials/hero/basic.html +++ b/layouts/partials/hero/basic.html @@ -3,6 +3,10 @@ {{- $images := .Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{ if .Params.featureimage }} +{{- $url:= .Params.featureimage -}} +{{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} +{{ end }} {{- with $featured -}} {{ if $disableImageOptimization }} {{ with . }} diff --git a/layouts/partials/hero/big.html b/layouts/partials/hero/big.html index 89bb1759..294c37e5 100644 --- a/layouts/partials/hero/big.html +++ b/layouts/partials/hero/big.html @@ -3,9 +3,12 @@ {{- $images := .Resources.ByType "image" -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{ $caption := "" }} +{{ if .Params.featureimage }} {{- $url:= .Params.featureimage -}} -{{- $caption:= .Params.featureimagecaption -}} +{{- $caption = .Params.featureimagecaption -}} {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} +{{ end }} {{- $alt := .Page.Title -}} {{- with .Page.Params.alt }}{{ $alt = . }}{{ end -}} {{- with $featured -}} @@ -13,14 +16,18 @@ {{ with . }}
{{ $alt }} -
{{ $caption | markdownify }}
+ {{ if $caption }} +
{{ $caption | markdownify }}
+ {{end}}
{{ end }} {{ else }} {{ with .Resize "1200x" }}
{{ $alt }} -
{{ $caption | markdownify }}
+ {{ if $caption }} +
{{ $caption | markdownify }}
+ {{end}}
{{ end }} {{ end }} diff --git a/layouts/partials/hero/thumbAndBackground.html b/layouts/partials/hero/thumbAndBackground.html index 7704345d..5d9c6071 100644 --- a/layouts/partials/hero/thumbAndBackground.html +++ b/layouts/partials/hero/thumbAndBackground.html @@ -7,8 +7,10 @@ {{- if not $background }}{{ $background = $images.GetMatch "*feature*" }}{{ end -}} {{- $featured := $images.GetMatch "*feature*" -}} {{- if not $featured }}{{ $featured = $images.GetMatch "{*cover*,*thumbnail*}" }}{{ end -}} +{{ if .Params.featureimage }} {{- $url:= .Params.featureimage -}} {{- if not $featured }}{{ $featured = resources.GetRemote $url }}{{ end -}} +{{ end }} {{- if not $featured }}{{ $featured = $images.GetMatch "*background*" }}{{ end -}} {{- if not $featured }}{{ with .Site.Params.defaultBackgroundImage }}{{ $featured = resources.Get . }}{{ end }}{{ end -}} {{ $isParentList := eq (.Scratch.Get "scope") "list" }} diff --git a/layouts/partials/home/background.html b/layouts/partials/home/background.html index 66af2cb8..3ee48e58 100644 --- a/layouts/partials/home/background.html +++ b/layouts/partials/home/background.html @@ -20,14 +20,22 @@
{{ with .Site.Author.image }} - {{ $authorImage := resources.Get . }} - {{ if $authorImage }} - {{ if not $disableImageOptimization }} - {{ $authorImage = $authorImage.Fill "288x288" }} - {{ end }} - {{ $.Site.Author.name | default - {{ end }} + {{ $authorImage := resources.Get . }} + {{ if $authorImage }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "288x288" }} + {{ end }} + {{ $.Site.Author.name | default + {{else}} + {{ $authorImage := resources.GetRemote . }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "288x288" }} + {{ end }} + {{ $.Site.Author.name | default + {{ end }} + {{ end }}

{{ .Site.Author.name | default .Site.Title }} diff --git a/layouts/partials/home/hero.html b/layouts/partials/home/hero.html index 8cf60984..91cb89fd 100644 --- a/layouts/partials/home/hero.html +++ b/layouts/partials/home/hero.html @@ -17,14 +17,21 @@

{{ with .Site.Author.image }} - {{ $authorImage := resources.Get . }} - {{ if $authorImage }} - {{ if not $disableImageOptimization }} - {{ $authorImage = $authorImage.Fill "288x288" }} - {{ end }} - {{ $.Site.Author.name | default - {{ end }} + {{ $authorImage := resources.Get . }} + {{ if $authorImage }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "288x288" }} + {{ end }} + {{ $.Site.Author.name | default + {{ else }} + {{ $authorImage := resources.GetRemote . }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "288x288" }} + {{ end }} + {{ $.Site.Author.name | default + {{ end }} {{ end }}

{{ .Site.Author.name | default .Site.Title }} diff --git a/layouts/partials/home/profile.html b/layouts/partials/home/profile.html index 7ba08a7e..2a8a64bc 100644 --- a/layouts/partials/home/profile.html +++ b/layouts/partials/home/profile.html @@ -9,7 +9,19 @@ {{ $authorImage := resources.Get . }} {{ if $authorImage }} {{ if not $disableImageOptimization }} - {{ $authorImage = $authorImage.Fill "288x288" }} + {{ $authorImage = $authorImage.Fill "288x288" }} + {{ end }} + {{ $.Site.Author.name | default + {{ else }} + {{ $authorImage := resources.GetRemote . }} + {{ if not $disableImageOptimization }} + {{ $authorImage = $authorImage.Fill "288x288" }} {{ end }}