Hugo convert for single md files

I would love to be able to use hugo convert for single files, but writing the the result to stdout not a new file, so when I want to automatically update posts I don’t need to be able to parse 3 different front matter types.

Please re-read Requesting Help and rephrase this topic. It’s very unclear what exactly you want to achieve.

I want the same functionality of hugo convert, but not for a whole site, but for a single file. I also want (an option for) the output to be written to stdout not a new file.

1 Like

This might be useful:

You would have to write a script to:

  1. Detect the front matter format (yj does not autodetect)
  2. Split the front matter from the content
  3. Convert the front matter
  4. Reassemble the front matter with the content

yj reads from stdin and writes to stdout

1 Like

Disregard my previous post. This is simple with a Bash script.

#!/usr/bin/env bash

temp=$(mktemp -d)
hugo convert 1>&2 "$1" -o "${temp}"
cat "${temp}/content/$2"
rm -r "${temp}"

Then call it like:

myscript toYAML post/

The script doesn’t do any error checking (number of args, value of args, path existence, success of commands, etc.), but you get the basic idea.

Under the covers it converts the entire site, then displays the file of interest, so I have no idea how quick this would be with large site.


Thanks! I added --quiet to the hugo command like so, to remove the output from hugo convert:

temp=$(mktemp -d)
hugo convert 1>&2 "$1" -o "${temp}" --quiet
cat "${temp}/content/$2"
rm -r "${temp}"
1 Like

So the 1>&2 bit directs Hugo’s messages from stdout to stderr. So if you do this:

myscript toYAML post/ > test.txt

You will see that stdout does not contain Hugo’s message. The --quiet option does the job, but may hide things you would rather know about.

1 Like

I didn’t know that. thanks for explaining.

There’s an existing proposal related to this:

1 Like

I searched “hugo convert”, but it seems like I missed the second page.