mirror of https://github.com/jlelse/GoBlog
Use static home page
This commit is contained in:
parent
315fb575cb
commit
818a1c23c2
|
@ -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 {
|
||||
|
|
20
http.go
20
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 {
|
||||
|
|
6
posts.go
6
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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
{{ define "title" }}
|
||||
<title>{{ .Blog.Title }}</title>
|
||||
{{ include "postheadmeta" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
<main class=h-entry>
|
||||
<article>
|
||||
<data class="u-url hide" value="{{ absolute .Data.Path }}"></data>
|
||||
{{ if .Data.Content }}
|
||||
<div class=e-content>
|
||||
{{ content .Data }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</article>
|
||||
{{ include "author" . }}
|
||||
</main>
|
||||
{{ end }}
|
||||
|
||||
{{ define "statichome" }}
|
||||
{{ template "base" . }}
|
||||
{{ end }}
|
Loading…
Reference in New Issue