-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load featured image from media library (#2799)
Adds support for loading featured image from media library via `image.filename` param as an alternative to placing a `featured.*` image in the page folder. Supports setting a default feature image for all pages via Hugo Cascade in Hugo Config. Supports featured image reuse without duplicating the image within each page folder.
- Loading branch information
Showing
9 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
modules/wowchemy/layouts/partials/functions/get_featured_image.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{{/* Function to retrieve the featured image */}} | ||
{{/* Inputs: page context */}} | ||
{{/* Output: image resource, or nil if not found */}} | ||
|
||
{{/* | ||
Featured image is searched in this order: | ||
1. Search for a file `*featured*` in the post directory | ||
2. Search for a file `.Params.image.filename` in the post directory | ||
3. Search for a file `.Params.image.filename` in the `assets/media/` directory | ||
*/}} | ||
|
||
{{/* Search for an image "*featured*" in post folder */}} | ||
{{ $resource := (.Resources.ByType "image").GetMatch "*featured*" }} | ||
{{ if eq $resource nil }} | ||
{{/* Otherwise fall back the image file specified in front matter */}} | ||
{{ $filename := .Params.image.filename }} | ||
{{/* Search in post folder */}} | ||
{{ $resource = (.Resources.ByType "image").GetMatch $filename }} | ||
{{/* Otherwise in `assets/media/` folder */}} | ||
{{ if eq $resource nil }} {{ $resource = resources.GetMatch (path.Join "media" $filename) }} {{ end }} | ||
{{ end }} | ||
|
||
{{ return $resource }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1fe36f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is huge @Agos95! Thanks a ton for doing this!
I have a friend who keeps forgetting to change the name of the file!