Search code examples
htmlrhugoblogdown

Image scoping issue when using Wowchemy Hugo Academic and Blogdown workflow


I was following ApresHill's amazingly helpful blog post for creating my website. I have a question regarding the image scoping, I would appreciate it if someone can shed some light. Wowchemy tutorial says the images can be placed under /assets/media/ folder starting with Wowchemy v5.1. Prior to this release, they were to be found under static folder.

My question has to do with the difference in scoping when I'm referring to an image in the yaml front matter or within the post itself. In short, YAML headers scope for images in /assets/media/ while post bodies scope for images in static/media/:

Let the image paths be: /assets/media/IMG_IN_ASSETS_MEDIA_FOLDER.jpg /static/media/IMG_IN_STATIC_MEDIA_FOLDER.jpg

---
# This works in YAML
  background:
    image: IMG_IN_ASSETS_MEDIA_FOLDER.jpg
    image_darken: 0.65
    image_parallax: true
    image_position: center
    image_size: cover
    text_color_light: true
  spacing:
    padding: ["20px", "0", "20px", "0"]
---
---
# This doesn't work in YAML
  background:
    image: IMG_IN_STATIC_MEDIA_FOLDER.jpg
    image_darken: 0.65
    image_parallax: true
    image_position: center
    image_size: cover
    text_color_light: true
  spacing:
    padding: ["20px", "0", "20px", "0"]
---

When I try to insert an image to the post body only static folder is scoped

# adding images under `static` folder works
![](/media/IMG_IN_STATIC_MEDIA_FOLDER.jpg) # works 

# images under `/assets/media/` aren't found. I tried a few things here:
![](/media/IMG_IN_ASSETS_MEDIA_FOLDER.jpg)
![](/assets/media/IMG_IN_ASSETS_MEDIA_FOLDER.jpg)
![](../assets/media/IMG_IN_ASSETS_MEDIA_FOLDER.jpg)
# It works when I use the shortcodes though

{{< figure src="IMG_IN_ASSETS_MEDIA_FOLDER.jpg" >}}

Why do the post front matter and body behave differently when it comes to image scoping? What am I missing here?


Solution

  • As I heard in the R Studio Community, this may be due to differences in where Hugo or Blogdown looks for images. It also explains why the shortcode worked for inserting an image from the assets folder.