aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorAlex Scerba <alex@scerba.org>2025-02-11 13:57:11 -0500
committerAlex Scerba <alex@scerba.org>2025-02-11 13:57:11 -0500
commit7cef22cd87d160c2484c572c8a4248d4b64c076f (patch)
tree90b3de9c5fc9f453b82757b26c28e82d5019925c /cmd
parenta95cca2f0bb22725e6c7e4d8957c91cb93bdb59f (diff)
Add atom feed generation based on acsq.me
Diffstat (limited to 'cmd')
-rw-r--r--cmd/http/feed.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/cmd/http/feed.go b/cmd/http/feed.go
new file mode 100644
index 0000000..41ec399
--- /dev/null
+++ b/cmd/http/feed.go
@@ -0,0 +1,43 @@
+package main
+
+import (
+ "time"
+)
+
+/*
+ post.File = file
+ post.Title = title
+ post.Date = date
+ post.Tags = tags
+*/
+
+// use this to check for valid feed: https://validator.w3.org/feed/
+func generateFeed(domain string, p *Posts) []byte {
+ feed := `<?xml version="1.0" encoding="UTF-8"?>
+<feed xmlns="http://www.w3.org/2005/Atom">
+ <title>ScerbaDotOrg</title>
+ <subtitle>Blog feed</subtitle>
+ <link rel="self" href="https://` + domain + `/atom.xml"/>
+ <link href="https://` + domain + `"/>
+ <author>
+ <name>Alex Scerba</name>
+ </author>
+ <id>https://` + domain + `</id>
+ <updated>` + time.Now().UTC().Format("2006-01-02T15:04:05.000Z") + `</updated>`
+
+ for _, post := range p.Collection {
+ entry := `
+ <entry>
+ <title>` + post.Title + `</title>
+ <link href="https://` + domain + `/posts/` + post.File + `.html"/>
+ <id>https://` + domain + `/posts/` + post.File + `</id>
+ <published>` + post.Date + `T00:00:00.000Z</published>`
+ entry = entry + `
+ </entry>`
+ feed = feed + entry
+ }
+ feed = feed + `
+</feed>`
+
+ return []byte(feed)
+}