Featured image of post Hugo them switch and modifying posts

Hugo them switch and modifying posts

I just switched to a new theme and want to modify post from PostName.md to PostName/index.md

I previously used the hugo theme Mainroad and implemented a local search function using Tipue Search (project seems abandoned). It works well but I need to manually modify the generated content file (remove “,” in the first line) every time for a new post. For me the search function is essential, along with other features like ToC, dark mode, and tag counts. Now I am using Stack which uses Hugo’s Page Bundle feature. Then I need to re-organise the sources of a post, i.e. move all figures in the same directory as the post index.md file.

For all PostName.md files, make a folder with the name PostName, and move and rename PostName.md to /PostName/index.md

First I need to change the “thumbnail = " slug to “image = " for each post md file:

1
for i in *.md; do sed 's/thumbnail =/image =/' $i > ../_step1/$i; done

and then remove the “/images/” prefix for the path

1
for i in *.md; do sed 's/image = \"\/images\//image = \"/' $i > ../$i; done

Finally make folder and rename files (credit)

1
2
3
4
5
6
7
#!/bin/bash
for f in *.md
do
  subdir=${f%%.*}
  [ ! -d "$subdir" ] && mkdir -- "$subdir"
  mv -- "$f" "$subdir"/index.md
done
comments powered by Disqus
CC-BY-NC 4.0
Built with Hugo Theme Stack