PippoRJ / hugo-refresh

MIT License
117 stars 82 forks source link

Homepage Image From Config File (When Image Not located in theme) #15

Closed dunhampa closed 4 years ago

dunhampa commented 4 years ago

I am not having luck specifying a new image to display on homepage from the config file that does not live in the scheme.

I can get the desired result but only when I save my image in the theme directory for instance if myimage is saved here:

<site>/themes/hugo-refresh/assets/images/myimage.png

then the following config works:

  homepage:
    # option to specify the title in the homepage
    title: My Title
    # option to specify the subtitle in the homepage
    subtitle: My Subtitle
    # option to specify image in the homepage
    image: "/images/myimage.png"

But I tried to save my image outside of theme in static/images or static/assets/images and never could make image appear.

Should image be ok to live outside of theme?

Thanks again for theme and support.

PippoRJ commented 4 years ago

Hey @dunhampa , You are always welcome! the reason why the images are in the assets folder is simple. I use the Resize method to resize the images so that the usage of the bandwidth to transfer the images is more optimized. As far as I tried, I couldn't fetch the images from the static folder since it is usually used to place content that is not going to change. If you find a way to place the images there and resize them with that method, I will be happy to update the code..!

dunhampa commented 4 years ago

@PippoRJ i have been experimenting with this, and based on:

https://discourse.gohugo.io/t/resize-image-from-static-folder/14453

adding the line:

assetDir = "static"

to config seems to do the trick.

I can put together a reproducible example if you are interested. Any pitfalls you are aware of?

PippoRJ commented 4 years ago

Hi @dunhampa , This is actually great! I was not aware of this. I am not aware of any pitfalls but I will need to test the theme after this modification.

I will be offline for a couple of weeks for Christmas holidays but I will update the Theme as soon as I am online again. Thanks for this!

PippoRJ commented 4 years ago

I closed it by mistake.

I'll close it when I'm sure everything is tested.

PippoRJ commented 4 years ago

I have added the assetDir = "static" everything works perfectly. I have updated the docs and example site accordingly.