Create An Atom Feed In Rust
Introduction
This is what I'm doing to make an Atom feed for my site. More notes below the code.
Code
//! ```cargo
//! [dependencies]
//! atom_syndication = "0.12.2"
//! chrono = { version = "0.4.26", features = ["std"] }
//! uuid = { version = "1.6.1", features = ["v5"] }
//! ```
use *;
use *;
use BTreeMap;
use fs;
use Uuid;
Results
My Example Feed
urn:uuid:b71fc261-fc1a-4220-b43f-2be4b216c0b2
2024-01-02T23:29:27.999342+00:00
Alan W. Smith
https://www.example.com/
This Is A Title
urn:uuid:b1507332-d46c-5bcf-929a-f89c59e01bac
2023-12-17T10:33:55+05:00
Alan W. Smith
https://www.example.com/
<p>Hello, world</p>
Notes
This is for an Atom feed. A similar crate exists for RSS (linked below)
I went with Atom based off
The UUIDs work by creating a UUID4 that stays the same every time the feed is generated and then a UUID5 for each file based off an ID that's attached to the file
The UUID5 is a combination of the main feeds UUID4 + the unique ID for the file. Given those two inputs the output is always the same. That lets the individual entry IDs stay the same even if their content changes.
The `updated_date`` is a `atom_syndication::FixedDateTime`` which is an alias of `chrono::DateTime<::chrono::FixedOffset<`` from the chrono crate
My content file dates don't have a timezone (e.g. `2023-07-15 18:02:07``). The `tz_hour_offset`` is my offset from GMT which I use to calculate the data to get to the `DateTime`` that's needed
The rest of the date code converts to the necessary object format that then outputs with a timezone like: `2023-07-15T18:02:07+05:00`` in the feed
There's a bunch of things set to `None`` across the code. The docs (linked below) list all those details
The content comes out as HTML escaped characters. (e.g. `
I put two outputs in the example. The first one outputs to a file with a config attached that pretty prints the contents. The second one outputs a string. I haven't figure out a way to pretty print that though
I'm not sure what the 'rel' should be. I tried "canonical" at first, but it didn't work with RSS Parrot. I've now changed it to "self" which is what I've now seen on other feeds. We'll see what happens