hugo-blox-builder icon indicating copy to clipboard operation
hugo-blox-builder copied to clipboard

Featured Image naming flexibility in CMS

Open ShoGinn opened this issue 2 years ago • 1 comments

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 }}

ShoGinn avatar Jul 20 '22 15:07 ShoGinn

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

ShoGinn avatar Aug 02 '22 20:08 ShoGinn

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:

  1. Search for a file *featured* in the post directory
    • this is for backward compatibility
  2. 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
  3. Search for a file .Params.image.filename in the assets/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

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 avatar Aug 24 '22 08:08 Agos95

@Agos95 Awesome, I had made an attempt, but as you pointed out, its in a ton of locations ;) I appreciate you taking this on

ShoGinn avatar Aug 24 '22 12:08 ShoGinn