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"`
|
Search *search `mapstructure:"search"`
|
||||||
CustomPages []*customPage `mapstructure:"custompages"`
|
CustomPages []*customPage `mapstructure:"custompages"`
|
||||||
Telegram *configTelegram `mapstructure:"telegram"`
|
Telegram *configTelegram `mapstructure:"telegram"`
|
||||||
|
PostAsHome bool `mapstructure:"postAsHome"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type section struct {
|
type section struct {
|
||||||
|
|
20
http.go
20
http.go
|
@ -263,16 +263,18 @@ func buildHandler() (http.Handler, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Blog
|
// Blog
|
||||||
var mw []func(http.Handler) http.Handler
|
if !blogConfig.PostAsHome {
|
||||||
if appConfig.ActivityPub.Enabled {
|
var mw []func(http.Handler) http.Handler
|
||||||
mw = []func(http.Handler) http.Handler{manipulateAsPath, cacheMiddleware, minifier.Middleware}
|
if appConfig.ActivityPub.Enabled {
|
||||||
} else {
|
mw = []func(http.Handler) http.Handler{manipulateAsPath, cacheMiddleware, minifier.Middleware}
|
||||||
mw = []func(http.Handler) http.Handler{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
|
// Custom pages
|
||||||
for _, cp := range blogConfig.CustomPages {
|
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 == "" {
|
if canonical == "" {
|
||||||
canonical = p.fullURL()
|
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()))
|
w.Header().Add("Link", fmt.Sprintf("<%s>; rel=shortlink", p.shortURL()))
|
||||||
render(w, templatePost, &renderData{
|
render(w, template, &renderData{
|
||||||
blogString: p.Blog,
|
blogString: p.Blog,
|
||||||
Canonical: canonical,
|
Canonical: canonical,
|
||||||
Data: p,
|
Data: p,
|
||||||
|
|
|
@ -62,7 +62,9 @@ func (p *post) checkPost() (err error) {
|
||||||
return errors.New("section doesn't exist")
|
return errors.New("section doesn't exist")
|
||||||
}
|
}
|
||||||
// Check path
|
// Check path
|
||||||
p.Path = strings.TrimSuffix(p.Path, "/")
|
if p.Path != "/" {
|
||||||
|
p.Path = strings.TrimSuffix(p.Path, "/")
|
||||||
|
}
|
||||||
if p.Path == "" {
|
if p.Path == "" {
|
||||||
if p.Section == "" {
|
if p.Section == "" {
|
||||||
p.Section = appConfig.Blogs[p.Blog].DefaultSection
|
p.Section = appConfig.Blogs[p.Blog].DefaultSection
|
||||||
|
|
|
@ -32,6 +32,7 @@ const templateSummary = "summary"
|
||||||
const templatePhotosSummary = "photosummary"
|
const templatePhotosSummary = "photosummary"
|
||||||
const templateEditor = "editor"
|
const templateEditor = "editor"
|
||||||
const templateLogin = "login"
|
const templateLogin = "login"
|
||||||
|
const templateStaticHome = "statichome"
|
||||||
|
|
||||||
var templates map[string]*template.Template
|
var templates map[string]*template.Template
|
||||||
var templateFunctions template.FuncMap
|
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