Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Featured Image naming flexibility in CMS #2777

Closed
ShoGinn opened this issue Jul 20, 2022 · 3 comments · Fixed by #2799
Closed

Featured Image naming flexibility in CMS #2777

ShoGinn opened this issue Jul 20, 2022 · 3 comments · Fixed by #2799

Comments

@ShoGinn
Copy link

ShoGinn commented Jul 20, 2022

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
Copy link
Author

ShoGinn commented Aug 2, 2022

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

@Agos95
Copy link
Contributor

Agos95 commented Aug 24, 2022

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*).

@ShoGinn
Copy link
Author

ShoGinn commented Aug 24, 2022

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants