okay so i got up to some bullshit while writing this, so listen up.

I'm still using the "blog" and "journal" formats from miso.town for writing the blog and the journal.

<https://blog.miso.town/>

<https://journal.miso.town/>

But I grew unsatisfied using them to auto-generate the rss feeds.

Primarily because it couldn't handle the "~/dozens" part of my base "https://tilde.town/~dozens/clericthief" URL. And also because it included a lot of auxilary HTML elements like the navbar.

So I decided I needed to roll my own feed generators.

I discovered a clever way to use ed.

You can wrap a file in ed commands like so:

```
echo i | cat - file.txt commands.ed | ed -s
```

where `i` is the ed command for insert.

The contents of your file, `file.txt` follow.

Make the first ed command in `commands.ed` a `.` to stop insert mode.

And then all your other ed commands can follow.

`ed -s` starts ed in silent mode.

If you end your list of commands with `1,$w /dev/stdout` then you can pipe the output to something else.

Neat!

So what I had was some very lightly structured text.

I decided the easiest thing to do would be to isolate the list of blog entries, and then format them as recfiles, which was pretty easy.

Here's my index.md at the time of this writing:

```
---
title: "Cleric + Thief"
subtitle: Adventures of Iofi and Maddox
created: 2022-08-30
updated: 2022-09-01
---

[subscribe to episodes](episodes.xml)

<!-- BEGIN //-->
- <time>2022-09-03</time> - [00003. The Hand](00003-hand.html)
- <time>2022-09-01</time> - [00002. Meadowgloom](00002-meadowgloom.html)
- <time>2022-08-30</time> - [00001. Cleric + Thief](00001-introductions.html)
<!-- END //-->
```

ed commands:

- `g/BEGIN/ka` - find 'BEGIN' and make a bookmark `a`
- `g/END/kb` - find 'END' and make a bookmark `b`
- `1,'ad` - delete eveything from the 1st line up through bookmark a
- `'b,$d` - delete from 'b to the end of the file

output:

```
- <time>2022-09-03</time> - [00003. The Hand](00003-hand.html)
- <time>2022-09-01</time> - [00002. Meadowgloom](00002-meadowgloom.html)
- <time>2022-08-30</time> - [00001. Cleric + Thief](00001-introductions.html)
```

Then I did some search and replace so that each line turned into a recfile record.

ed commands for that:

```
%s/^- //
%s,<time>\(.*\)</time>,time: \1|,
%s, - \[\(.*\)\],title: \1|,
%s,(\(.*\))$,source: \1|link: \1|,
%s/html/md/
%s/|/\
/g
```

results:

```
time: 2022-09-03
title: 00003. The Hand
link: 00003-hand.html
source: 00003-hand.md

time: 2022-09-01
title: 00002. Meadowgloom
link: 00002-meadowgloom.html
source: 00002-meadowgloom.md

time: 2022-08-30
title: 00001. Cleric + Thief
link: 00001-introductions.html
source: 00001-introductions.md
```

and from there I could write a recfmt template:

```
01 <item>
02   <title>{{title}}</title>
03   <link>http://tilde.town/~dozens/clericthief/{{link}}</link>
04   <pubDate>syscmd(`gdate -d {{time}}')</pubDate>
05   <guid isPermaLink="false">{{time}} {{title}}</guid>
06   <description>
07     <![CDATA[
08       include(`src/{{source}}')
09     ]]>
10   </description>
11 </item>
```

There are m4 macros on lines 04 and 08 to insert the correctly formatted time, and to include the markdown content, respectively.

You can see the whole thing in the justfile, but the gist to get each rss item is:

```
echo i | cat - src/index.md ed/blogcommands.ed | ed -s | recfmt -f templates/blogitem.template | m4
```

The process for the journal entries is basically the same, with a little extra search and replace funny business in ed since the whole thing is one flat document.

The thing that really made all this work was the rec format. It made it super easy to format the data.
