Add automatic cover image support#303
Conversation
There was a problem hiding this comment.
Hello and thank you for this!
The naming of the returning partial is dangerously ambiguous.
If any user has their own layouts/partials/featured.html in their project's root, to render say, a "featured" section, this will be used instead of this PR's partial and compromise the whole work added here.
As this is the first time we add a returning partial to the theme, I suggest we set a good example for future contributors.
I would put it in a layouts/partials/func directory and name it with a more action looking name like GetFeaturedImage (My reasons, debatables of course, are detailed here)
This way if the project's user has their own logic for finding featured image, they can simply overwrite layouts/partials/func/GetFeaturedImage.html
I would also add the partial should be heavily commented, keeping with the intent of this theme to teach. |
|
Good call @budparr. Here's a commenting example: |
Renamed the partial to func/GetFeaturedImage.html. Additionally added more documentation in the partial to explain how it worked, and what values were returned.
|
As requested, added documentation to the partial and changed the function name. Also, fixed a small bug - the previous version explicitly searched for a jpg with the name cover. The updated version searches for any image file with the name cover (so png or other formats can be used). |
regisphilibert
left a comment
There was a problem hiding this comment.
Thanks a lot for this @iUnknwn.
* Add support for auto-detection of featured images. * Rename Partial, Add Documentation Renamed the partial to func/GetFeaturedImage.html. Additionally added more documentation in the partial to explain how it worked, and what values were returned. Co-authored-by: Sean Zimmermann <sz2243@columbia.edu>
This adds support for automatic featured image detection, using the simple rule as the twitter and open graph internal template - if we can find a file named "cover".jpg it is automatically selected as the featured image if one was not selected in front matter.
This should make working with bundles easier.
(Fixes #302)