utilities/snippets_cli_go#5: Assign IDs to feed items



Issue Information

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

Milestone: v0.1
Created: 27-Sep-24 10:19



Description

The old setup uses numbers to identify specific snippets. These are assigned by the SSG.

The new deployment won't have this, but it's quite a useful way to be able to refer to items where a search returns multiple results:

$ sbt_cli lua
Search results - String: lua, title: False, lang: False, similarto: False
| Snippet ID | Title                                         | Language |
|-----------------------------------------------------------------------|
| 142        | Check if value exists in table                | LUA      |
| 133        | Connect to HTTPS upstream with lua-resty-http | LUA      |
| 101        | Check if variable is numeric                  | LUA      |
| 96         | Urldecode string                              | LUA      |
| 83         | Recursively print table (print_r equivalent)  | LUA      |
| 40         | Check if variable is table                    | LUA      |
| 26         | Imploding a table                             | LUA      |
| 18         | Trim whitespace from string                   | LUA      |
| 17         | Trim whitespace from beginning of string      | LUA      |
| 14         | Trim whitespace from end of string            | LUA      |
| 13         | Split string on Delimiter                     | LUA      |
| 12         | Check if table has element                    | LUA      |
-------------------------------------------------------------------------

To view "Split string on Delimiter" I'd run sbt_cli 13.

This new utility needs to do the same, but will need to allocate numbers itself.

Requirements:

  • The numbers must be relatively deterministic: they shouldn't shift every time I publish a new snippet
  • The numbers need to be feed wide rather than allocated when building search results


Toggle State Changes

Activity


assigned to @btasker

We could probably implement this by iterating through the feed to build a slice.

However, that feels more than a little inefficient (because we'll be iterating through again to run the search).

So, there are two other ways we could run at this

  • Allocate an ID when iterating through during search (regardless of whether the search term matches)
  • Pass go-feed a custom translator which allocates an ID

Although the second could be fun, I think the first is probably the better one.

verified

mentioned in commit f975c94f0ef5a719dbbb81102bd2f5311edca092

Commit: f975c94f0ef5a719dbbb81102bd2f5311edca092 
Author: B Tasker                            
                            
Date: 2024-09-27T11:24:49.000+01:00 

Message

feat: assign an ID to each entry (utilities/snippets_cli_go#5)

+8 -2 (10 lines changed)

This turned out to be much easier than expected: gofeed has a Len() function which tells you how many items there are in the feed. So it's easy to have a decrementing counter

mentioned in issue #6