pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit 2d8805f90782cbb4cdc51fae46da1a44bd5d37b2
parent 6edcf02544d2c68d0820bf87237149c0da9a83ce
Author: pyratebeard <root@pyratebeard.net>
Date:   Thu, 17 Nov 2022 23:13:51 +0000

as_a_matter_of_course

Diffstat:
Mentry/as_a_matter_of_course.md | 82++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 58 insertions(+), 24 deletions(-)

diff --git a/entry/as_a_matter_of_course.md b/entry/as_a_matter_of_course.md @@ -1,11 +1,11 @@ -This web log as been through a number of iterations. First I used Jekyll on Github Pages, then I switched to Hugo using a docker container and Gitlab's CI/CD pipeline, and finally the current setup. +This web log as been through a number of iterations. First I used [Jekyll](https://jekyllrb.com/){target="_blank" rel="noreferrer"} on [Github Pages](https://pages.github.com/){target="_blank" rel="noreferrer"}, then I switched to [Hugo](https://gohugo.io/){target="_blank" rel="noreferrer"} using a docker container and [Gitlab's CI/CD](https://docs.gitlab.com/ee/ci/){target="_blank" rel="noreferrer"} pipeline, and finally the current setup. -I moved away from the docker container as the build started failing and I hit too many issues trying to get it working. In an effort to simplify everything I thought why couldn't I write my entries in markdown then use [pandoc](https://pandoc.org/){target="_blank" rel="noreferrer"} to convert them to HTML? +I moved away from the docker container as the build started failing and I hit too many issues trying to get it working. In an effort to simplify everything I thought, why couldn't I write my entries in markdown then use [pandoc](https://pandoc.org/){target="_blank" rel="noreferrer"} to convert them to HTML? ``` pandoc -f markdown -t html -o new_entry.html new_entry.md ``` -Sounds so easy, and it is in essence. +Sounds so easy. The main script, [pyratelog.sh](https://git.pyratebeard.net/pyratelog/file/pyratelog.sh.html){target="_blank" rel="noreferrer"} does all the heavy lifting. When a new entry is published the script does some prep then runs `pandoc` to convert the markdown file to html. I use a template file so my markdown only has to be the main body of content. This is how the command looks in my script @@ -19,10 +19,16 @@ pandoc -s \ entry/${input}.md ``` -The pyratelog.sh script also sets the link on the main page and adds the entry to my _rss.xml_ file. +The `pyratelog.sh` script also sets the link on the main page and adds the entry to my _rss.xml_ file. + +In order for the script to know when a new entry has been published I use `inotifywait` to watch for files in the _entry/_ directory +``` +inotifywait -m -e create -e moved_to /var/www/html/entry/ | xargs -L 1 /var/www/html/pyratelog.sh +``` Over time I have included three more scripts to improve my writing workflow, [draft](https://git.pyratebeard.net/pyratelog/file/scripts/draft.html){target="_blank" rel="noreferrer"}, [preview](https://git.pyratebeard.net/pyratelog/file/scripts/preview.html){target="_blank" rel="noreferrer"}, and [publish](https://git.pyratebeard.net/pyratelog/file/scripts/publish.html). +### clapperboard The `draft` script will checkout a new or existing branch based on the name I pass it, the name will be the title of the entry. ``` # use arg as title and set entry file path @@ -46,7 +52,7 @@ vim "${ENTRY}" Now I let my creative juices flow to produce more enjoyable content for you. -Once I have finished and close `vim` the `draft` script continues by adding and committing the changes to `git`. +Once I have finished and close `vim`, the `draft` script continues by adding and committing the changes to `git` ``` # when vim closes add and commit the changes # if there are any @@ -55,6 +61,7 @@ git add "${ENTRY}" git commit -S -m "${TITLE}" ``` +### advanced screening The `preview` script was written as sometimes I like to see what the entry looks like in the browser, especially when I put pictures in. It is useful to read through in the browser as well, I have caught a number of spelling mistakes and poorly worded sentences that way. To do this the script creates a temporary directory and copies in the entry in question, the template file for `pandoc`, and my custom CSS @@ -105,6 +112,7 @@ kill ${busypid} rm -rf demo/ ``` +### it's a wrap Finally I can run the `publish` script to send my entry out into the world. This is the simplest of the three scripts. It will rename the entry to prefix the date then merge the branch into the main branch and push to my git server ``` # use arg as title and set entry file path @@ -132,46 +140,48 @@ git merge "${TITLE}" git push ``` -In a [previous entry](TK){target="_blank" rel="noreferrer"} I spoke about using [git hooks](TK){target="_blank" rel="noreferrer"} on my git server to keep my wiki up to date. I use the same `post-receive` hook for my blog. +In my [last entry](20221111-what_the_hook.html){target="_blank" rel="noreferrer"} I spoke about using [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks){target="_blank" rel="noreferrer"} on my git server to keep my wiki up to date. I use the same `post-receive` hook for my web log. ``` #!/bin/sh ssh logserver "cd /var/www/html ; git pull" ``` -The only thing I have to do after hitting publish is [toot about it](https://harbour.cafe/@pyratebeard){target="_blank" rel="noreferrer"}. I will be adding in an auto toot in the `publish` script, similar to my [weeklymusictoot](TK){target="_blank" rel="noreferrer"} soon to save me having to even do that little job. +The only thing I have to do after hitting publish is [toot about it](https://harbour.cafe/@pyratebeard){target="_blank" rel="noreferrer"}. I will be adding in an auto toot in the `publish` script soon, similar to my [weeklymusictoot](20221005-weeklymusictoot.html){target="_blank" rel="noreferrer"}, to save me having to even do that little job. -Now because I [seem to like](TK){target="_blank" rel="noreferrer"} using [Makefiles](TK){target="_blank" rel="noreferrer"} for running things I had a go at one for the `draft`, `preview`, and `publish` scripts. +### behind the scenes +Now because I [seem to like](20220124-make_believe.html){target="_blank" rel="noreferrer"} using Makefiles for running things I had a go at one for the `draft`, `preview`, and `publish` scripts. It got a bit a bit complicated with the arguments, but I was able to make it work, even setting it so that if I am already on the correct branch I don't have to pass any arguments ``` #TITLE := $(shell git branch --show-current) +RND := "" # https://stackoverflow.com/a/14061796 # If the first argument is "draft" ifeq (draft,$(firstword $(MAKECMDGOALS))) # use the rest as arguments for "draft" - DRAFT_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) # ...and turn them into do-nothing targets - $(eval $(DRAFT_ARGS):;@:) + $(eval $(ARGS):;@:) else ifeq (preview,$(firstword $(MAKECMDGOALS))) - VIEW_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) - $(eval $(VIEW_ARGS):;@:) + ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + $(eval $(ARGS):;@:) else ifeq (publish,$(firstword $(MAKECMDGOALS))) - PUB_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) - $(eval $(PUB_ARGS):;@:) + ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) + $(eval $(ARGS):;@:) endif endif endif -ifeq ($(DRAFT_ARGS), ) - DRAFT_ARGS := $(shell git branch --show-current) +ifeq ($(ARGS), ) + ARGS := $(shell git branch --show-current) endif -ifeq ($(VIEW_ARGS), ) - VIEW_ARGS := $(shell git branch --show-current) +ifeq ($(ARGS), ) + ARGS := $(shell git branch --show-current) endif -ifeq ($(PUB_ARGS), ) - PUB_ARGS := $(shell git branch --show-current) +ifeq ($(ARGS), ) + ARGS := $(shell git branch --show-current) endif prog: # ... @@ -180,13 +190,37 @@ prog: # ... .PHONY: draft preview publish draft : prog - scripts/draft $(DRAFT_ARGS) + scripts/draft $(ARGS) $(RND) preview : prog - scripts/preview $(VIEW_ARGS) + scripts/preview $(ARGS) publish : prog - scripts/publish $(PUB_ARGS) + scripts/publish $(ARGS) $(RND) +``` + +As an example, to start a new entry I incant +``` +make draft as_a_matter_of_course +``` + +An empty buffer is opened in `vim` and I can start writing. After some time I decide I need a break so I save and exit `vim`. When I come back I know I am already on the *as_a_matter_of_course* branch so I can incant +``` +make draft ``` -For example, when writing this entry +Once the entry is finished I save and exit `vim` then incant +``` +make preview +``` + +After reviewing the finished piece I can incant +``` +make publish +``` + +These three scripts have sped up my writing process and have made it even easier to switch between drafts if I have more than one entry in the works at a time. + +One issue that I have had to overcome, and it's a big one, is that I need to think of the title before I start the draft. A few of my previous entries have had working titles right up until the moment they are published. I have thought about adding in a step to the publish script to change the title before it goes out, but for now I will force myself to think harder about the titles. + +There are still some tweaks and improvements I want to look into but I have been happy with this process since I created it, and adding in the additional scripts has helped a lot. It has certainly sped up my workflow and I haven't had any issues with the automated publishing, long may it last.