utilities/snippets_cli_go#1: Project Overview



Issue Information

Issue Type: issue
Status: closed
Reported By: btasker
Assigned To: btasker

Created: 27-Sep-24 08:03



Description

Background

snippets.bentasker.co.uk is currently created with my home-grown PHP static site generator.

However, it's now years old and I'd like to replace it with something more modern.

My intention is to migrate to Nikola just like I did with my recipes site.

But, most of my snippets usage happens via a custom cli:

sbt_cli foo

That CLI relies on fetching the JSON sitemap that my SSG generates. No other SSG generates one of these. Whilst I could create a Nikola plugin to generate a compatible file, it would seem to make more sense to create a new utility which consumes a RSS feed.

The old CLI was in Python, but I've elected to write this in Go - there's no other reason for that than that I fancied doing it in Go.


Featureset

The Python CLI has a number of features, not all of which are intended for the initial Go implementation

  • [x] search: My primary mode of interaction is searching
  • [x] [number]: Output snippet with id (see note below)
  • [x] autodisplay: if a search results in a single snippet, output that snippet
  • [ ] list: list all snippets in the system (not implemented because I've never used it)
  • [ ] local caching: probably will be implemented in future, but not a high priority
  • [ ] analytics ping: not needed. I never actually updated the embedded URL when I stopped using piwik

Snippet IDs

The old implementation leans quite heavily on IDs - each snippet is given an ID at generation time.

Whilst we could (and probably will, come import time) expand the front-matter fed into Nikola to include these they'll still not be available via the RSS feed.

So, if we want to use IDs as a means of specifying a snippet they'll need to be assigned deterministically by the CLI


Snippet Output

The old CLI retrieves a JSON object describing the snippet and then constructs output section by section.

We won't be able to do that - we'll have to process HTML and reformat into something CLI friendly.

We can get that HTML from one of two sources

  • RSS feed: requires the feed to be set to contain full content, increasing its size
  • Fetching the page itself: means an extra request but keeps the RSS feed small (and reduces it's utility to sites that steal content by rendering RSS feeds)


Toggle State Changes

Activity


assigned to @btasker

I think we're now more or less at parity with the features that I actually use with a couple of extras thrown in

  • Support for searching www.bentasker.co.uk and recipebook.bentasker.co.uk depending on the binary name (see #8)
  • Removal of the unused sub-commands

What we're lacking, of course, is the ability to search my snippets site because I haven't done the migration yet.