Skip to content
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

Merged
merged 3 commits into from
Jun 23, 2020

Conversation

iUnknwn
Copy link
Contributor

@iUnknwn iUnknwn commented Jun 19, 2020

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)

Copy link
Member

@regisphilibert regisphilibert left a 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

@budparr
Copy link
Member

budparr commented Jun 22, 2020

As this is the first time we add a returning partial to the theme

I would also add the partial should be heavily commented, keeping with the intent of this theme to teach.

@regisphilibert
Copy link
Member

regisphilibert commented Jun 22, 2020

Renamed the partial to func/GetFeaturedImage.html.

Additionally added more documentation in the partial to explain how it
worked, and what values were returned.
@iUnknwn
Copy link
Contributor Author

iUnknwn commented Jun 23, 2020

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

Copy link
Member

@regisphilibert regisphilibert left a 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.

@regisphilibert regisphilibert merged commit 5001b28 into theNewDynamic:master Jun 23, 2020
Remicck pushed a commit to Remicck/gohugo-theme-ananke that referenced this pull request Mar 7, 2022
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set featured image automatically if cover image is present
3 participants