Refactor renderer and templates

This commit is contained in:
r 2020-01-14 16:57:16 +00:00
parent 3c6653a77b
commit 55987a4c1b
27 changed files with 262 additions and 242 deletions

View File

@ -54,10 +54,7 @@ type Status struct {
ShowReplies bool `json:"show_replies"` ShowReplies bool `json:"show_replies"`
ReplyMap map[string][]ReplyInfo `json:"reply_map"` ReplyMap map[string][]ReplyInfo `json:"reply_map"`
ReplyNumber int `json:"reply_number"` ReplyNumber int `json:"reply_number"`
ThreadInNewTab bool `json:"thread_in_new_tab"`
MaskNSFW bool `json:"mask_nsfw"`
RetweetedByID string `json:"retweeted_by_id"` RetweetedByID string `json:"retweeted_by_id"`
DarkMode bool `json:"dark_mode"`
} }
// Context hold information for mastodon context. // Context hold information for mastodon context.

View File

@ -5,12 +5,17 @@ import (
"mastodon" "mastodon"
) )
type Context struct {
MaskNSFW bool
FluorideMode bool
ThreadInNewTab bool
DarkMode bool
}
type HeaderData struct { type HeaderData struct {
Title string Title string
NotificationCount int NotificationCount int
CustomCSS string CustomCSS string
FluorideMode bool
DarkMode bool
} }
type NavbarData struct { type NavbarData struct {

View File

@ -1,7 +1,6 @@
package renderer package renderer
import ( import (
"context"
"io" "io"
"strconv" "strconv"
"strings" "strings"
@ -44,22 +43,26 @@ var (
} }
) )
type TemplateData struct {
Data interface{}
Ctx *Context
}
type Renderer interface { type Renderer interface {
RenderErrorPage(ctx context.Context, writer io.Writer, data *ErrorData) RenderSigninPage(ctx *Context, writer io.Writer, data *SigninData) (err error)
RenderHomePage(ctx context.Context, writer io.Writer, data *HomePageData) (err error) RenderErrorPage(ctx *Context, writer io.Writer, data *ErrorData)
RenderSigninPage(ctx context.Context, writer io.Writer, data *SigninData) (err error) RenderTimelinePage(ctx *Context, writer io.Writer, data *TimelineData) (err error)
RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error) RenderThreadPage(ctx *Context, writer io.Writer, data *ThreadData) (err error)
RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadData) (err error) RenderNotificationPage(ctx *Context, writer io.Writer, data *NotificationData) (err error)
RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationData) (err error) RenderUserPage(ctx *Context, writer io.Writer, data *UserData) (err error)
RenderUserPage(ctx context.Context, writer io.Writer, data *UserData) (err error) RenderAboutPage(ctx *Context, writer io.Writer, data *AboutData) (err error)
RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutData) (err error) RenderEmojiPage(ctx *Context, writer io.Writer, data *EmojiData) (err error)
RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error) RenderLikedByPage(ctx *Context, writer io.Writer, data *LikedByData) (err error)
RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error) RenderRetweetedByPage(ctx *Context, writer io.Writer, data *RetweetedByData) (err error)
RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error) RenderFollowingPage(ctx *Context, writer io.Writer, data *FollowingData) (err error)
RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error) RenderFollowersPage(ctx *Context, writer io.Writer, data *FollowersData) (err error)
RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error) RenderSearchPage(ctx *Context, writer io.Writer, data *SearchData) (err error)
RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error) RenderSettingsPage(ctx *Context, writer io.Writer, data *SettingsData) (err error)
RenderSettingsPage(ctx context.Context, writer io.Writer, data *SettingsData) (err error)
} }
type renderer struct { type renderer struct {
@ -76,6 +79,7 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
"FormatTimeRFC3339": FormatTimeRFC3339, "FormatTimeRFC3339": FormatTimeRFC3339,
"FormatTimeRFC822": FormatTimeRFC822, "FormatTimeRFC822": FormatTimeRFC822,
"GetIcon": GetIcon, "GetIcon": GetIcon,
"WithContext": WithContext,
}).ParseGlob(templateGlobPattern) }).ParseGlob(templateGlobPattern)
if err != nil { if err != nil {
return return
@ -85,65 +89,61 @@ func NewRenderer(templateGlobPattern string) (r *renderer, err error) {
}, nil }, nil
} }
func (r *renderer) RenderErrorPage(ctx context.Context, writer io.Writer, errorData *ErrorData) { func (r *renderer) RenderSigninPage(ctx *Context, writer io.Writer, signinData *SigninData) (err error) {
r.template.ExecuteTemplate(writer, "error.tmpl", errorData) return r.template.ExecuteTemplate(writer, "signin.tmpl", WithContext(signinData, ctx))
}
func (r *renderer) RenderErrorPage(ctx *Context, writer io.Writer, errorData *ErrorData) {
r.template.ExecuteTemplate(writer, "error.tmpl", WithContext(errorData, ctx))
return return
} }
func (r *renderer) RenderHomePage(ctx context.Context, writer io.Writer, homePageData *HomePageData) (err error) { func (r *renderer) RenderTimelinePage(ctx *Context, writer io.Writer, data *TimelineData) (err error) {
return r.template.ExecuteTemplate(writer, "homepage.tmpl", homePageData) return r.template.ExecuteTemplate(writer, "timeline.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderSigninPage(ctx context.Context, writer io.Writer, signinData *SigninData) (err error) { func (r *renderer) RenderThreadPage(ctx *Context, writer io.Writer, data *ThreadData) (err error) {
return r.template.ExecuteTemplate(writer, "signin.tmpl", signinData) return r.template.ExecuteTemplate(writer, "thread.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderTimelinePage(ctx context.Context, writer io.Writer, data *TimelineData) (err error) { func (r *renderer) RenderNotificationPage(ctx *Context, writer io.Writer, data *NotificationData) (err error) {
return r.template.ExecuteTemplate(writer, "timeline.tmpl", data) return r.template.ExecuteTemplate(writer, "notification.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadData) (err error) { func (r *renderer) RenderUserPage(ctx *Context, writer io.Writer, data *UserData) (err error) {
return r.template.ExecuteTemplate(writer, "thread.tmpl", data) return r.template.ExecuteTemplate(writer, "user.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationData) (err error) { func (r *renderer) RenderAboutPage(ctx *Context, writer io.Writer, data *AboutData) (err error) {
return r.template.ExecuteTemplate(writer, "notification.tmpl", data) return r.template.ExecuteTemplate(writer, "about.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderUserPage(ctx context.Context, writer io.Writer, data *UserData) (err error) { func (r *renderer) RenderEmojiPage(ctx *Context, writer io.Writer, data *EmojiData) (err error) {
return r.template.ExecuteTemplate(writer, "user.tmpl", data) return r.template.ExecuteTemplate(writer, "emoji.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutData) (err error) { func (r *renderer) RenderLikedByPage(ctx *Context, writer io.Writer, data *LikedByData) (err error) {
return r.template.ExecuteTemplate(writer, "about.tmpl", data) return r.template.ExecuteTemplate(writer, "likedby.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderEmojiPage(ctx context.Context, writer io.Writer, data *EmojiData) (err error) { func (r *renderer) RenderRetweetedByPage(ctx *Context, writer io.Writer, data *RetweetedByData) (err error) {
return r.template.ExecuteTemplate(writer, "emoji.tmpl", data) return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderLikedByPage(ctx context.Context, writer io.Writer, data *LikedByData) (err error) { func (r *renderer) RenderFollowingPage(ctx *Context, writer io.Writer, data *FollowingData) (err error) {
return r.template.ExecuteTemplate(writer, "likedby.tmpl", data) return r.template.ExecuteTemplate(writer, "following.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderRetweetedByPage(ctx context.Context, writer io.Writer, data *RetweetedByData) (err error) { func (r *renderer) RenderFollowersPage(ctx *Context, writer io.Writer, data *FollowersData) (err error) {
return r.template.ExecuteTemplate(writer, "retweetedby.tmpl", data) return r.template.ExecuteTemplate(writer, "followers.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderFollowingPage(ctx context.Context, writer io.Writer, data *FollowingData) (err error) { func (r *renderer) RenderSearchPage(ctx *Context, writer io.Writer, data *SearchData) (err error) {
return r.template.ExecuteTemplate(writer, "following.tmpl", data) return r.template.ExecuteTemplate(writer, "search.tmpl", WithContext(data, ctx))
} }
func (r *renderer) RenderFollowersPage(ctx context.Context, writer io.Writer, data *FollowersData) (err error) { func (r *renderer) RenderSettingsPage(ctx *Context, writer io.Writer, data *SettingsData) (err error) {
return r.template.ExecuteTemplate(writer, "followers.tmpl", data) return r.template.ExecuteTemplate(writer, "settings.tmpl", WithContext(data, ctx))
}
func (r *renderer) RenderSearchPage(ctx context.Context, writer io.Writer, data *SearchData) (err error) {
return r.template.ExecuteTemplate(writer, "search.tmpl", data)
}
func (r *renderer) RenderSettingsPage(ctx context.Context, writer io.Writer, data *SettingsData) (err error) {
return r.template.ExecuteTemplate(writer, "settings.tmpl", data)
} }
func EmojiFilter(content string, emojis []mastodon.Emoji) string { func EmojiFilter(content string, emojis []mastodon.Emoji) string {
@ -222,3 +222,7 @@ func GetIcon(name string, darkMode bool) (icon string) {
icon, _ = icons[name] icon, _ = icons[name]
return return
} }
func WithContext(data interface{}, ctx *Context) TemplateData {
return TemplateData{data, ctx}
}

View File

@ -73,12 +73,9 @@ func (s *authService) GetUserToken(ctx context.Context, sessionID string, c *mod
return return
} }
func (s *authService) ServeHomePage(ctx context.Context, client io.Writer) (err error) { func (s *authService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
return s.Service.ServeHomePage(ctx, client) c, _ = s.getClient(ctx)
} s.Service.ServeErrorPage(ctx, client, c, err)
func (s *authService) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
s.Service.ServeErrorPage(ctx, client, err)
} }
func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) { func (s *authService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {

View File

@ -37,20 +37,12 @@ func (s *loggingService) GetUserToken(ctx context.Context, sessionID string, c *
return s.Service.GetUserToken(ctx, sessionID, c, code) return s.Service.GetUserToken(ctx, sessionID, c, code)
} }
func (s *loggingService) ServeHomePage(ctx context.Context, client io.Writer) (err error) { func (s *loggingService) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeHomePage", time.Since(begin), err)
}(time.Now())
return s.Service.ServeHomePage(ctx, client)
}
func (s *loggingService) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
defer func(begin time.Time) { defer func(begin time.Time) {
s.logger.Printf("method=%v, err=%v, took=%v\n", s.logger.Printf("method=%v, err=%v, took=%v\n",
"ServeErrorPage", err, time.Since(begin)) "ServeErrorPage", err, time.Since(begin))
}(time.Now()) }(time.Now())
s.Service.ServeErrorPage(ctx, client, err) s.Service.ServeErrorPage(ctx, client, c, err)
} }
func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) { func (s *loggingService) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {

View File

@ -26,10 +26,9 @@ var (
) )
type Service interface { type Service interface {
ServeHomePage(ctx context.Context, client io.Writer) (err error)
GetAuthUrl(ctx context.Context, instance string) (url string, sessionID string, err error) GetAuthUrl(ctx context.Context, instance string) (url string, sessionID string, err error)
GetUserToken(ctx context.Context, sessionID string, c *model.Client, token string) (accessToken string, err error) GetUserToken(ctx context.Context, sessionID string, c *model.Client, token string) (accessToken string, err error)
ServeErrorPage(ctx context.Context, client io.Writer, err error) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error)
ServeSigninPage(ctx context.Context, client io.Writer) (err error) ServeSigninPage(ctx context.Context, client io.Writer) (err error)
ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error) ServeTimelinePage(ctx context.Context, client io.Writer, c *model.Client, timelineType string, maxID string, sinceID string, minID string) (err error)
ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error) ServeThreadPage(ctx context.Context, client io.Writer, c *model.Client, id string, reply bool) (err error)
@ -79,6 +78,15 @@ func NewService(clientName string, clientScope string, clientWebsite string,
} }
} }
func getRendererContext(s model.Settings) *renderer.Context {
return &renderer.Context{
MaskNSFW: s.MaskNSFW,
ThreadInNewTab: s.ThreadInNewTab,
FluorideMode: s.FluorideMode,
DarkMode: s.DarkMode,
}
}
func (svc *service) GetAuthUrl(ctx context.Context, instance string) ( func (svc *service) GetAuthUrl(ctx context.Context, instance string) (
redirectUrl string, sessionID string, err error) { redirectUrl string, sessionID string, err error) {
var instanceURL string var instanceURL string
@ -202,20 +210,7 @@ func (svc *service) GetUserToken(ctx context.Context, sessionID string, c *model
return res.AccessToken, nil return res.AccessToken, nil
} }
func (svc *service) ServeHomePage(ctx context.Context, client io.Writer) (err error) { func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, c *model.Client, err error) {
commonData, err := svc.getCommonData(ctx, client, nil, "home")
if err != nil {
return
}
data := &renderer.HomePageData{
CommonData: commonData,
}
return svc.renderer.RenderHomePage(ctx, client, data)
}
func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err error) {
var errStr string var errStr string
if err != nil { if err != nil {
errStr = err.Error() errStr = err.Error()
@ -231,7 +226,15 @@ func (svc *service) ServeErrorPage(ctx context.Context, client io.Writer, err er
Error: errStr, Error: errStr,
} }
svc.renderer.RenderErrorPage(ctx, client, data) var s model.Settings
if c != nil {
s = c.Session.Settings
} else {
s = *model.NewSettings()
}
rCtx := getRendererContext(s)
svc.renderer.RenderErrorPage(rCtx, client, data)
} }
func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) { func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err error) {
@ -244,7 +247,8 @@ func (svc *service) ServeSigninPage(ctx context.Context, client io.Writer) (err
CommonData: commonData, CommonData: commonData,
} }
return svc.renderer.RenderSigninPage(ctx, client, data) rCtx := getRendererContext(*model.NewSettings())
return svc.renderer.RenderSigninPage(rCtx, client, data)
} }
func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer, func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
@ -279,14 +283,8 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
} }
for i := range statuses { for i := range statuses {
statuses[i].ThreadInNewTab = c.Session.Settings.ThreadInNewTab
statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
statuses[i].DarkMode = c.Session.Settings.DarkMode
if statuses[i].Reblog != nil { if statuses[i].Reblog != nil {
statuses[i].Reblog.RetweetedByID = statuses[i].ID statuses[i].Reblog.RetweetedByID = statuses[i].ID
statuses[i].Reblog.ThreadInNewTab = c.Session.Settings.ThreadInNewTab
statuses[i].Reblog.MaskNSFW = c.Session.Settings.MaskNSFW
statuses[i].Reblog.DarkMode = c.Session.Settings.DarkMode
} }
} }
@ -319,7 +317,6 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
postContext := model.PostContext{ postContext := model.PostContext{
DefaultVisibility: c.Session.Settings.DefaultVisibility, DefaultVisibility: c.Session.Settings.DefaultVisibility,
Formats: svc.postFormats, Formats: svc.postFormats,
DarkMode: c.Session.Settings.DarkMode,
} }
commonData, err := svc.getCommonData(ctx, client, c, timelineType+" timeline ") commonData, err := svc.getCommonData(ctx, client, c, timelineType+" timeline ")
@ -337,8 +334,9 @@ func (svc *service) ServeTimelinePage(ctx context.Context, client io.Writer,
PostContext: postContext, PostContext: postContext,
CommonData: commonData, CommonData: commonData,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderTimelinePage(ctx, client, data) err = svc.renderer.RenderTimelinePage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -404,8 +402,6 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *mo
for i := range statuses { for i := range statuses {
statuses[i].ShowReplies = true statuses[i].ShowReplies = true
statuses[i].ReplyMap = replyMap statuses[i].ReplyMap = replyMap
statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
statuses[i].DarkMode = c.Session.Settings.DarkMode
addToReplyMap(replyMap, statuses[i].InReplyToID, statuses[i].ID, i+1) addToReplyMap(replyMap, statuses[i].InReplyToID, statuses[i].ID, i+1)
} }
@ -420,8 +416,9 @@ func (svc *service) ServeThreadPage(ctx context.Context, client io.Writer, c *mo
ReplyMap: replyMap, ReplyMap: replyMap,
CommonData: commonData, CommonData: commonData,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderThreadPage(ctx, client, data) err = svc.renderer.RenderThreadPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -448,8 +445,6 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
for i := range notifications { for i := range notifications {
if notifications[i].Status != nil { if notifications[i].Status != nil {
notifications[i].Status.CreatedAt = notifications[i].CreatedAt notifications[i].Status.CreatedAt = notifications[i].CreatedAt
notifications[i].Status.MaskNSFW = c.Session.Settings.MaskNSFW
notifications[i].Status.DarkMode = c.Session.Settings.DarkMode
switch notifications[i].Type { switch notifications[i].Type {
case "reblog", "favourite": case "reblog", "favourite":
notifications[i].Status.HideAccountInfo = true notifications[i].Status.HideAccountInfo = true
@ -482,9 +477,10 @@ func (svc *service) ServeNotificationPage(ctx context.Context, client io.Writer,
HasNext: hasNext, HasNext: hasNext,
NextLink: nextLink, NextLink: nextLink,
CommonData: commonData, CommonData: commonData,
DarkMode: c.Session.Settings.DarkMode,
} }
err = svc.renderer.RenderNotificationPage(ctx, client, data) rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderNotificationPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -512,15 +508,6 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mode
return return
} }
for i := range statuses {
statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
statuses[i].DarkMode = c.Session.Settings.DarkMode
if statuses[i].Reblog != nil {
statuses[i].Reblog.MaskNSFW = c.Session.Settings.MaskNSFW
statuses[i].Reblog.DarkMode = c.Session.Settings.DarkMode
}
}
if len(pg.MaxID) > 0 { if len(pg.MaxID) > 0 {
hasNext = true hasNext = true
nextLink = "/user/" + id + "?max_id=" + pg.MaxID nextLink = "/user/" + id + "?max_id=" + pg.MaxID
@ -537,10 +524,10 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mode
HasNext: hasNext, HasNext: hasNext,
NextLink: nextLink, NextLink: nextLink,
CommonData: commonData, CommonData: commonData,
DarkMode: c.Session.Settings.DarkMode,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderUserPage(ctx, client, data) err = svc.renderer.RenderUserPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -557,7 +544,9 @@ func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mod
data := &renderer.AboutData{ data := &renderer.AboutData{
CommonData: commonData, CommonData: commonData,
} }
err = svc.renderer.RenderAboutPage(ctx, client, data) rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderAboutPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -580,8 +569,9 @@ func (svc *service) ServeEmojiPage(ctx context.Context, client io.Writer, c *mod
Emojis: emojis, Emojis: emojis,
CommonData: commonData, CommonData: commonData,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderEmojiPage(ctx, client, data) err = svc.renderer.RenderEmojiPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -604,8 +594,9 @@ func (svc *service) ServeLikedByPage(ctx context.Context, client io.Writer, c *m
CommonData: commonData, CommonData: commonData,
Users: likers, Users: likers,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderLikedByPage(ctx, client, data) err = svc.renderer.RenderLikedByPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -628,8 +619,9 @@ func (svc *service) ServeRetweetedByPage(ctx context.Context, client io.Writer,
CommonData: commonData, CommonData: commonData,
Users: retweeters, Users: retweeters,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderRetweetedByPage(ctx, client, data) err = svc.renderer.RenderRetweetedByPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -668,8 +660,9 @@ func (svc *service) ServeFollowingPage(ctx context.Context, client io.Writer, c
HasNext: hasNext, HasNext: hasNext,
NextLink: nextLink, NextLink: nextLink,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderFollowingPage(ctx, client, data) err = svc.renderer.RenderFollowingPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -708,8 +701,9 @@ func (svc *service) ServeFollowersPage(ctx context.Context, client io.Writer, c
HasNext: hasNext, HasNext: hasNext,
NextLink: nextLink, NextLink: nextLink,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderFollowersPage(ctx, client, data) err = svc.renderer.RenderFollowersPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -731,11 +725,6 @@ func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *mo
hasNext = len(results.Accounts) == 20 hasNext = len(results.Accounts) == 20
case "statuses": case "statuses":
hasNext = len(results.Statuses) == 20 hasNext = len(results.Statuses) == 20
for i := range results.Statuses {
results.Statuses[i].MaskNSFW = c.Session.Settings.MaskNSFW
results.Statuses[i].DarkMode = c.Session.Settings.DarkMode
}
} }
if hasNext { if hasNext {
@ -761,8 +750,9 @@ func (svc *service) ServeSearchPage(ctx context.Context, client io.Writer, c *mo
HasNext: hasNext, HasNext: hasNext,
NextLink: nextLink, NextLink: nextLink,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderSearchPage(ctx, client, data) err = svc.renderer.RenderSearchPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -780,8 +770,9 @@ func (svc *service) ServeSettingsPage(ctx context.Context, client io.Writer, c *
CommonData: commonData, CommonData: commonData,
Settings: &c.Session.Settings, Settings: &c.Session.Settings,
} }
rCtx := getRendererContext(c.Session.Settings)
err = svc.renderer.RenderSettingsPage(ctx, client, data) err = svc.renderer.RenderSettingsPage(rCtx, client, data)
if err != nil { if err != nil {
return return
} }
@ -837,8 +828,6 @@ func (svc *service) getCommonData(ctx context.Context, client io.Writer, c *mode
} }
data.HeaderData.NotificationCount = notificationCount data.HeaderData.NotificationCount = notificationCount
data.HeaderData.FluorideMode = c.Session.Settings.FluorideMode
data.HeaderData.DarkMode = c.Session.Settings.DarkMode
} }
return return

View File

@ -41,7 +41,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) { r.HandleFunc("/signin", func(w http.ResponseWriter, req *http.Request) {
err := s.ServeSigninPage(ctx, w) err := s.ServeSigninPage(ctx, w)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -50,7 +50,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
instance := req.FormValue("instance") instance := req.FormValue("instance")
url, sessionID, err := s.GetAuthUrl(ctx, instance) url, sessionID, err := s.GetAuthUrl(ctx, instance)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -69,7 +69,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
token := req.URL.Query().Get("code") token := req.URL.Query().Get("code")
_, err := s.GetUserToken(ctx, "", nil, token) _, err := s.GetUserToken(ctx, "", nil, token)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -92,7 +92,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeTimelinePage(ctx, w, nil, timelineType, maxID, sinceID, minID) err := s.ServeTimelinePage(ctx, w, nil, timelineType, maxID, sinceID, minID)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -103,7 +103,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
reply := req.URL.Query().Get("reply") reply := req.URL.Query().Get("reply")
err := s.ServeThreadPage(ctx, w, nil, id, len(reply) > 1) err := s.ServeThreadPage(ctx, w, nil, id, len(reply) > 1)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -114,7 +114,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeLikedByPage(ctx, w, nil, id) err := s.ServeLikedByPage(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -125,7 +125,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeRetweetedByPage(ctx, w, nil, id) err := s.ServeRetweetedByPage(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -139,7 +139,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeFollowingPage(ctx, w, nil, id, maxID, minID) err := s.ServeFollowingPage(ctx, w, nil, id, maxID, minID)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -153,7 +153,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeFollowersPage(ctx, w, nil, id, maxID, minID) err := s.ServeFollowersPage(ctx, w, nil, id, maxID, minID)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -165,7 +165,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
_, err := s.Like(ctx, w, nil, id) _, err := s.Like(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -184,7 +184,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
_, err := s.UnLike(ctx, w, nil, id) _, err := s.UnLike(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -203,7 +203,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
_, err := s.Retweet(ctx, w, nil, id) _, err := s.Retweet(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -222,7 +222,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
_, err := s.UnRetweet(ctx, w, nil, id) _, err := s.UnRetweet(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -239,13 +239,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
id, _ := mux.Vars(req)["id"] id, _ := mux.Vars(req)["id"]
count, err := s.Like(ctx, w, nil, id) count, err := s.Like(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
err = serveJson(w, count) err = serveJson(w, count)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodPost) }).Methods(http.MethodPost)
@ -255,13 +255,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
id, _ := mux.Vars(req)["id"] id, _ := mux.Vars(req)["id"]
count, err := s.UnLike(ctx, w, nil, id) count, err := s.UnLike(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
err = serveJson(w, count) err = serveJson(w, count)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodPost) }).Methods(http.MethodPost)
@ -271,13 +271,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
id, _ := mux.Vars(req)["id"] id, _ := mux.Vars(req)["id"]
count, err := s.Retweet(ctx, w, nil, id) count, err := s.Retweet(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
err = serveJson(w, count) err = serveJson(w, count)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodPost) }).Methods(http.MethodPost)
@ -287,13 +287,13 @@ func NewHandler(s Service, staticDir string) http.Handler {
id, _ := mux.Vars(req)["id"] id, _ := mux.Vars(req)["id"]
count, err := s.UnRetweet(ctx, w, nil, id) count, err := s.UnRetweet(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
err = serveJson(w, count) err = serveJson(w, count)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodPost) }).Methods(http.MethodPost)
@ -303,7 +303,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := req.ParseMultipartForm(4 << 20) err := req.ParseMultipartForm(4 << 20)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -317,7 +317,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
id, err := s.PostTweet(ctx, w, nil, content, replyToID, format, visibility, isNSFW, files) id, err := s.PostTweet(ctx, w, nil, content, replyToID, format, visibility, isNSFW, files)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -337,7 +337,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeNotificationPage(ctx, w, nil, maxID, minID) err := s.ServeNotificationPage(ctx, w, nil, maxID, minID)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -351,7 +351,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeUserPage(ctx, w, nil, id, maxID, minID) err := s.ServeUserPage(ctx, w, nil, id, maxID, minID)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -363,7 +363,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.Follow(ctx, w, nil, id) err := s.Follow(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -378,7 +378,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.UnFollow(ctx, w, nil, id) err := s.UnFollow(ctx, w, nil, id)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
@ -391,7 +391,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeAboutPage(ctx, w, nil) err := s.ServeAboutPage(ctx, w, nil)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -401,7 +401,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeEmojiPage(ctx, w, nil) err := s.ServeEmojiPage(ctx, w, nil)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -418,14 +418,14 @@ func NewHandler(s Service, staticDir string) http.Handler {
if len(offsetStr) > 1 { if len(offsetStr) > 1 {
offset, err = strconv.Atoi(offsetStr) offset, err = strconv.Atoi(offsetStr)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
} }
err = s.ServeSearchPage(ctx, w, nil, q, qType, offset) err = s.ServeSearchPage(ctx, w, nil, q, qType, offset)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -435,7 +435,7 @@ func NewHandler(s Service, staticDir string) http.Handler {
err := s.ServeSettingsPage(ctx, w, nil) err := s.ServeSettingsPage(ctx, w, nil)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }
}).Methods(http.MethodGet) }).Methods(http.MethodGet)
@ -455,12 +455,12 @@ func NewHandler(s Service, staticDir string) http.Handler {
ThreadInNewTab: threadInNewTab, ThreadInNewTab: threadInNewTab,
MaskNSFW: maskNSFW, MaskNSFW: maskNSFW,
FluorideMode: fluorideMode, FluorideMode: fluorideMode,
DarkMode: darkMode, DarkMode: darkMode,
} }
err := s.SaveSettings(ctx, w, nil, settings) err := s.SaveSettings(ctx, w, nil, settings)
if err != nil { if err != nil {
s.ServeErrorPage(ctx, w, err) s.ServeErrorPage(ctx, w, nil, err)
return return
} }

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> About </div> <div class="page-title"> About </div>
<div> <div>
@ -15,4 +16,5 @@
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Emojis </div> <div class="page-title"> Emojis </div>
<div class="emoji-list-container"> <div class="emoji-list-container">
@ -12,5 +13,4 @@
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,9 +1,12 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
<div class="page-title"> Error </div> <div class="page-title"> Error </div>
<div class="error-text"> {{.Error}} </div> <div class="error-text"> {{.Error}} </div>
<div> <div>
<a href="/timeline/home">Home</a> <a href="/timeline/home">Home</a>
<a href="/signin">Sign In</a> <a href="/signin">Sign In</a>
</div> </div>
{{template "footer.tmpl"}}
{{template "footer.tmpl"}}
{{end}}

View File

@ -1,8 +1,9 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Followers </div> <div class="page-title"> Followers </div>
{{template "userlist.tmpl" .Users}} {{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
<div class="pagination"> <div class="pagination">
{{if .HasNext}} {{if .HasNext}}
<a href="{{.NextLink}}">next</a> <a href="{{.NextLink}}">next</a>
@ -10,3 +11,4 @@
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,8 +1,9 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Following </div> <div class="page-title"> Following </div>
{{template "userlist.tmpl" .Users}} {{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
<div class="pagination"> <div class="pagination">
{{if .HasNext}} {{if .HasNext}}
<a href="{{.NextLink}}">next</a> <a href="{{.NextLink}}">next</a>
@ -10,3 +11,4 @@
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,3 +1,4 @@
{{with .Data}}
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
@ -8,8 +9,9 @@
{{if .CustomCSS}} {{if .CustomCSS}}
<link rel="stylesheet" href="{{.CustomCSS}}"> <link rel="stylesheet" href="{{.CustomCSS}}">
{{end}} {{end}}
{{if .FluorideMode}} {{if $.Ctx.FluorideMode}}
<script src="/static/fluoride.js"></script> <script src="/static/fluoride.js"></script>
{{end}} {{end}}
</head> </head>
<body {{if .DarkMode}}class="dark"{{end}}> <body {{if $.Ctx.DarkMode}}class="dark"{{end}}>
{{end}}

View File

@ -1,4 +0,0 @@
{{template "header.tmpl" .HeaderData}}
<div class="page-title"> Home </div>
<a href="/signin"> Signin </a>
{{template "footer.tmpl"}}

View File

@ -1,7 +1,9 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Liked By </div> <div class="page-title"> Liked By </div>
{{template "userlist.tmpl" .Users}} {{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,3 +1,4 @@
{{with .Data}}
<div class="user-info"> <div class="user-info">
<div class="user-info-img-container"> <div class="user-info-img-container">
<a class="img-link" href="/timeline/home" title="home"> <a class="img-link" href="/timeline/home" title="home">
@ -25,3 +26,4 @@
</div> </div>
</div> </div>
</div> </div>
{{end}}

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Notifications </div> <div class="page-title"> Notifications </div>
{{range .Notifications}} {{range .Notifications}}
@ -14,7 +15,7 @@
<div> <div>
<div class="notification-info-text"> <div class="notification-info-text">
<span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span> <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<img class="icon" src="{{GetIcon "user-plus" .DarkMode}}" alt="followed" /> <img class="icon" src="{{GetIcon "user-plus" $.Ctx.DarkMode}}" alt="followed" />
<span> followed you </span> <span> followed you </span>
</div> </div>
<div class="notification-follow-uname"> <div class="notification-follow-uname">
@ -24,7 +25,7 @@
</div> </div>
{{else if eq .Type "mention"}} {{else if eq .Type "mention"}}
{{template "status" .Status}} {{template "status" (WithContext .Status $.Ctx)}}
{{else if eq .Type "reblog"}} {{else if eq .Type "reblog"}}
<div class="notification-retweet-container"> <div class="notification-retweet-container">
@ -36,10 +37,10 @@
<div> <div>
<div class="notification-info-text"> <div class="notification-info-text">
<span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span> <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<img class="icon" src="{{GetIcon "retweeted" .DarkMode}}" alt="retweeted" /> <img class="icon" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="retweeted" />
<span> retweeted your post </span> <span> retweeted your post </span>
</div> </div>
{{template "status" .Status}} {{template "status" (WithContext .Status $.Ctx)}}
</div> </div>
</div> </div>
@ -53,10 +54,10 @@
<div> <div>
<div class="notification-info-text"> <div class="notification-info-text">
<span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span> <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<img class="icon" src="{{GetIcon "liked" .DarkMode}}" alt="liked" /> <img class="icon" src="{{GetIcon "liked" $.Ctx.DarkMode}}" alt="liked" />
<span> liked your post </span> <span> liked your post </span>
</div> </div>
{{template "status" .Status}} {{template "status" (WithContext .Status $.Ctx)}}
</div> </div>
</div> </div>
{{end}} {{end}}
@ -68,4 +69,6 @@
<a href="{{.NextLink}}">next</a> <a href="{{.NextLink}}">next</a>
{{end}} {{end}}
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,3 +1,4 @@
{{with .Data}}
<form class="post-form" action="/post" method="POST" enctype="multipart/form-data"> <form class="post-form" action="/post" method="POST" enctype="multipart/form-data">
{{if .ReplyContext}} {{if .ReplyContext}}
<input type="hidden" name="reply_to_id" value="{{.ReplyContext.InReplyToID}}" /> <input type="hidden" name="reply_to_id" value="{{.ReplyContext.InReplyToID}}" />
@ -6,7 +7,7 @@
<label for="post-content" class="post-form-title"> New post </label> <label for="post-content" class="post-form-title"> New post </label>
{{end}} {{end}}
<a class="post-form-emoji-link" href="/emojis" target="_blank" title="emoji reference"> <a class="post-form-emoji-link" href="/emojis" target="_blank" title="emoji reference">
<img class="icon post-emoji" src="{{GetIcon "smile-o" .DarkMode}}" alt="emojis" /> <img class="icon post-emoji" src="{{GetIcon "smile-o" $.Ctx.DarkMode}}" alt="emojis" />
</a> </a>
<div class="post-form-content-container"> <div class="post-form-content-container">
<textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea> <textarea id="post-content" name="content" class="post-content" cols="50" rows="5">{{if .ReplyContext}}{{.ReplyContext.ReplyContent}}{{end}}</textarea>
@ -42,4 +43,5 @@
</div> </div>
<button type="submit"> Post </button> <button type="submit"> Post </button>
</form> </form>
{{end}}

View File

@ -1,7 +1,9 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Retweeted By </div> <div class="page-title"> Retweeted By </div>
{{template "userlist.tmpl" .Users}} {{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Search </div> <div class="page-title"> Search </div>
<div> <div>
@ -21,12 +22,12 @@
{{if eq .Type "statuses"}} {{if eq .Type "statuses"}}
{{range .Statuses}} {{range .Statuses}}
{{template "status.tmpl" .}} {{template "status.tmpl" (WithContext . $.Ctx)}}
{{end}} {{end}}
{{end}} {{end}}
{{if eq .Type "accounts"}} {{if eq .Type "accounts"}}
{{template "userlist.tmpl" .Users}} {{template "userlist.tmpl" (WithContext .Users $.Ctx)}}
{{end}} {{end}}
<div class="pagination"> <div class="pagination">
@ -34,4 +35,6 @@
<a href="{{.NextLink}}">next</a> <a href="{{.NextLink}}">next</a>
{{end}} {{end}}
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Settings </div> <div class="page-title"> Settings </div>
<form id="settings-form" action="/settings" method="POST"> <form id="settings-form" action="/settings" method="POST">
@ -36,3 +37,4 @@
</form> </form>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,4 +1,5 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
<div class="page-title"> Signin </div> <div class="page-title"> Signin </div>
<form class="signin-form" action="/signin" method="post"> <form class="signin-form" action="/signin" method="post">
@ -8,3 +9,4 @@
</form> </form>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,3 +1,4 @@
{{with .Data}}
<div id="status-{{.ID}}" class="status-container-container"> <div id="status-{{.ID}}" class="status-container-container">
{{if .Reblog}} {{if .Reblog}}
<div class="retweet-info"> <div class="retweet-info">
@ -5,12 +6,13 @@
<img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="avatar" /> <img class="status-profile-img" src="{{.Account.AvatarStatic}}" alt="avatar" />
</a> </a>
<span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span> <span class="status-dname"> {{EmojiFilter .Account.DisplayName .Account.Emojis}} </span>
<img class="icon" src="{{GetIcon "retweeted" .DarkMode}}" alt="retweeted" /> <img class="icon" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="retweeted" />
retweeted retweeted
</div> </div>
{{template "status" .Reblog}} {{template "status" (WithContext .Reblog $.Ctx)}}
{{else}} {{else}}
{{block "status" .}} {{block "status" (WithContext . $.Ctx)}}
{{with $s := .Data}}
<div class="status-container status-{{.ID}}" data-id="{{.ID}}"> <div class="status-container status-{{.ID}}" data-id="{{.ID}}">
{{if not .HideAccountInfo}} {{if not .HideAccountInfo}}
<div class="status-profile-img-container"> <div class="status-profile-img-container">
@ -28,17 +30,17 @@
</a> </a>
<a class="status-visibility"> <a class="status-visibility">
{{if eq .Visibility "public"}} {{if eq .Visibility "public"}}
<img class="icon" src="{{GetIcon "globe" .DarkMode}}" alt="Public" title="Public" /> <img class="icon" src="{{GetIcon "globe" $.Ctx.DarkMode}}" alt="Public" title="Public" />
{{else if eq .Visibility "unlisted"}} {{else if eq .Visibility "unlisted"}}
<img class="icon" src="{{GetIcon "unlock-alt" .DarkMode}}" alt="Unlisted" title="Unlisted" /> <img class="icon" src="{{GetIcon "unlock-alt" $.Ctx.DarkMode}}" alt="Unlisted" title="Unlisted" />
{{else if eq .Visibility "private"}} {{else if eq .Visibility "private"}}
<img class="icon" src="{{GetIcon "lock" .DarkMode}}" alt="Private" title="Private" /> <img class="icon" src="{{GetIcon "lock" $.Ctx.DarkMode}}" alt="Private" title="Private" />
{{else if eq .Visibility "direct"}} {{else if eq .Visibility "direct"}}
<img class="icon" src="{{GetIcon "envelope" .DarkMode}}" alt="Direct" title="Direct" /> <img class="icon" src="{{GetIcon "envelope" $.Ctx.DarkMode}}" alt="Direct" title="Direct" />
{{end}} {{end}}
</a> </a>
<a class="remote-link" href="{{.URL}}" target="_blank" title="source"> <a class="remote-link" href="{{.URL}}" target="_blank" title="source">
<img class="icon" src="{{GetIcon "link" .DarkMode}}" alt="source" /> <img class="icon" src="{{GetIcon "link" $.Ctx.DarkMode}}" alt="source" />
</a> </a>
</div> </div>
{{end}} {{end}}
@ -46,7 +48,7 @@
{{if .InReplyToID}} {{if .InReplyToID}}
<div class="status-reply-to"> <div class="status-reply-to">
<a class="status-reply-to-link" href="{{if not .ShowReplies}}/thread/{{.InReplyToID}}{{end}}#status-{{.InReplyToID}}"> <a class="status-reply-to-link" href="{{if not .ShowReplies}}/thread/{{.InReplyToID}}{{end}}#status-{{.InReplyToID}}">
<img class="icon" src="{{GetIcon "mail-forward" .DarkMode}}" alt="reply to" /> reply to {{.Pleroma.InReplyToAccountAcct}} <img class="icon" src="{{GetIcon "mail-forward" $.Ctx.DarkMode}}" alt="reply to" /> reply to {{.Pleroma.InReplyToAccountAcct}}
</a> </a>
</div> </div>
{{if index .ReplyMap .ID}} <span class="status-reply-info-divider"> - </span> {{end}} {{if index .ReplyMap .ID}} <span class="status-reply-info-divider"> - </span> {{end}}
@ -66,7 +68,7 @@
{{if eq .Type "image"}} {{if eq .Type "image"}}
<a class="img-link" href="{{.URL}}" target="_blank"> <a class="img-link" href="{{.URL}}" target="_blank">
<img class="status-image" src="{{.URL}}" alt="status-image" /> <img class="status-image" src="{{.URL}}" alt="status-image" />
{{if (and $.MaskNSFW $.Sensitive)}} {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
<div class="status-nsfw-overlay"></div> <div class="status-nsfw-overlay"></div>
{{end}} {{end}}
</a> </a>
@ -81,7 +83,7 @@
<source src="{{.URL}}"> <source src="{{.URL}}">
<p> Your browser doesn't support HTML5 video </p> <p> Your browser doesn't support HTML5 video </p>
</video> </video>
{{if (and $.MaskNSFW $.Sensitive)}} {{if (and $.Ctx.MaskNSFW $s.Sensitive)}}
<div class="status-nsfw-overlay"></div> <div class="status-nsfw-overlay"></div>
{{end}} {{end}}
</div> </div>
@ -93,27 +95,27 @@
<div class="status-action-container"> <div class="status-action-container">
<div class="status-action"> <div class="status-action">
<a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply"> <a class="status-you" href="/thread/{{.ID}}?reply=true#status-{{.ID}}" title="reply">
<img class="icon" src="{{GetIcon "reply" .DarkMode}}" alt="reply" /> <img class="icon" src="{{GetIcon "reply" $.Ctx.DarkMode}}" alt="reply" />
</a> </a>
<a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}> <a class="status-reply-count" href="/thread/{{.ID}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}>
{{DisplayInteractionCount .RepliesCount}} {{DisplayInteractionCount .RepliesCount}}
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">
{{if or (eq .Visibility "private") (eq .Visibility "direct")}} {{if or (eq .Visibility "private") (eq .Visibility "direct")}}
<a class="status-retweet" title="this status cannot be retweeted"> <a class="status-retweet" title="this status cannot be retweeted">
<img class="icon" src="{{GetIcon "retweet" .DarkMode}}" alt="retweet" /> <img class="icon" src="{{GetIcon "retweet" $.Ctx.DarkMode}}" alt="retweet" />
</a> </a>
{{else}} {{else}}
{{if .Reblogged}} {{if .Reblogged}}
<form class="status-retweet" data-action="unretweet" action="/unretweet/{{.ID}}" method="post"> <form class="status-retweet" data-action="unretweet" action="/unretweet/{{.ID}}" method="post">
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
<input type="image" src="{{GetIcon "retweeted" .DarkMode}}" alt="undo retweet" class="icon" title="undo retweet"> <input type="image" src="{{GetIcon "retweeted" $.Ctx.DarkMode}}" alt="undo retweet" class="icon" title="undo retweet">
</form> </form>
{{else}} {{else}}
<form class="status-retweet" data-action="retweet" action="/retweet/{{.ID}}" method="post"> <form class="status-retweet" data-action="retweet" action="/retweet/{{.ID}}" method="post">
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
<input type="image" src="{{GetIcon "retweet" .DarkMode}}" alt="retweet" class="icon" title="retweet"> <input type="image" src="{{GetIcon "retweet" $.Ctx.DarkMode}}" alt="retweet" class="icon" title="retweet">
</form> </form>
{{end}} {{end}}
{{end}} {{end}}
@ -125,12 +127,12 @@
{{if .Favourited}} {{if .Favourited}}
<form class="status-like" data-action="unlike" action="/unlike/{{.ID}}" method="post"> <form class="status-like" data-action="unlike" action="/unlike/{{.ID}}" method="post">
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
<input type="image" src="{{GetIcon "liked" .DarkMode}}" alt="unlike" class="icon" title="unlike"> <input type="image" src="{{GetIcon "liked" $.Ctx.DarkMode}}" alt="unlike" class="icon" title="unlike">
</form> </form>
{{else}} {{else}}
<form class="status-like" data-action="like" action="/like/{{.ID}}" method="post"> <form class="status-like" data-action="like" action="/like/{{.ID}}" method="post">
<input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" /> <input type="hidden" name="retweeted_by_id" value="{{.RetweetedByID}}" />
<input type="image" src="{{GetIcon "star-o" .DarkMode}}" alt="like" class="icon" title="like"> <input type="image" src="{{GetIcon "star-o" $.Ctx.DarkMode}}" alt="like" class="icon" title="like">
</form> </form>
{{end}} {{end}}
<a class="status-like-count" href="/likedby/{{.ID}}" title="click to see the the list"> <a class="status-like-count" href="/likedby/{{.ID}}" title="click to see the the list">
@ -138,7 +140,7 @@
</a> </a>
</div> </div>
<div class="status-action"> <div class="status-action">
<a class="status-time" href="{{if not .ShowReplies}}/thread/{{.ID}}{{end}}#status-{{.ID}}" {{if .ThreadInNewTab}}target="_blank"{{end}}> <a class="status-time" href="{{if not .ShowReplies}}/thread/{{.ID}}{{end}}#status-{{.ID}}" {{if $.Ctx.ThreadInNewTab}}target="_blank"{{end}}>
<time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{FormatTimeRFC822 .CreatedAt}}"> {{TimeSince .CreatedAt}} </time> <time datetime="{{FormatTimeRFC3339 .CreatedAt}}" title="{{FormatTimeRFC822 .CreatedAt}}"> {{TimeSince .CreatedAt}} </time>
</a> </a>
</div> </div>
@ -147,4 +149,6 @@
</div> </div>
{{end}} {{end}}
{{end}} {{end}}
{{end}}
</div> </div>
{{end}}

View File

@ -1,14 +1,16 @@
{{template "header.tmpl" .HeaderData}} {{with $s := .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> Thread </div> <div class="page-title"> Thread </div>
{{range .Statuses}} {{range .Statuses}}
{{template "status.tmpl" .}} {{template "status.tmpl" (WithContext . $.Ctx)}}
{{if $.PostContext.ReplyContext}}{{if eq .ID $.PostContext.ReplyContext.InReplyToID}} {{if $s.PostContext.ReplyContext}}{{if eq .ID $s.PostContext.ReplyContext.InReplyToID}}
{{template "postform.tmpl" $.PostContext}} {{template "postform.tmpl" (WithContext $s.PostContext $.Ctx)}}
{{end}}{{end}} {{end}}{{end}}
{{end}} {{end}}
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,12 +1,12 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> {{.Title}} </div> <div class="page-title"> {{.Title}} </div>
{{template "postform.tmpl" (WithContext .PostContext $.Ctx)}}
{{template "postform.tmpl" .PostContext}}
{{range .Statuses}} {{range .Statuses}}
{{template "status.tmpl" .}} {{template "status.tmpl" (WithContext . $.Ctx)}}
{{end}} {{end}}
<div class="pagination"> <div class="pagination">
@ -17,4 +17,6 @@
<a href="{{.NextLink}}">next</a> <a href="{{.NextLink}}">next</a>
{{end}} {{end}}
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,5 +1,6 @@
{{template "header.tmpl" .HeaderData}} {{with .Data}}
{{template "navigation.tmpl" .NavbarData}} {{template "header.tmpl" (WithContext .HeaderData $.Ctx)}}
{{template "navigation.tmpl" (WithContext .NavbarData $.Ctx)}}
<div class="page-title"> User </div> <div class="page-title"> User </div>
<div class="user-info-container"> <div class="user-info-container">
@ -14,7 +15,7 @@
<span class="status-dname"> {{EmojiFilter .User.DisplayName .User.Emojis}} </span> <span class="status-dname"> {{EmojiFilter .User.DisplayName .User.Emojis}} </span>
<span class="status-uname"> {{.User.Acct}} </span> <span class="status-uname"> {{.User.Acct}} </span>
<a class="remote-link" href="{{.User.URL}}" target="_blank" title="remote profile"> <a class="remote-link" href="{{.User.URL}}" target="_blank" title="remote profile">
<img class="icon" src="{{GetIcon "link" .DarkMode}}" alt="link" /> <img class="icon" src="{{GetIcon "link" $.Ctx.DarkMode}}" alt="link" />
</a> </a>
</div> </div>
<div> <div>
@ -48,7 +49,7 @@
</div> </div>
{{range .Statuses}} {{range .Statuses}}
{{template "status.tmpl" .}} {{template "status.tmpl" (WithContext . $.Ctx)}}
{{end}} {{end}}
<div class="pagination"> <div class="pagination">
@ -58,4 +59,4 @@
</div> </div>
{{template "footer.tmpl"}} {{template "footer.tmpl"}}
{{end}}

View File

@ -1,3 +1,4 @@
{{with .Data}}
<div class="user-list-container"> <div class="user-list-container">
{{range .}} {{range .}}
<div class="user-list-item"> <div class="user-list-item">
@ -15,3 +16,4 @@
</div> </div>
{{end}} {{end}}
</div> </div>
{{end}}