diff --git a/admin.go b/admin.go index fe19ad5..4269bcc 100644 --- a/admin.go +++ b/admin.go @@ -319,6 +319,8 @@ func handleViewAdminPage(app *App, u *User, w http.ResponseWriter, r *http.Reque } p.Content, err = getLandingBody(app) p.Content.ID = "landing" + } else if slug == "reader" { + p.Content, err = getReaderSection(app) } else { p.Content, err = app.db.GetDynamicContent(slug) } @@ -342,7 +344,7 @@ func handleAdminUpdateSite(app *App, u *User, w http.ResponseWriter, r *http.Req id := vars["page"] // Validate - if id != "about" && id != "privacy" && id != "landing" { + if id != "about" && id != "privacy" && id != "landing" && id != "reader" { return impart.HTTPError{http.StatusNotFound, "No such page."} } @@ -356,6 +358,9 @@ func handleAdminUpdateSite(app *App, u *User, w http.ResponseWriter, r *http.Req return impart.HTTPError{http.StatusFound, "/admin/page/" + id + m} } err = app.db.UpdateDynamicContent("landing-body", "", r.FormValue("content"), "section") + } else if id == "reader" { + // Update sections with titles + err = app.db.UpdateDynamicContent(id, r.FormValue("title"), r.FormValue("content"), "section") } else { // Update page err = app.db.UpdateDynamicContent(id, r.FormValue("title"), r.FormValue("content"), "page") diff --git a/pages.go b/pages.go index 405b34f..d8f034b 100644 --- a/pages.go +++ b/pages.go @@ -135,3 +135,30 @@ WriteFreely can communicate with other federated platforms like Mastodon, so peo } return "" } + +func getReaderSection(app *App) (*instanceContent, error) { + c, err := app.db.GetDynamicContent("reader") + if err != nil { + return nil, err + } + if c == nil { + c = &instanceContent{ + ID: "reader", + Type: "section", + Content: defaultReaderBanner(app.cfg), + Updated: defaultPageUpdatedTime, + } + } + if !c.Title.Valid { + c.Title = defaultReaderTitle(app.cfg) + } + return c, nil +} + +func defaultReaderTitle(cfg *config.Config) sql.NullString { + return sql.NullString{String: "Reader", Valid: true} +} + +func defaultReaderBanner(cfg *config.Config) string { + return "Read the latest posts from " + cfg.App.SiteName + "." +} diff --git a/read.go b/read.go index 3efb89d..ec0305a 100644 --- a/read.go +++ b/read.go @@ -50,6 +50,10 @@ type readPublication struct { SelTopic string IsAdmin bool CanInvite bool + + // Customizable page content + ContentTitle string + Content template.HTML } func initLocalTimeline(app *App) { @@ -211,8 +215,14 @@ func showLocalTimeline(app *App, w http.ResponseWriter, r *http.Request, page in d.IsAdmin = u != nil && u.IsAdmin() d.CanInvite = canUserInvite(app.cfg, d.IsAdmin) } + c, err := getReaderSection(app) + if err != nil { + return err + } + d.ContentTitle = c.Title.String + d.Content = template.HTML(applyMarkdown([]byte(c.Content), "", app.cfg)) - err := templates["read"].ExecuteTemplate(w, "base", d) + err = templates["read"].ExecuteTemplate(w, "base", d) if err != nil { log.Error("Unable to render reader: %v", err) fmt.Fprintf(w, ":(") diff --git a/templates/read.tmpl b/templates/read.tmpl index 28d2fd1..9541ab5 100644 --- a/templates/read.tmpl +++ b/templates/read.tmpl @@ -80,8 +80,8 @@ {{define "body-attrs"}}id="collection"{{end}} {{define "content"}}
-

Reader

- {{if .SelTopic}}#{{.SelTopic}} posts{{else}}Read the latest posts from {{.SiteName}}. {{if .Username}}To showcase your writing here, go to your blog settings and select the Public option.{{end}}{{end}}

+

{{.ContentTitle}}

+ {{if .SelTopic}}#{{.SelTopic}} posts{{else}}{{.Content}}{{end}}

{{ if gt (len .Posts) 0 }} diff --git a/templates/user/admin/pages.tmpl b/templates/user/admin/pages.tmpl index 25f7984..7a9e66a 100644 --- a/templates/user/admin/pages.tmpl +++ b/templates/user/admin/pages.tmpl @@ -20,6 +20,9 @@ table.classy.export .disabled, table.classy.export a { Home + {{if .LocalTimeline}} + Reader + {{end}} {{range .Pages}} {{if .Title.Valid}}{{.Title.String}}{{else}}{{.ID}}{{end}} diff --git a/templates/user/admin/view-page.tmpl b/templates/user/admin/view-page.tmpl index 6d98b9d..161e40b 100644 --- a/templates/user/admin/view-page.tmpl +++ b/templates/user/admin/view-page.tmpl @@ -31,6 +31,8 @@ input[type=text] {

Describe what your instance is about.

{{else if eq .Content.ID "privacy"}}

Outline your privacy policy.

+ {{else if eq .Content.ID "reader"}} +

Customize your Reader page.

{{else if eq .Content.ID "landing"}}

Customize your home page.

{{end}} @@ -38,7 +40,7 @@ input[type=text] { {{if .Message}}

{{.Message}}

{{end}}
- {{if eq .Content.Type "section"}} + {{if .Banner}}