💾 Archived View for thrig.me › software › blog-engine.gmi captured on 2023-06-16 at 17:15:37. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2023-04-19)

➡️ Next capture (2023-11-14)

-=-=-=-=-=-=-

Blog Engine

A description may be more useful than any code. Alternatives exist:

gemini://perso.pw/blog/articles/blog-workflow.gmi

schema

For sqlite. To support multiple blogs I'd probably vary the database file used rather than complicating it with a site table. One could make this more complicated with a field to indicate whether an article should be published, or not.

    CREATE TABLE blog (
      id INTEGER NOT NULL PRIMARY KEY,
      epoch INTEGER NOT NULL,
      mtime INTEGER NOT NULL DEFAULT 0,
      filename TEXT NOT NULL,
      subject TEXT NOT NULL,
      body TEXT NOT NULL
    );
    CREATE INDEX blogepoch ON blog (epoch);
    CREATE INDEX blogmtime ON blog (mtime);

blog-about

A CLI tool to make new, list existing, or to edit entries. At the heart it calls out to a text editor that works on a temporary file; the format looks something like an email message,

    Epoch 1670907653
    Filename yet-another-blog-engine-rewrite
    Subject Yet Another Blog Engine Rewrite

    # Yet Another Blog Engine Rewrite
    ...

Known header values get put into the corresponding blog table columns, and remaining text after the header is placed into the body column.

    $ blog-about yet-another-blog-engine-rewrite
    $ blog-about -l
    $ blog-about -e 30

The epoch tracks the "date" of the posting, and the mtime when the article was last edited, which is used to determine what articles need to be updated and can be exposed via RSS or other interfaces.

genblog

This script converts the database contents into a static site. Local links that have files for them in ~/tmp get copied into the directory of the blog entry automatically. Improvements could be made to generate monthly or yearly round-ups, to limit the number of entries on on the main index, etc.

Then, rsync stuffs the files up onto the virtual host via a Makefile rule--since OpenBSD ships with make, why not use it?

    clean:
    	git clean $PREVIEW --force -x

    sync:
    	rsync --timeout=15 $PREVIEW --delete --delete-excluded -avz --exclude=.git\* --exclude=/Makefile --exclude=/genblog . gh:/var/gemini/thrig.me/

    .PHONY: clean sync

The PREVIEW environment variable can then be used to see what would change without actually doing so by passing a suitable flag for rsync. The "clean" rule is so things like *.core or ktrace.out can be removed. Probably these should get added to an rsync exclude-from file.

    $ PREVIEW=-n make sync
    ...

The "gh" in the "gh:/var/gemini/thrig.me" rsync target is an alias for my "go home" host. This is set in the ~/.ssh/config file.

    Host thrig.me vultr gh
      Hostname 104.207.156.138
      IdentityFile ...

Offline Copy

The offline copy is a backup, and can be used locally

/tech/gemini/localhost.gmi

to view pages being modified:

    $ ls
    blog-engine.gmi index.gmi       w3m.gmi
    $ wv -l blog-engine.gmi
    gemini://thrig.me/software/blog-engine.gmi
    $ wv -t test -l blog-engine.gmi
    gemini://localhost/software/blog-engine.gmi

wv is an alias for the perhaps too complicated ow.c that can be found under

https://thrig.me/src/scripts.git

that uses the mapping

    $ grep gemini ~/.ow/dirmap
    /var/gemini/(?<rest>.+) gemini://%{rest}
    /var/gemini/thrig.me(?:/(?<rest>.+))? gemini://localhost/%{rest} test

Another way to view what a file looks like is via the editor configuration, here for vi (there are two ^M after the % in the actual configuration file):

    map \t :!amfora %

which merely maps backslash-t (for "try it out") to running a gemini browser on the filename. This however will not have the full features of a gemini server, autoindex in particular. One could also make a mapping of

    map \y :!wv -t 

to direct the URL of the file to the server on the localhost interface. But that will take longer, as instead of using a file on disk it must go though a gemini server. This is a custom version of vi, forked from the base version found on OpenBSD, and is delightfully lacking in features, and thus very fast.

https://thrig.me/src/vi.git

How about some other software?

tags #blog #sqlite #perl