diff options
author | knotteye <knotteye@airmail.cc> | 2021-07-01 20:26:49 -0500 |
---|---|---|
committer | knotteye <knotteye@airmail.cc> | 2021-07-01 20:26:49 -0500 |
commit | 168225daa21fe494bcd74ab6c90d6498ecf9f1e3 (patch) | |
tree | 65274dc8181e7c1805fb601f3674f6d357b5dc80 /client.go | |
parent | 4e3848cadbb3fd89b94a7ef24838173939d198db (diff) |
Make news list links to full page news articles
Diffstat (limited to 'client.go')
-rw-r--r-- | client.go | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -8,6 +8,7 @@ import "strings" import "strconv" import "sort" import "regexp" +import "time" var Key *string = new(string) @@ -82,7 +83,7 @@ type NewsItem struct { } func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { - t := template.Must(template.New("").Funcs(template.FuncMap{"mod": func(i, j int) bool { return i%j == 0 }}).ParseFiles("./static/main.html", "./static/index.html")) + t := template.Must(template.New("").Funcs(template.FuncMap{"mod": func(i, j int) bool { return i%j == 0 }, "unixtoreadable": func(u int) string { return time.Unix(int64(u), 0).Format("Jan 02, 2006") }}).ParseFiles("./static/main.html", "./static/index.html")) actor := GetActorFromDB(db, Domain) @@ -103,6 +104,37 @@ func IndexGet(w http.ResponseWriter, r *http.Request, db *sql.DB) { t.ExecuteTemplate(w, "layout", data) } +func NewsGet(w http.ResponseWriter, r *http.Request, db *sql.DB, timestamp int) { + t := template.Must(template.New("").Funcs(template.FuncMap{"unixtoreadable": func(u int) string { return time.Unix(int64(u), 0).Format("Jan 02, 2006") }}).ParseFiles("./static/main.html", "./static/news.html")) + + actor := GetActorFromDB(db, Domain) + + var data PageData + data.PreferredUsername = actor.PreferredUsername + data.Boards = Boards + data.Board.Name = "" + data.Key = *Key + data.Board.Domain = Domain + data.Board.ModCred, _ = GetPasswordFromSession(r) + data.Board.Actor = actor + data.Board.Post.Actor = actor.Id + data.Board.Restricted = actor.Restricted + data.NewsItems = []NewsItem{NewsItem{}} + + var err error + data.NewsItems[0], err = getNewsItemFromDB(db, timestamp) + + if err != nil { + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("404 no path")) + return + } + + data.Title = actor.PreferredUsername + ": " + data.NewsItems[0].Title + + t.ExecuteTemplate(w, "layout", data) +} + func OutboxGet(w http.ResponseWriter, r *http.Request, db *sql.DB, collection Collection){ t := template.Must(template.ParseFiles("./static/main.html", "./static/nposts.html", "./static/top.html", "./static/bottom.html", "./static/posts.html")) |