use webs/rss now
Ted Unangst tedu@tedunangst.com
Sat, 04 May 2019 22:56:58 -0400
M
go.mod
→
go.mod
@@ -6,5 +6,5 @@ github.com/mattn/go-runewidth v0.0.4
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 humungus.tedunangst.com/r/go-sqlite3 v1.1.2 - humungus.tedunangst.com/r/webs v0.3.0 + humungus.tedunangst.com/r/webs v0.4.0 )
M
go.sum
→
go.sum
@@ -12,5 +12,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= humungus.tedunangst.com/r/go-sqlite3 v1.1.2 h1:bRAXNRZ4VNFRFhhG4tdudK4Lv4ktHQAHEppKlDANUFg= humungus.tedunangst.com/r/go-sqlite3 v1.1.2/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M= -humungus.tedunangst.com/r/webs v0.3.0 h1:Igx471E1Rabh5BIkVJw9N48xGNEHENx05r/7lOBJRUs= -humungus.tedunangst.com/r/webs v0.3.0/go.mod h1:6yLLDXBaE4pKURa/3/bxoQPod37uAqc/Kq8J0IopWW0= +humungus.tedunangst.com/r/webs v0.4.0 h1:X+CC6+YVSiK7038GTX5X/HvHUFOjEQ0NGgbDT4xNwZg= +humungus.tedunangst.com/r/webs v0.4.0/go.mod h1:6yLLDXBaE4pKURa/3/bxoQPod37uAqc/Kq8J0IopWW0=
M
honk.go
→
honk.go
@@ -37,6 +37,7 @@
"github.com/gorilla/mux" "humungus.tedunangst.com/r/webs/image" "humungus.tedunangst.com/r/webs/login" + "humungus.tedunangst.com/r/webs/rss" "humungus.tedunangst.com/r/webs/templates" )@@ -166,11 +167,11 @@ if name != "" {
home += "u/" + name name += " " } - feed := RssFeed{ + feed := rss.Feed{ Title: name + "honk", Link: home, Description: name + "honk rss", - FeedImage: &RssFeedImage{ + Image: &rss.Image{ URL: base + "icon.png", Title: name + "honk rss", Link: home,@@ -184,9 +185,9 @@ desc += fmt.Sprintf(`<p><a href="%sd/%s">Attachment: %s</a>`,
base, d.XID, html.EscapeString(d.Name)) } - feed.Items = append(feed.Items, &RssItem{ + feed.Items = append(feed.Items, &rss.Item{ Title: fmt.Sprintf("%s %s %s", honk.Username, honk.What, honk.XID), - Description: RssCData{desc}, + Description: rss.CData{desc}, Link: honk.URL, PubDate: honk.Date.Format(time.RFC1123), })
D
rss.go
@@ -1,65 +0,0 @@
-// -// Copyright (c) 2018 Ted Unangst <tedu@tedunangst.com> -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -package main - -import ( - "encoding/xml" - "io" -) - -type Rss struct { - XMLName xml.Name `xml:"rss"` - Version string `xml:"version,attr"` - Feed *RssFeed -} - -type RssFeed struct { - XMLName xml.Name `xml:"channel"` - Title string `xml:"title"` - Link string `xml:"link"` - Description string `xml:"description"` - FeedImage *RssFeedImage - Items []*RssItem -} - -type RssFeedImage struct { - XMLName xml.Name `xml:"image"` - URL string `xml:"url"` - Title string `xml:"title"` - Link string `xml:"link"` -} - -type RssItem struct { - XMLName xml.Name `xml:"item"` - Title string `xml:"title"` - Description RssCData `xml:"description"` - Link string `xml:"link"` - PubDate string `xml:"pubDate"` -} - -type RssCData struct { - Data string `xml:",cdata"` -} - -func (fd *RssFeed) Write(w io.Writer) error { - r := Rss{Version: "2.0", Feed: fd} - io.WriteString(w, xml.Header) - enc := xml.NewEncoder(w) - enc.Indent("", " ") - err := enc.Encode(r) - io.WriteString(w, "\n") - return err -}