-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automatic cover image support #303
Add automatic cover image support #303
Conversation
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.
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). |
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.
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 <[email protected]>
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)