# recutils exploration

*Entered: in emacs on GPD Pocket X7* 
*Date: 20230824*

## ever since

Tomasino [posted about recutils][1], I have been
intrigued. In my [2022-06-06 phlog post][2], I stated I had
an idea to generate my gophermaps via a recutils
database. This wasn't such a new idea for me, back in 2017
this gopherhole was run on a "CMS" system I wrote in C that
fed from a MySQL database. This was overkill, and of course,
ended up being a pain in the ass.

[1]: https://labs.tomasino.org/gnu-recutils/
[2]: gopher://1436.ninja/0Phlog/20220606.md

## giving it a shot

The main thing that made it a pain in the ass, was I never
got around to writing a frontend for the database. I used
the PHPMySQL frontend to edit my site the entire time I used
the CMS system. The PHPMySQL instance was only hitable from
my internal network, and at the time that meant I used it
via VNC most of the time.

Using recutils, well it's a damn text file. I ssh into my
server often and can use the recutils utils, sed, awk, vim,
etc. to make changes. Simple scripts can easily turn any
gophermap into a recfile - gophermaps are tab delimited
files already made up of fields.

I wrote a cgi-bin script that uses the $QUERY_STRING to
receive the name of a gophermap (strips all non-alpha
characters) and then it recsels the matching entries and
feeds the results to a recfmt template as described in my
phlog entry above (but a lot less kludgily). 

I really like that everything is in one central file. I do
not need to navigate all over to make changes to menu
structure. Another plus is consistent look - I have the main
gophermap (itself a script feeding from the recfile) and the
page cgi script both displaying the same header file. Change
in one place and it is reflected instantly everywhere,

## sitelog

I also went ahead and converted my sitelog into a
recfile. Recfiles only sort ascending. This posed the issue
of how to pull just the latest sitelog entry to display on
the main gophermap. I came up with this:

```
recsel -n $(echo $(grep Date /path/to/sitelog.rec | wc -l)-2 | bc) -P Date,Log /path/to/sitelog.rec
```

Okay, not everything is less kludgey, but I'm working on it.