Add featured image in "projects" section without creating folders

I am wondering is there any chance that I can keep current directories and add individual featured images in my “projects” section.

This is the link of my repo and my blog.

I have checked several example websites, all of them create a single folder for each project.

My directory structure is as below (some of them):

├───content
│   ├───home
│   ├───post
│   ├───project ─── individual .md
├───static
│   ├───files
│   └───img

Thanks!

Are you going to do any image processing, or just render the image files without modification?

Currently I only want to show the featured image like this blog. But if you know how to proecess the image without bundling resources in single folders such as the way in your link, please let me know. Thanks in advance.

assets/
└── images/
    ├── a.jpg
    └── b.jpg
content/
├── posts/
│   ├── post-1.md
│   └── post-2.md
└── _index.md

content/posts/post-1.md

+++
title = 'Post 1'
date = 2023-01-04T09:04:35-08:00
draft = false
featured = 'images/a.jpg'
+++

layouts/_default/single.html

{{ with .Params.featured }}
  {{ with resources.Get . }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ else }}
    {{ errorf "Unable to locate %s in the assets directory" . }}
  {{ end }}
{{ end }}
1 Like

Thanks for your reply. I have tested the method below but failed.

  1. I created the folder “assets” and “images” under it then added photos there.
  2. I created “_default” folder and “single.html”.
  3. I added “featured = ‘images/a.jpg’” to my script.

Here are my questions:

  1. Originally, I have a html file related to section already. Would it cause problem since I newly created single.html?
  2. My markdown used “:” instead of “=”. Would it be a problem? My process is based on blogdown library in R. When I add this “featured = ‘images/a.jpg’”, there is some problem appearing in R.
    Thanks.

It works fine. Try it:

git clone --single-branch -b hugo-forum-topic-42231 https://github.com/jmooring/hugo-testing hugo-forum-topic-42231
cd hugo-forum-topic-42231
hugo server

I got your point. I saw your folder and how you organized files. But I can’t adopt your method into my blog.

First is about the way I write in my markdown file. I can’t change them from “:” to “=” as you did.
Second is about the html. Should I combine my publication html to yours? Actually, I have tried it but failed.

Then convert the TOML to YAML

I think you can just insert the snippet above in your existing template, but I can’t be sure without seeing your repository; it is currently private.

.