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

Featured images shared between posts #866

Closed
newres opened this issue Jan 5, 2019 · 2 comments
Closed

Featured images shared between posts #866

newres opened this issue Jan 5, 2019 · 2 comments

Comments

@newres
Copy link

newres commented Jan 5, 2019

Is there a way in hugo-academic to use the same featured image for multiple posts without actually duplicating the image? In previous versions, I could just give the relative link to the file in static/img for this. Unless I missed something, in the new resource system I feel like this image has to be always located/found in the directory of the post under the "featured.jpg" or "featured.png" name.

Something like an optional:

[image]
src="sharedfeaturedimage.png"

that would take the featured imagine from the static/img directory, would be really helpful.

@gcushen
Copy link
Collaborator

gcushen commented Jan 5, 2019

Hugo's new resource system (which we use for featured images) does not currently work with images in the static dir. See https://gohugo.io/content-management/image-processing/#readout :

The image is a Page Resource, and the processing methods listed below does not work on images inside your /static folder.

I believe it's on their roadmap to remove the limitation.

If you are using an OS which supports symlinks, such as Mac or Linux, then you may be able to create symlink shortcuts to your image rather than duplicate it.

Alternatively, the header image can be used (which works with images in the static media library) or an image can simply be place at the top of the content using Markdown/shortcodes.

Hope that helps.

@gcushen gcushen closed this as completed Jan 5, 2019
@newres
Copy link
Author

newres commented Jan 12, 2019

I figured out a way to work around the /static folder limitation for sharing resources between multiple posts, so I thought I share it. I created a headless-bundle in the /media directory, which allows anything put under that directory to be used as resources with Hugo's new resources system.

Next I changed the partials that pick up the resource from the featured image, to pick the resource specified with a src parameter of the image, if it exists, e.g.:

[image]
src="sharedfeaturedimage.png"

If there is no such resource specified the featured image works as in the default case. The headless-bundle under /media can also be used to hold any image, not just the featured ones, that would be available for image processing without potentially duplicating them for articles.

I think this is a pretty solid solution to enable shared resources, especially featured images, between multiple posts. The biggest change required is changing all the partials to make use of the /media directory. I could create a pull request for the changes, as I feel like the solution would work for others in a similar situation.

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

No branches or pull requests

2 participants