It’s taken a bit of tweaking but I’ve finally put together a simple script which archives and publishes in one command.

The Problem

Last post, I mentioned having three different scripts to effectively publish:

  • autoscrp.sh (the first script I wrote to push to Scriptogram from the console)
  • create_metadata.sh (a script I wrote to create the metadata Scriptogram needed automatically)
  • archive.sh (a more recent script to keep my drafts folder clear of published material)

These had to be executed in a certain order (2, 1, 3 as it turns out since autoscrp.sh was dependent on create_metadata.sh).

Furthermore, I still had to tweak the files as I went. The script create_metadata.sh was written so that it required the first level-1 header in the file to provide the title of the post (Scriptogram takes this as a metadata field), whereas autoscrp.sh didn’t need the level-1 header at all. In fact, as it was, I had to manually strip out the header, publish with autoscrp.sh before putting it back in for archive.sh. I wanted to do away with this fiddliness.

The Solution

I got rid of create_metadata.sh and integrated that into my autoscrp.sh file.

That left me with only two files so I had to create another one to make up for it (I’m only half-serious).

I wrote publish.sh to effectively determine the order the other two scripts should be run in and to save myself from typing two commands. At the moment, it’s a simple as this:

## Make folder definitive by moving out of `drafts` and into `archive`.

	pieceref=$(./archive.sh $1)

## Use reference for relevant piece to push out to Scriptogram.

	./autoscrp.sh $pieceref

You may also notice that it takes an output from archive.sh as a variable and uses it as an argument for autoscrp.sh. This is because I silenced other messages from archive.sh and had it echo only the new filename of the now-archived piece.

This is effectively like a sign-off which provides a single reference to the relevant content. I then use that reference for a now adapted autoscrp.sh to push straight from the archive to my blog – which happens to be on Scriptogram.

As I write other scripts for other possible blogging platforms I simply add the scripts to this publish.sh file using the same archived piece reference. In this way, I can theoretically push out to multiple channels and keep my own repository channel-neutral.

What next?

At some point, I see myself relegating all Scriptogram specific scripts and data files to a Scriptogram specific folder so that I can start to explore and review other platforms without any dependencies. I might also need to build in some error-checking.

In the short-term however I hope to use this work on tying up and making the publish consistent as a springboard into issues like cross-linking and image-referencing. And from there on into less self-referential posts.

I also need to come up with a simple way of republishing a post, with or without a new date and time. At the moment, the scripts act as if typos and the like won’t ever be a problem.