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.
This might be useful: https://github.com/sclevine/yj
You would have to write a script to:
- Detect the front matter format (
yj
does not autodetect) - Split the front matter from the content
- Convert the front matter
- Reassemble the front matter with the content
yj
reads from stdin
and writes to stdout
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/test.md
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}"
So the 1>&2
bit directs Hugo’s messages from stdout
to stderr
. So if you do this:
myscript toYAML post/test.md > 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.
I didn’t know that. thanks for explaining.
There’s an existing proposal related to this:
I searched “hugo convert”, but it seems like I missed the second page.