diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000..255b886 Binary files /dev/null and b/assets/favicon.ico differ diff --git a/assets/style.css b/assets/style.css index a889494..3a60d19 100644 --- a/assets/style.css +++ b/assets/style.css @@ -16,22 +16,6 @@ body { background-color: lightgreen; padding: 0.5em 1em; color: darkgreen; - animation: 500ms ease-out 3s 1 forwards fadeout; -} - -@keyframes fadeout { - 0% { - opacity: 1; - } - 99% { - opacity: 0; - font-size: inherit; - height: inherit; - } - 100% { - font-size: 0; - height: 0; - } } .cols { diff --git a/go.mod b/go.mod index c49097f..574a184 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.16 require ( github.com/fogleman/gg v1.3.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 - github.com/gorilla/feeds v1.1.1 github.com/gorilla/mux v1.8.0 github.com/gorilla/sessions v1.2.1 github.com/kr/pretty v0.3.0 // indirect diff --git a/web/handler/common.go b/web/handler/common.go index 60667e7..bee2441 100644 --- a/web/handler/common.go +++ b/web/handler/common.go @@ -14,9 +14,14 @@ var TplCommonMap = map[string]string{ - status.cafe + {{ template "title" . }}Status Cafe + {{ if .face }} + + {{ else }} + + {{ end }} {{ template "head" . }} @@ -40,7 +45,7 @@ var TplCommonMap = map[string]string{ {{ end }} {{ define "head" }}{{ end }} -`, +{{ define "title" }}{{ end }}`, "status": `{{ define "status" }}
{{ .User }} {{ .Face }} {{ .TimeAgo }}

{{ .Content }}

diff --git a/web/handler/feed_show.go b/web/handler/feed_show.go index 776d10f..6269363 100644 --- a/web/handler/feed_show.go +++ b/web/handler/feed_show.go @@ -2,18 +2,112 @@ package handler import ( "fmt" - "github.com/gorilla/feeds" "net/http" + "status/model" "time" ) +import ( + "encoding/xml" +) + +type Feed struct { + XMLName xml.Name `xml:"http://www.w3.org/2005/Atom feed"` + Title string `xml:"title"` + ID string `xml:"id"` + Link []Link `xml:"link"` + Updated TimeStr `xml:"updated"` + Author *Person `xml:"author"` + Icon string `xml:"icon,omitempty"` + Logo string `xml:"logo,omitempty"` + Subtitle string `xml:"subtitle,omitempty"` + Entry []*Entry `xml:"entry"` +} + +type Entry struct { + Title string `xml:"title"` + ID string `xml:"id"` + Link []Link `xml:"link"` + Published TimeStr `xml:"published"` + Updated TimeStr `xml:"updated"` + Author *Person `xml:"author"` + Summary *Text `xml:"summary"` + Content *Text `xml:"content"` +} + +type Link struct { + Rel string `xml:"rel,attr,omitempty"` + Href string `xml:"href,attr"` + Type string `xml:"type,attr,omitempty"` + HrefLang string `xml:"hreflang,attr,omitempty"` + Title string `xml:"title,attr,omitempty"` + Length uint `xml:"length,attr,omitempty"` +} + +type Person struct { + Name string `xml:"name"` + URI string `xml:"uri,omitempty"` + Email string `xml:"email,omitempty"` + InnerXML string `xml:",innerxml"` +} + +type Text struct { + Type string `xml:"type,attr"` + Body string `xml:",chardata"` +} + +type TimeStr string + +func Time(t time.Time) TimeStr { + return TimeStr(t.Format("2006-01-02T15:04:05-07:00")) +} + +func createAtomEntryFromStatus(status model.Status) *Entry { + return &Entry{ + Title: fmt.Sprintf("%s %s %s", status.User, status.Face, truncate(status.Content, 50)), + ID: fmt.Sprintf("https://status.cafe/users/%s/%d", status.User, status.Id), + //Link: []Link{ + // { + // Rel: "alternate", + // Href: fmt.Sprintf("https://status.cafe/users/%s/%d", status.User, status.Id), + // Type: "text/html", + // }, + //}, + Updated: Time(status.CreatedAt), + Published: Time(status.CreatedAt), + Author: &Person{ + Name: status.User, + URI: fmt.Sprintf("https://status.cafe/users/%s", status.User), + }, + Content: &Text{ + Type: "text", + Body: status.Content, + }, + } +} + func (h *Handler) showFeedView(w http.ResponseWriter, r *http.Request) { - now := time.Now() - feed := &feeds.Feed{ - Title: "status.cafe", - Link: &feeds.Link{Href: "https://status.cafe/"}, - Author: &feeds.Author{Name: "status.cafe"}, - Created: now, + feed := Feed{ + Title: "status.cafe", + ID: "https://status.cafe/", + Subtitle: "Your friends' updates", + Icon: "/assets/icon.png", + Author: &Person{ + Name: "status.cafe", + URI: "https://status.cafe", + }, + Updated: Time(time.Now()), + Link: []Link{ + { + Rel: "self", + Href: "https://status.cafe/feed.atom", + }, + { + Rel: "alternate", + Type: "text/html", + Href: "https://status.cafe", + }, + }, } statuses, err := h.storage.StatusFeed() @@ -23,25 +117,15 @@ func (h *Handler) showFeedView(w http.ResponseWriter, r *http.Request) { } for _, status := range statuses { - if err != nil { - serverError(w, err) - return - } - feed.Items = append(feed.Items, &feeds.Item{ - Title: fmt.Sprintf("%s %s %s", status.User, status.Face, truncate(status.Content, 50)), - Link: &feeds.Link{Href: fmt.Sprintf("https://status.cafe/users/%s/%d", status.User, status.Id)}, - Author: &feeds.Author{Name: status.User}, - Content: status.Content, - Created: status.CreatedAt, - }) - } - atom, err := feed.ToAtom() - if err != nil { - serverError(w, err) - return + feed.Entry = append(feed.Entry, createAtomEntryFromStatus(status)) } w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Content-Type", "application/atom+xml") - w.Write([]byte(atom)) + var data []byte + data, err = xml.MarshalIndent(&feed, "", " ") + if err != nil { + serverError(w, err) + } + w.Write([]byte(xml.Header + string(data))) } diff --git a/web/handler/html.go b/web/handler/html.go index 3f34e40..d7f80da 100644 --- a/web/handler/html.go +++ b/web/handler/html.go @@ -154,7 +154,6 @@ var TplMap = map[string]string{ {{ if .form.Error }}

{{ .form.Error }}

{{ end }} - {{ template "flash" .flash }}
{{ template "status_form" .status }}