hugo-blox-builder
hugo-blox-builder copied to clipboard
Featured Image naming flexibility in CMS
Feature Request
Is your feature request related to a problem? Please describe. When using the netlify CMS and adding a featured image to a post, having to depend on the filename is not optimal. Specifically if someone uses an ipad or mobile device and it names the file a GUID
Describe the solution you'd like
Modify the layouts/partials/page_header.html
to use the .Params.image.filename
included in the CMS submission
Describe alternatives you've considered No alternatives
Additional context Here is the code I recommend:
{{ if and .Params.image.filename (not $featured) }}
{{ $featured = (.Resources.ByType "image").GetMatch (print "*" (strings.TrimSuffix (path.Ext .Params.image.filename) .Params.image.filename) "*") }}
{{ end }}
So I closed the pull request due to the fact that the fix works on just the article page, but everywhere else it is an issue.
Hopefully someone else finds this issue
I am working on a possible solution. I need some more time time to fix some other things (such as previews on different views). For now, my changes do these steps to find the featured images:
- Search for a file
*featured*
in the post directory- this is for backward compatibility
- Search for a file
.Params.image.filename
in the post directory- this is for people who prefers having all the files related to a specific post inside the post directory
- Search for a file
.Params.image.filename
in theassets/media/
directory- this allows to use an image in
assets/media
as a featured one. In this way, multiple posts can have the same featured figure without the need to upload the same image multiple times in multiple folders - in addition, using Hudo cascade, it is possible to specify a default featured image in
config.yaml
, which can be used as fallback in the case nothing is specified in the post front matter
- this allows to use an image in
Before sending a pull request I need to modify also the code for the different views to have the same logic (now they search only for a file named *featured*
).
@Agos95 Awesome, I had made an attempt, but as you pointed out, its in a ton of locations ;) I appreciate you taking this on