From 79d73d12f538309849a9c1d88028e513c6277d29 Mon Sep 17 00:00:00 2001
From: m15o
Date: Tue, 14 Dec 2021 07:41:05 +0100
Subject: [PATCH] various changes
---
assets/favicon.ico | Bin 0 -> 132 bytes
assets/style.css | 16 ----
go.mod | 1 -
web/handler/common.go | 9 +-
web/handler/feed_show.go | 132 ++++++++++++++++++++++-----
web/handler/html.go | 5 +-
web/handler/html/common/layout.html | 8 +-
web/handler/html/index.html | 1 -
web/handler/html/status-updater.html | 2 +-
web/handler/html/user.html | 2 +
web/handler/tpl.go | 2 +-
web/handler/user_show.go | 62 +++++++------
12 files changed, 163 insertions(+), 77 deletions(-)
create mode 100644 assets/favicon.ico
diff --git a/assets/favicon.ico b/assets/favicon.ico
new file mode 100644
index 0000000000000000000000000000000000000000..255b88649ec11eeb2bc4f7cb7e9f8a2f660509fb
GIT binary patch
literal 132
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`-kvUwAr`&KKR*2bU+-nWyvt$J
z>T~~7!evFwjE-e8m>vCL@Rb)N`G1>*^df_E1`-v_@9yq(6_GP#=w}o;&ScmoaK=YO
d+ChtrK{efU+DrDGHb7$;JYD@<);T3K0RXuqEMEWs
literal 0
HcmV?d00001
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" }}
{{ .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 }}
- status updater
+ status updater
That's it! From now on, whenever you want to update your status, click the status updater button from your bookmarks and a pop-up window will launch to let you update it.
@@ -378,6 +377,8 @@ var TplMap = map[string]string{
{{ end }}
+{{ define "title" }}{{ .user }} - {{ end }}
+
{{ define "content" }}
diff --git a/web/handler/html/common/layout.html b/web/handler/html/common/layout.html
index 25502e7..1fefffb 100644
--- a/web/handler/html/common/layout.html
+++ b/web/handler/html/common/layout.html
@@ -4,9 +4,14 @@
- status.cafe
+ {{ template "title" . }}Status Cafe
+ {{ if .face }}
+
+ {{ else }}
+
+ {{ end }}
{{ template "head" . }}
@@ -30,3 +35,4 @@
{{ end }}
{{ define "head" }}{{ end }}
+{{ define "title" }}{{ end }}
\ No newline at end of file
diff --git a/web/handler/html/index.html b/web/handler/html/index.html
index bce78f9..2a4405e 100644
--- a/web/handler/html/index.html
+++ b/web/handler/html/index.html
@@ -6,7 +6,6 @@
{{ if .form.Error }}
{{ .form.Error }}
{{ end }}
- {{ template "flash" .flash }}
diff --git a/web/handler/html/user.html b/web/handler/html/user.html
index d9d37a9..1fdd4af 100644
--- a/web/handler/html/user.html
+++ b/web/handler/html/user.html
@@ -2,6 +2,8 @@
{{ end }}
+{{ define "title" }}{{ .user }} - {{ end }}
+
{{ define "content" }}
diff --git a/web/handler/tpl.go b/web/handler/tpl.go
index 8cb7856..9c9ccdd 100644
--- a/web/handler/tpl.go
+++ b/web/handler/tpl.go
@@ -16,7 +16,7 @@ func (h *Handler) initTpl() {
for name, content := range TplMap {
views[name] = template.Must(template.New("main").Funcs(template.FuncMap{
"faces": func() []string {
- return []string{"🙂", "😎", "😛", "🥰", "👽", "😱", "🤔", "😯", "🤒", "😡", "🥺", "🥳", "🤖", "💀", "😴", "😭", "☕", "🍺", "📖", "🔥", "❄️", "✨", "💡", "🎼"}
+ return []string{"🙂", "😎", "😛", "🥰", "❤️", "👽", "😱", "🤔", "😯", "🤒", "😡", "🥺", "🥳", "🤖", "💀", "😴", "😭", "🤐", "🤢", "👀", "☕", "🍺", "📖", "🔥", "❄️", "✨", "💡", "🎶", "✈️", "🚄", "🍿", "📰", "✏️", "🍱", "🎄", "🎁", "🌧️", "🌙", "🎨", "📺", "🍕", "✅"}
}}).Parse(commonTemplates + content))
}
}
diff --git a/web/handler/user_show.go b/web/handler/user_show.go
index 78ceb98..facf25a 100644
--- a/web/handler/user_show.go
+++ b/web/handler/user_show.go
@@ -2,11 +2,11 @@ package handler
import (
"encoding/json"
+ "encoding/xml"
"fmt"
"github.com/fogleman/gg"
"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
- "github.com/gorilla/feeds"
"github.com/gorilla/mux"
"golang.org/x/image/font"
"golang.org/x/image/font/gofont/goregular"
@@ -75,9 +75,14 @@ func (h *Handler) showUserView(w http.ResponseWriter, r *http.Request) {
serverError(w, err)
return
}
+ face := ""
+ if len(statuses) > 0 {
+ face = statuses[0].Face
+ }
h.renderLayout(w, "user", map[string]interface{}{
"user": username,
"statuses": statuses,
+ "face": face,
"homepage": user.Homepage,
"about": template.HTML(user.About),
"picture": user.Picture,
@@ -282,41 +287,42 @@ func (h *Handler) showAtomView(w http.ResponseWriter, r *http.Request) {
notFound(w)
return
}
-
- now := time.Now()
- feed := &feeds.Feed{
- Title: user.Name,
- Link: &feeds.Link{Href: fmt.Sprintf("https://status.cafe/users/%s", username)}, // TODO change the scheme?
- Author: &feeds.Author{Name: user.Name, Email: "todo@todo.com"}, // TODO EMAIL
- Created: now,
+ feed := Feed{
+ Title: user.Name,
+ ID: fmt.Sprintf("https://status.cafe/users/%s/", user.Name),
+ Author: &Person{
+ Name: user.Name,
+ URI: fmt.Sprintf("https://status.cafe/users/%s", user.Name),
+ },
+ Updated: Time(time.Now()),
+ Link: []Link{
+ {
+ Rel: "self",
+ Href: fmt.Sprintf("https://status.cafe/users/%s.atom", user.Name),
+ },
+ {
+ Rel: "alternate",
+ Href: fmt.Sprintf("https://status.cafe/users/%s", user.Name),
+ Type: "text/html",
+ },
+ },
+ Icon: user.Picture,
+ Logo: user.Picture,
}
-
statuses, _, err := h.storage.StatusByUsername(user.Name, 20, 0)
if err != nil {
serverError(w, err)
return
}
-
for _, status := range statuses {
- if err != nil {
- serverError(w, err)
- return
- }
- feed.Items = append(feed.Items, &feeds.Item{
- Title: fmt.Sprintf("%s - %s", status.User, truncate(status.Content, 50)),
- Link: &feeds.Link{Href: fmt.Sprintf("https://status.cafe/users/%s/%d", username, status.Id)},
- Author: &feeds.Author{Name: user.Name},
- Content: status.Content,
- Created: status.CreatedAt,
- })
+ feed.Entry = append(feed.Entry, createAtomEntryFromStatus(status))
}
- atom, err := feed.ToAtom()
- if err != nil {
- serverError(w, err)
- return
- }
-
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)))
}