Convert Hugo Content Files to Page Bundles

The bash script here converts the _index.md file to a page (leaf) bundle which is not convenient (since it converts the branch bundle to a leaf bundle). To exclude the file, try the code below

for FILE in *.md
do
if [[ "$FILE" == "_index.md" ]];then continue; fi
  # remove the last dot and subsequent chars to name the folder from the .md
  DIR="${FILE%.*}"
  mkdir -p "$DIR"
  mv "$FILE" "$DIR"
done
find . \( -iname '*.md' ! -iname '_index.md' \) -execdir mv -i '{}' index.md \;

Save the script in a file such as page-bundles.sh and make it executable depending on your platform. (On Windows, I have Git installed and double clicking on the sh file does the conversion for me automatically).

N.B. The script should be used in a folder full of .md files and the .sh should be in the same directory. (Solution put together with support from Stack-Overflow)

4 Likes