Note: In order to avoid more repetition than is utterly necessary, this post assumes at least some familiarity with the content of its predecessor from earlier this year.
Now, in a Node.js-based SSG, you can do something like this from the command line:
node newfile.js posts/2022/12/this-is-my-new-post.md
. . . to get:
src/ └─ posts/ └─ 2022/ └─ 12/ ├── this-is-my-new-post.md
. . . with the following content (assuming someone named John Doe had entered that command at 10:18:47 AM U.S. Central Standard Time today):
---- title: "This is my new post" description: "DESCRIPTION TO COME." author: John Doe date: 2022-12-12T10:18:47-06:00 draft: true --- Text begins here.
This leaves only the immediate task of slightly improving the
title’s punctuation and capitalization, if necessary (as you see, a simpler title doesn’t need any help). You could wait until later to firm up the
description; and, of course, the
date timestamp doesn’t matter until it’s actually time to publish to the website. The
draft item is valid in some JS-based SSGs out of the box, while others require some additional work to make the SSG know how to handle it.
The point, however, is that doing it this way, as opposed to using the simpler shell-script method from my earlier post on this subject, allows for more easily including variables which further automate the job.1
newfile.js, that came from all this noodgering on my part; the comments provide annotation and give credit to those sources from which I gratefully grabbed and/or adapted helpful code:
And, yes, I know there are ways to inject at least some variables into shell scripts to achieve somewhat similar results; but, in the end, I preferred going this route in order to achieve its greater flexibility and extensibility. ↩︎