use webs/rss now
This commit is contained in:
parent
af849f4371
commit
a9d5bb35e9
2
go.mod
2
go.mod
|
@ -6,5 +6,5 @@ require (
|
||||||
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d
|
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
|
||||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.2
|
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
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -12,5 +12,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
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 h1:bRAXNRZ4VNFRFhhG4tdudK4Lv4ktHQAHEppKlDANUFg=
|
||||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.2/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M=
|
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.4.0 h1:X+CC6+YVSiK7038GTX5X/HvHUFOjEQ0NGgbDT4xNwZg=
|
||||||
humungus.tedunangst.com/r/webs v0.3.0/go.mod h1:6yLLDXBaE4pKURa/3/bxoQPod37uAqc/Kq8J0IopWW0=
|
humungus.tedunangst.com/r/webs v0.4.0/go.mod h1:6yLLDXBaE4pKURa/3/bxoQPod37uAqc/Kq8J0IopWW0=
|
||||||
|
|
9
honk.go
9
honk.go
|
@ -37,6 +37,7 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"humungus.tedunangst.com/r/webs/image"
|
"humungus.tedunangst.com/r/webs/image"
|
||||||
"humungus.tedunangst.com/r/webs/login"
|
"humungus.tedunangst.com/r/webs/login"
|
||||||
|
"humungus.tedunangst.com/r/webs/rss"
|
||||||
"humungus.tedunangst.com/r/webs/templates"
|
"humungus.tedunangst.com/r/webs/templates"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -166,11 +167,11 @@ func showrss(w http.ResponseWriter, r *http.Request) {
|
||||||
home += "u/" + name
|
home += "u/" + name
|
||||||
name += " "
|
name += " "
|
||||||
}
|
}
|
||||||
feed := RssFeed{
|
feed := rss.Feed{
|
||||||
Title: name + "honk",
|
Title: name + "honk",
|
||||||
Link: home,
|
Link: home,
|
||||||
Description: name + "honk rss",
|
Description: name + "honk rss",
|
||||||
FeedImage: &RssFeedImage{
|
Image: &rss.Image{
|
||||||
URL: base + "icon.png",
|
URL: base + "icon.png",
|
||||||
Title: name + "honk rss",
|
Title: name + "honk rss",
|
||||||
Link: home,
|
Link: home,
|
||||||
|
@ -184,9 +185,9 @@ func showrss(w http.ResponseWriter, r *http.Request) {
|
||||||
base, d.XID, html.EscapeString(d.Name))
|
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),
|
Title: fmt.Sprintf("%s %s %s", honk.Username, honk.What, honk.XID),
|
||||||
Description: RssCData{desc},
|
Description: rss.CData{desc},
|
||||||
Link: honk.URL,
|
Link: honk.URL,
|
||||||
PubDate: honk.Date.Format(time.RFC1123),
|
PubDate: honk.Date.Format(time.RFC1123),
|
||||||
})
|
})
|
||||||
|
|
65
rss.go
65
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
|
|
||||||
}
|
|
Loading…
Reference in New Issue