Use images from assets for both image processing and static images

Hi all.

I have a small project like this:

.
├── asset
│   ├── images
│   │   ├── image1.jpg
│   │   ├── image2.jpg
│   │   └── ...
│   ├── js
│   │   └── ...
│   └── scss
│       └── ...
├── content
│   ├── doc
│   │   ├── page1.md
│   │   └── page2.md
│   └── ...
└── layout
    └── doc
        ├── list.html
        └── single.html

I want to include the related image for each document in the document itself using plain markdown code (I know this wouldn’t work as explained in the documentation: https://gohugo.io/hugo-pipes/introduction/#asset-publishing).

# content/doc/pageX.md
---
title: Page number X
---
[!image X](/images/imageX.jpg)

and in the list page for all the docs use a thumbnail:

# layouts/doc/list.html
{{ $range .Pages }}
    {{ $basename := .File.Basename }}
    {{ $asset := printf "%s.jpg" $basename }}
    {{ $thumbnail := $asset.Resize "250x" }}
    <img src="{{ $thumbnail.Permalink }}"> 
{{ end }}

The thumbnails are shown in the listing but the images aren’t shown in the pages, as expected

I’d like to know what are the best practices to deal with problems like these:

  • Duplicate images in assets/images and static/images.
  • Create symbolic links between static/images and assets/images?
  • Use shortcodes in .md files to force the {{ .Permalink }} rule (it would prevent from use plain markdown)
  • Add assets to the static directory list lookup with staticDir (it would copy a lot of non-processed files as well)

Do I miss a better approach?

Thanks.

Are you even using markdown render hooks?

@sephore that’s fits perfectly with what I need.

Thanks!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.