From 818a1c23c238000f8d771ec850ba91f02d6698f1 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Wed, 23 Dec 2020 16:53:10 +0100 Subject: [PATCH] Use static home page --- config.go | 1 + http.go | 20 +++++++++++--------- posts.go | 6 +++++- postsDb.go | 4 +++- render.go | 1 + templates/statichome.gohtml | 22 ++++++++++++++++++++++ 6 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 templates/statichome.gohtml diff --git a/config.go b/config.go index bb0c167..c77a65a 100644 --- a/config.go +++ b/config.go @@ -58,6 +58,7 @@ type configBlog struct { Search *search `mapstructure:"search"` CustomPages []*customPage `mapstructure:"custompages"` Telegram *configTelegram `mapstructure:"telegram"` + PostAsHome bool `mapstructure:"postAsHome"` } type section struct { diff --git a/http.go b/http.go index 1638482..9f23fd2 100644 --- a/http.go +++ b/http.go @@ -263,16 +263,18 @@ func buildHandler() (http.Handler, error) { } // Blog - var mw []func(http.Handler) http.Handler - if appConfig.ActivityPub.Enabled { - mw = []func(http.Handler) http.Handler{manipulateAsPath, cacheMiddleware, minifier.Middleware} - } else { - mw = []func(http.Handler) http.Handler{cacheMiddleware, minifier.Middleware} + if !blogConfig.PostAsHome { + var mw []func(http.Handler) http.Handler + if appConfig.ActivityPub.Enabled { + mw = []func(http.Handler) http.Handler{manipulateAsPath, cacheMiddleware, minifier.Middleware} + } else { + mw = []func(http.Handler) http.Handler{cacheMiddleware, minifier.Middleware} + } + handler := serveHome(blog, blogPath) + r.With(mw...).Get(fullBlogPath, handler) + r.With(cacheMiddleware, minifier.Middleware).Get(fullBlogPath+feedPath, handler) + r.With(cacheMiddleware, minifier.Middleware).Get(blogPath+paginationPath, handler) } - handler := serveHome(blog, blogPath) - r.With(mw...).Get(fullBlogPath, handler) - r.With(cacheMiddleware, minifier.Middleware).Get(fullBlogPath+feedPath, handler) - r.With(cacheMiddleware, minifier.Middleware).Get(blogPath+paginationPath, handler) // Custom pages for _, cp := range blogConfig.CustomPages { diff --git a/posts.go b/posts.go index acc796c..cd9c629 100644 --- a/posts.go +++ b/posts.go @@ -52,8 +52,12 @@ func servePost(w http.ResponseWriter, r *http.Request) { if canonical == "" { canonical = p.fullURL() } + template := templatePost + if p.Path == appConfig.Blogs[p.Blog].Path { + template = templateStaticHome + } w.Header().Add("Link", fmt.Sprintf("<%s>; rel=shortlink", p.shortURL())) - render(w, templatePost, &renderData{ + render(w, template, &renderData{ blogString: p.Blog, Canonical: canonical, Data: p, diff --git a/postsDb.go b/postsDb.go index 7bd9a76..046d83f 100644 --- a/postsDb.go +++ b/postsDb.go @@ -62,7 +62,9 @@ func (p *post) checkPost() (err error) { return errors.New("section doesn't exist") } // Check path - p.Path = strings.TrimSuffix(p.Path, "/") + if p.Path != "/" { + p.Path = strings.TrimSuffix(p.Path, "/") + } if p.Path == "" { if p.Section == "" { p.Section = appConfig.Blogs[p.Blog].DefaultSection diff --git a/render.go b/render.go index b5615a6..e0966c4 100644 --- a/render.go +++ b/render.go @@ -32,6 +32,7 @@ const templateSummary = "summary" const templatePhotosSummary = "photosummary" const templateEditor = "editor" const templateLogin = "login" +const templateStaticHome = "statichome" var templates map[string]*template.Template var templateFunctions template.FuncMap diff --git a/templates/statichome.gohtml b/templates/statichome.gohtml new file mode 100644 index 0000000..36a8b8d --- /dev/null +++ b/templates/statichome.gohtml @@ -0,0 +1,22 @@ +{{ define "title" }} + {{ .Blog.Title }} + {{ include "postheadmeta" . }} +{{ end }} + +{{ define "main" }} +
+
+ + {{ if .Data.Content }} +
+ {{ content .Data }} +
+ {{ end }} +
+ {{ include "author" . }} +
+{{ end }} + +{{ define "statichome" }} + {{ template "base" . }} +{{ end }} \ No newline at end of file