diff options
author | Alan Pearce | 2024-06-29 23:02:51 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-29 23:02:51 +0200 |
commit | c4d5654e6360e90be2106439463f49acb55dffc8 (patch) | |
tree | 9056a81b9733022f17ce7dc2eff070bedf7822ea /internal/atom | |
parent | e1a16b18ee0271bbad754d889a1455fc2e8b1d6d (diff) | |
download | website-c4d5654e6360e90be2106439463f49acb55dffc8.tar.lz website-c4d5654e6360e90be2106439463f49acb55dffc8.tar.zst website-c4d5654e6360e90be2106439463f49acb55dffc8.zip |
use encoding/xml for atom feeds
Diffstat (limited to 'internal/atom')
-rw-r--r-- | internal/atom/atom.go | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/internal/atom/atom.go b/internal/atom/atom.go index 601c125..f75d18a 100644 --- a/internal/atom/atom.go +++ b/internal/atom/atom.go @@ -1,7 +1,9 @@ package atom import ( + "bytes" "encoding/xml" + "net/url" "time" "go.alanpearce.eu/website/internal/config" @@ -11,18 +13,35 @@ func MakeTagURI(config *config.Config, specific string) string { return "tag:" + config.OriginalDomain + "," + config.DomainStartDate + ":" + specific } +func LinkXSL(w *bytes.Buffer, url string) error { + _, err := w.WriteString(`<?xml-stylesheet href="`) + if err != nil { + return err + } + err = xml.EscapeText(w, []byte(url)) + if err != nil { + return err + } + _, err = w.WriteString(`" type="text/xsl"?>`) + if err != nil { + return err + } + + return nil +} + type Link struct { XMLName xml.Name `xml:"link"` - Rel string `xml:"rel,attr"` - Type string `xml:"type,attr"` + Rel string `xml:"rel,attr,omitempty"` + Type string `xml:"type,attr,omitempty"` Href string `xml:"href,attr"` } -func MakeLink(url string) Link { +func MakeLink(url *url.URL) Link { return Link{ Rel: "alternate", Type: "text/html", - Href: url, + Href: url.String(), } } @@ -41,3 +60,12 @@ type FeedEntry struct { Content FeedContent `xml:"content"` Author string `xml:"author>name"` } + +type Feed struct { + XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"` + Title string `xml:"title"` + Link Link `xml:"link"` + ID string `xml:"id"` + Updated time.Time `xml:"updated"` + Entries []*FeedEntry `xml:"entry"` +} |