Add about page

This commit is contained in:
r 2019-12-21 05:48:48 +00:00
parent 889f8da496
commit 2648484a1d
8 changed files with 75 additions and 0 deletions

View File

@ -86,3 +86,13 @@ func NewUserPageTemplateData(user *mastodon.Account, statuses []*mastodon.Status
NavbarData: navbarData, NavbarData: navbarData,
} }
} }
type AboutPageTemplateData struct {
NavbarData *NavbarTemplateData
}
func NewAboutPageTemplateData(navbarData *NavbarTemplateData) *AboutPageTemplateData {
return &AboutPageTemplateData{
NavbarData: navbarData,
}
}

View File

@ -19,6 +19,7 @@ type Renderer interface {
RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadPageTemplateData) (err error) RenderThreadPage(ctx context.Context, writer io.Writer, data *ThreadPageTemplateData) (err error)
RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationPageTemplateData) (err error) RenderNotificationPage(ctx context.Context, writer io.Writer, data *NotificationPageTemplateData) (err error)
RenderUserPage(ctx context.Context, writer io.Writer, data *UserPageTemplateData) (err error) RenderUserPage(ctx context.Context, writer io.Writer, data *UserPageTemplateData) (err error)
RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutPageTemplateData) (err error)
} }
type renderer struct { type renderer struct {
@ -71,6 +72,9 @@ func (r *renderer) RenderUserPage(ctx context.Context, writer io.Writer, data *U
return r.template.ExecuteTemplate(writer, "user.tmpl", data) return r.template.ExecuteTemplate(writer, "user.tmpl", data)
} }
func (r *renderer) RenderAboutPage(ctx context.Context, writer io.Writer, data *AboutPageTemplateData) (err error) {
return r.template.ExecuteTemplate(writer, "about.tmpl", data)
}
func EmojiFilter(content string, emojis []mastodon.Emoji) string { func EmojiFilter(content string, emojis []mastodon.Emoji) string {
var replacements []string var replacements []string

View File

@ -127,6 +127,14 @@ func (s *authService) ServeUserPage(ctx context.Context, client io.Writer, c *ma
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID) return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
} }
func (s *authService) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
c, err = s.getClient(ctx)
if err != nil {
return
}
return s.Service.ServeAboutPage(ctx, client, c)
}
func (s *authService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) { func (s *authService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
c, err = s.getClient(ctx) c, err = s.getClient(ctx)
if err != nil { if err != nil {

View File

@ -93,6 +93,14 @@ func (s *loggingService) ServeUserPage(ctx context.Context, client io.Writer, c
return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID) return s.Service.ServeUserPage(ctx, client, c, id, maxID, minID)
} }
func (s *loggingService) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
defer func(begin time.Time) {
s.logger.Printf("method=%v, took=%v, err=%v\n",
"ServeAboutPage", time.Since(begin), err)
}(time.Now())
return s.Service.ServeAboutPage(ctx, client, c)
}
func (s *loggingService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) { func (s *loggingService) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) {
defer func(begin time.Time) { defer func(begin time.Time) {
s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n", s.logger.Printf("method=%v, id=%v, took=%v, err=%v\n",

View File

@ -33,6 +33,7 @@ type Service interface {
ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error) ServeThreadPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, reply bool) (err error)
ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error) ServeNotificationPage(ctx context.Context, client io.Writer, c *mastodon.Client, maxID string, minID string) (err error)
ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error) ServeUserPage(ctx context.Context, client io.Writer, c *mastodon.Client, id string, maxID string, minID string) (err error)
ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error)
Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) Like(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) UnLike(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error) Retweet(ctx context.Context, client io.Writer, c *mastodon.Client, id string) (err error)
@ -411,6 +412,21 @@ func (svc *service) ServeUserPage(ctx context.Context, client io.Writer, c *mast
return return
} }
func (svc *service) ServeAboutPage(ctx context.Context, client io.Writer, c *mastodon.Client) (err error) {
navbarData, err := svc.getNavbarTemplateData(ctx, client, c)
if err != nil {
return
}
data := renderer.NewAboutPageTemplateData(navbarData)
err = svc.renderer.RenderAboutPage(ctx, client, data)
if err != nil {
return
}
return
}
func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *mastodon.Client) (data *renderer.NavbarTemplateData, err error) { func (svc *service) getNavbarTemplateData(ctx context.Context, client io.Writer, c *mastodon.Client) (data *renderer.NavbarTemplateData, err error) {
notifications, err := c.GetNotifications(ctx, nil) notifications, err := c.GetNotifications(ctx, nil)
if err != nil { if err != nil {

View File

@ -228,6 +228,16 @@ func NewHandler(s Service, staticDir string) http.Handler {
w.WriteHeader(http.StatusFound) w.WriteHeader(http.StatusFound)
}).Methods(http.MethodPost) }).Methods(http.MethodPost)
r.HandleFunc("/about", func(w http.ResponseWriter, req *http.Request) {
ctx := getContextWithSession(context.Background(), req)
err := s.ServeAboutPage(ctx, w, nil)
if err != nil {
s.ServeErrorPage(ctx, w, err)
return
}
}).Methods(http.MethodGet)
r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) { r.HandleFunc("/signout", func(w http.ResponseWriter, req *http.Request) {
// TODO remove session from database // TODO remove session from database
w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0")) w.Header().Add("Set-Cookie", fmt.Sprintf("session_id=;max-age=0"))

18
templates/about.tmpl Normal file
View File

@ -0,0 +1,18 @@
{{template "header.tmpl"}}
{{template "navigation.tmpl" .NavbarData}}
<div class="page-title"> About </div>
<div>
<p>
A web client for <a href="https://pleroma.social" target="_blank">Mastodon Network</a>.
</p>
<p>
The source code is released under
<a href="https://creativecommons.org/share-your-work/public-domain/cc0" target="_blank">CC0</a>
and is available on
<a href="https://git.freesoftwareextremist.com/web" target="_blank">git.freesoftwareextremist.com/web</a>.
</P>
</div>
{{template "footer.tmpl"}}

View File

@ -1,5 +1,6 @@
<div class="navigation"> <div class="navigation">
<a href="/timeline">home</a> <a href="/timeline">home</a>
<a href="/notifications">notifications{{if gt .NotificationCount 0}} ({{.NotificationCount}}){{end}}</a> <a href="/notifications">notifications{{if gt .NotificationCount 0}} ({{.NotificationCount}}){{end}}</a>
<a href="/about">about</a>
<a href="/signout">sign out</a> <a href="/signout">sign out</a>
</div> </div>