pyratelog

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

commit 91bfbe9f45e5b9b027cbf6955f96e098883f2f64
parent e053d28b32d5ad9bf8630da1418604140173b168
Author: pyratebeard <root@pyratebeard.net>
Date:   Thu, 17 Nov 2022 21:57:51 +0000

as_a_matter_of_course

Diffstat:
Mentry/as_a_matter_of_course.md | 85+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 48 insertions(+), 37 deletions(-)

diff --git a/entry/as_a_matter_of_course.md b/entry/as_a_matter_of_course.md @@ -1,8 +1,8 @@ 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. -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 posts 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_post.html new_post.md +pandoc -f markdown -t html -o new_entry.html new_entry.md ``` Sounds so easy, and it is in essence. @@ -11,7 +11,7 @@ The main script, [pyratelog.sh](https://git.pyratebeard.net/pyratelog/file/pyrat ``` pandoc -s \ - --template=./post_template.html \ + --template=./entry_template.html \ --metadata title="${input_title}" \ -f markdown \ -t html \ @@ -23,11 +23,11 @@ The pyratelog.sh script also sets the link on the main page and adds the entry t 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). -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 post. +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 post file path +# use arg as title and set entry file path TITLE=$1 -POST="entry/${TITLE}.md" +ENTRY="entry/${TITLE}.md" # checkout the correct branch git branch | grep ${TITLE} && \ @@ -37,11 +37,11 @@ git branch | grep ${TITLE} && \ It will then open up a new or the existing file with that same name in `vim`. ``` -# if post file does not exist yet touch it -[ -f "${POST}" ] || touch "${POST}" +# if entry file does not exist yet touch it +[ -f "${ENTRY}" ] || touch "${ENTRY}" -# open post file in favourite editor -vim "${POST}" +# open entry file in favourite editor +vim "${ENTRY}" ``` Now I let my creative juices flow to produce more enjoyable content for you. @@ -50,46 +50,50 @@ Once I have finished and close `vim` the `draft` script continues by adding and ``` # when vim closes add and commit the changes # if there are any -git status | grep "${POST}" || exit 0 -git add "${POST}" +git status | grep "${ENTRY}" || exit 0 +git add "${ENTRY}" git commit -S -m "${TITLE}" ``` -The `preview` script was written as sometimes I like to see what the post 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. +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 post in question, the template file for `pandoc`, and my custom css +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 ``` -# use arg as title and set post file path +# use arg as title and set entry file path TITLE=$1 -POST="entry/${TITLE}.md" +ENTRY="entry/${TITLE}.md" # create a tmp dir mkdir demo -# copy post file, post_template and css +# copy entry file, entry_template and css # to temp dir -cp ${POST} demo/index.md -cp post_template.html style.css demo/ +cp ${ENTRY} demo/index.md +cp entry_template.html style.css demo/ -# small change to post_template for stylesheet -sed -i 's%\.\./%%' demo/post_template.html +# small change to entry_template for stylesheet +sed -i 's%\.\./%%' demo/entry_template.html ``` +The same `pandoc` command is used to generate the HTML ``` # generate html file pandoc -s \ - --template=demo/post_template.html \ + --template=demo/entry_template.html \ --metadata title="demolog" \ -f markdown \ -t html \ -o demo/index.html \ demo/index.md +``` +Using `busybox` the script starts a simple web server then waits for me to finish reviewing before killing the process and tidying up the temporary directory +``` # start web server and capture pid for later busybox httpd -f -h ./demo -p 8080 & busypid=$! -# open demo post file in browser +# open demo ENTRY file in browser xdg-open http://localhost:8080 # wait until ready to stop web server @@ -97,43 +101,48 @@ echo press any key to cancel read -n 1 # kill the web server and remove temp dir -kill -9 ${busypid} +kill ${busypid} rm -rf demo/ ``` +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 ``` -#!/bin/sh - -# use arg as title and set post file path +# use arg as title and set entry file path # set published file path with date TITLE=$1 -POST="entry/${TITLE}.md" +ENTRY="entry/${TITLE}.md" PUBLISH="entry/$(date +%Y%m%d)-${TITLE}.md" -LINK="https://log.pyratebeard.net/entry/$(date +%Y%m%d)-${TITLE}.html" - -# toot command path -TOOT="$HOME/src/warez/toot/bin/toot" # checkout the correct branch git branch | grep ${TITLE} && \ git checkout ${TITLE} || \ git checkout -b ${TITLE} -# rename post to set date -git mv "${POST}" "${PUBLISH}" +# rename entry to set date +git mv "${ENTRY}" "${PUBLISH}" # commit the rename as published git commit -S -m "publish ${TITLE}" -# checkout main branch and merge published post +# checkout main branch and merge published entry git checkout main git merge "${TITLE}" -# push new post +# push new entry git push ``` -To run these scripts I use a Makefile +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. +``` +#!/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. + +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. + +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) # https://stackoverflow.com/a/14061796 @@ -179,3 +188,5 @@ preview : prog publish : prog scripts/publish $(PUB_ARGS) ``` + +For example, when writing this entry