HUGO

HUGO postmaker (batch script) for Windows 10

Hello, I was working on a small helper utility to automate folder hierarchy and and page bundle generation for hugo. I made it for my own personal use but I figured others might benefit from it too.

It’s written in Batch script and yes, I had to tear my hair out the whole time I was writing it.

Prerequisites:
Before anything else, place the pm.bat in your hugo project main folder. You can rename it to whatever you want, it will still work the same. The reason it needs to reside in the project’s folder is because it uses relative paths to do things. Also the hugo CLI must be accessible from your project’s folder too (obviously).

image

What can it do?
Here’s what shows up when you do pm help or pm /? or pm -h

Show Snippet
C:\hugotest>pm help
HUGO postmaker 1.1 (by s1)

For more info, visit:
https://discourse.gohugo.io/t/26242/

HUGO postmaker helps easily create posts structured inside folders.

NOTICE: This needs to be placed in your HUGO project's main folder.

USAGE: pm [-b, bundle] <command> <post-filename> [<extra languages>]
(Don't add *.md at the end of filename.)


COMMANDS:

b, -b,    (Optional) Use to specify that you want a page bundle created
bundle,   instead of a single Markdown file.
--bundle

post      Creates a new post if it doesn't exist already.
page      Creates a new page if it doesn't exist already.
section   Creates a new section if it doesn't exist already.
help      Opens this help section.
version   Show version information.


EXTRA LANGUAGES:

Applies only to post, page and bundle mode section commands.

You can add any space-delimited language codes and postmaker will create a
copy of the created Markdown file while adding the language code to its
filename. (See usage examples below.)


ADDITIONAL CONFIG:

Applies only to post command.

To change these additional configs, Open up "pm.bat"
in a text editor and change the values in the top part of the script.
It should be self explanatory.

post_section, post_format
You can set the hierarchy of your post's folder structure. By default, the
format used is "yyyy/MM/dd" and the section is set to "posts".

NOTICE: post_format only accepts date format as of right now.


EXAMPLES:

  pm post hello-world

  The above command creates:
   - posts/2020/06/14/hello-world.md

  pm post hello-world ja es de

  The above command creates:
   - posts/2020/06/14/hello-world.md
   - posts/2020/06/14/hello-world.ja.md
   - posts/2020/06/14/hello-world.es.md
   - posts/2020/06/14/hello-world.de.md

  pm post -b hello-world ja es de

  The above command creates:
   - posts/2020/06/14/hello-world/index.md
   - posts/2020/06/14/hello-world/index.ja.md
   - posts/2020/06/14/hello-world/index.es.md
   - posts/2020/06/14/hello-world/index.de.md

  pm page stuff/my-page

  The above command creates:
   - stuff/my-page.md

  pm page stuff/my-page ja

  The above command creates:
   - stuff/my-page.md
   - stuff/my-page.ja.md

  pm section random

  The above command creates:
   - random/

  pm -b section random

  The above command creates:
   - random/_index.md

  pm -b section random ja es

  The above command creates:
   - random/_index.md
   - random/_index.es.md

Some screenshots

image image

Where to get it?
I put it on Github


Or you can download the zip
https://mega.nz/file/UstH3JoS#zJy8qC7lsf99RnMhyhsmtIvhoX--Bumj7P7aF_iikUY

Typical disclaimer
I just provide this script as is. It is your responsibility to test it out first on a dummy project before using it in your actual project. I’ve been using it but I’m just one person so you might stumble across edge cases that I didn’t think about beforehand.

Have you seen archetype directories?

That might change your bundle approach. :slight_smile: