Wednesday | 04 DEC 2024
[ previous ]
[ next ]

Updating the Blog

Title:
Date: 2024-01-07
Tags:  blog

Table of Contents

  1. BASIC Triggers
  2. Entr
  3. Inotify

I spent some time today to make it easier to update my blog. My usual flow is to make a change to one of my blog entries or a create a new one. Once I'm done, I'll manually do RUN BP DOWNLOAD-DATA which will update my public site. That routine checks for any changed files and pushes them to my web server where it get's loaded into #scarletdme.

It's been working well but I always need to do that step of triggering the push. I wanted to have monitor set up so that any change to my blog entries would trigger the push. This is just another stone in the path of making my blog easier to write for.

BASIC Triggers

My first idea was to use BASIC triggers. I thought that this would be a [pure] way of doing things.

I'll do a longer post later but the gist is the following: create a program that does the pushing, I already have this. Then set up a trigger in BASIC to watch the blog file and run the script when something changes. This structure is simple but effective.

The command to drop a trigger is:

DROP TRIGGER "BLOG-FILE" "UPDATE.BLOG.TRIGGER";

Triggers in BASIC need to be cataloged in the global scope:

ICATALOG BP "!UPDATE.BLOG.TRIGGER"

Finally the command to create a trigger is:

CREATE TRIGGER UPDATE.BLOG.TRIGGER AFTER INSERT OR UPDATE OR DELETE ON "BLOG-FILE" FOR EACH ROW CALLING "!UPDATE.BLOG.TRIGGER";

The great thing is because this is from within [universe] universe knows that a record is changed or added relatively easily.

This method ultimately doesn't work for me because there is a limitation on triggers. They are running inside a transaction and you can't shell out to Linux in a transaction. This means that I can't call my scp command to send things over.

I have some ideas on getting around this. I think there's a way to change the transaction settings to allow the shelling out. This is something to [todo] look into,.

Another interesting avenue is to get rid of my scp with something that works from BASIC directly. This one is harder to do.

Entr

I quickly gave up the idea of BASIC triggers and gave entr a shot. entr is a wrapper for inotify and I'd have preferred to use entr as it is simpler.

The big issue is that it didn't let me watch for modification events and because my blog file is a single file in linux, this means that entr was only running my push script when the file was closed. I wanted it to push every time I did :w.

This disqualified entr.

echo "BLOG-FILE" | entr /home/scripts/push-blog.sh

Inotify

This is what I'm currently using to watch for changes in my blog file.

#!/usr/bin/env bash

cd /home/BLOG/

while true; do
    inotifywait -e modify,close_write \
        /home/BLOG/BLOG-FILE && uv "RUN BP DOWNLOAD-DATA"
done

I then execute the script by doing:

nohup /home/scripts/push-blog.sh &

I watch for the modification event and the close event for my blog file and then run my routine to push the changes to my blog. Inside my routine, I have a lock that makes sure that only once instance of my push is running. This way if I rapidly make changes, I won't run into any weird issues. Hopefully.

Incoming Links

  1. [ January 2024 ]
  2. [ Ideas in 2024 ]