调整包名, 完善首页归档、分类、作者的参数验证

This commit is contained in:
xing 2023-01-21 21:13:33 +08:00
parent 04858e304f
commit 8d5c989d97
13 changed files with 158 additions and 75 deletions

View File

@ -1,11 +1,13 @@
package actions package actions
import ( import (
"errors"
"fmt" "fmt"
"github.com/fthvgb1/wp-go/helper/number"
"github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/helper/slice"
str "github.com/fthvgb1/wp-go/helper/strings" str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/pkg/cache" "github.com/fthvgb1/wp-go/internal/pkg/cache"
dao "github.com/fthvgb1/wp-go/internal/pkg/dao" "github.com/fthvgb1/wp-go/internal/pkg/dao"
"github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/plugins" "github.com/fthvgb1/wp-go/internal/plugins"
@ -20,6 +22,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync/atomic" "sync/atomic"
"time"
) )
type indexHandle struct { type indexHandle struct {
@ -40,10 +43,11 @@ type indexHandle struct {
order string order string
join model.SqlBuilder join model.SqlBuilder
postType []any postType []any
status []any postStatus []any
header string header string
paginationStep int paginationStep int
scene uint scene int
status int
} }
func newIndexHandle(ctx *gin.Context) *indexHandle { func newIndexHandle(ctx *gin.Context) *indexHandle {
@ -64,10 +68,16 @@ func newIndexHandle(ctx *gin.Context) *indexHandle {
orderBy: "post_date", orderBy: "post_date",
join: model.SqlBuilder{}, join: model.SqlBuilder{},
postType: []any{"post"}, postType: []any{"post"},
status: []any{"publish"}, postStatus: []any{"publish"},
scene: plugins.Home, scene: plugins.Home,
status: plugins.Ok,
} }
} }
var months = slice.SimpleToMap(number.Range(1, 12, 1), func(v int) int {
return v
})
func (h *indexHandle) setTitleLR(l, r string) { func (h *indexHandle) setTitleLR(l, r string) {
h.titleL = l h.titleL = l
h.titleR = r h.titleR = r
@ -89,12 +99,27 @@ func (h *indexHandle) parseParams() (err error) {
} }
year := h.c.Param("year") year := h.c.Param("year")
if year != "" { if year != "" {
y, er := strconv.Atoi(year)
if er != nil {
return err
}
if y > time.Now().Year() || y <= 1970 {
return errors.New(str.Join("year err : ", year))
}
h.where = append(h.where, []string{ h.where = append(h.where, []string{
"year(post_date)", year, "year(post_date)", year,
}) })
} }
month := h.c.Param("month") month := h.c.Param("month")
if month != "" { if month != "" {
m, err := strconv.Atoi(month)
if err != nil {
return err
}
if _, ok := months[m]; !ok {
return errors.New(str.Join("months err ", month))
}
h.where = append(h.where, []string{ h.where = append(h.where, []string{
"month(post_date)", month, "month(post_date)", month,
}) })
@ -111,12 +136,25 @@ func (h *indexHandle) parseParams() (err error) {
h.header = fmt.Sprintf("标签: <span>%s</span>", category) h.header = fmt.Sprintf("标签: <span>%s</span>", category)
} }
} else { } else {
allNames := cache.AllCategoryNames(h.c)
if _, ok := allNames[category]; !ok {
return errors.New(str.Join("not exists category ", category))
}
h.categoryType = "category" h.categoryType = "category"
h.header = fmt.Sprintf("分类: <span>%s</span>", category) h.header = fmt.Sprintf("分类: <span>%s</span>", category)
} }
h.category = category h.category = category
username := h.c.Param("author") username := h.c.Param("author")
if username != "" { if username != "" {
allUsername, er := cache.GetAllUsername(h.c)
if er != nil {
err = er
return
}
if _, ok := allUsername[username]; !ok {
err = errors.New(str.Join("user ", username, " is not exists"))
return
}
user, er := cache.GetUserByName(h.c, username) user, er := cache.GetUserByName(h.c, username)
if er != nil { if er != nil {
err = er err = er
@ -181,7 +219,7 @@ func (h *indexHandle) getTotalPage(totalRaws int) int {
func Index(c *gin.Context) { func Index(c *gin.Context) {
h := newIndexHandle(c) h := newIndexHandle(c)
var postIds []models.Posts var posts []models.Posts
var totalRaw int var totalRaw int
var err error var err error
archive := cache.Archives(c) archive := cache.Archives(c)
@ -189,6 +227,7 @@ func Index(c *gin.Context) {
categoryItems := cache.Categories(c) categoryItems := cache.Categories(c)
recentComments := cache.RecentComments(c, 5) recentComments := cache.RecentComments(c, 5)
ginH := gin.H{ ginH := gin.H{
"err": err,
"options": wpconfig.Options, "options": wpconfig.Options,
"recentPosts": recent, "recentPosts": recent,
"archives": archive, "archives": archive,
@ -198,14 +237,19 @@ func Index(c *gin.Context) {
"recentComments": recentComments, "recentComments": recentComments,
} }
defer func() { defer func() {
stat := http.StatusOK code := http.StatusOK
if err != nil { if err != nil {
code = http.StatusNotFound
if h.status == plugins.InternalErr {
code = http.StatusInternalServerError
c.Error(err) c.Error(err)
stat = http.StatusInternalServerError
return return
} }
c.Error(err)
h.status = plugins.Error
}
t := theme.GetTemplateName() t := theme.GetTemplateName()
theme.Hook(t, stat, c, ginH, int(h.scene)) theme.Hook(t, code, c, ginH, h.scene, h.status)
}() }()
err = h.parseParams() err = h.parseParams()
if err != nil { if err != nil {
@ -213,33 +257,34 @@ func Index(c *gin.Context) {
} }
ginH["title"] = h.getTitle() ginH["title"] = h.getTitle()
if c.Param("month") != "" { if c.Param("month") != "" {
postIds, totalRaw, err = cache.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order) posts, totalRaw, err = cache.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
if err != nil { if err != nil {
return return
} }
} else if h.search != "" { } else if h.search != "" {
postIds, totalRaw, err = cache.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status) posts, totalRaw, err = cache.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.postStatus)
} else { } else {
postIds, totalRaw, err = cache.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status) posts, totalRaw, err = cache.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, model.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.postStatus)
} }
if err != nil { if err != nil {
h.status = plugins.Error
logs.ErrPrintln(err, "获取数据错误") logs.ErrPrintln(err, "获取数据错误")
return return
} }
if len(postIds) < 1 && h.category != "" { if len(posts) < 1 && h.category != "" {
h.titleL = "未找到页面" h.titleL = "未找到页面"
h.scene = plugins.Empty404 h.status = plugins.Empty404
} }
pw := h.session.Get("post_password") pw := h.session.Get("post_password")
plug := plugins.NewPostPlugin(c, h.scene) plug := plugins.NewPostPlugin(c, h.scene)
for i, post := range postIds { for i, post := range posts {
plugins.PasswordProjectTitle(&postIds[i]) plugins.PasswordProjectTitle(&posts[i])
if post.PostPassword != "" && pw != post.PostPassword { if post.PostPassword != "" && pw != post.PostPassword {
plugins.PasswdProjectContent(&postIds[i]) plugins.PasswdProjectContent(&posts[i])
} else { } else {
plugins.ApplyPlugin(plug, &postIds[i]) plugins.ApplyPlugin(plug, &posts[i])
} }
} }
for i, post := range recent { for i, post := range recent {
@ -251,7 +296,7 @@ func Index(c *gin.Context) {
if q != "" { if q != "" {
q = fmt.Sprintf("?%s", q) q = fmt.Sprintf("?%s", q)
} }
ginH["posts"] = postIds ginH["posts"] = posts
ginH["totalPage"] = h.getTotalPage(totalRaw) ginH["totalPage"] = h.getTotalPage(totalRaw)
ginH["currentPage"] = h.page ginH["currentPage"] = h.page
ginH["title"] = h.getTitle() ginH["title"] = h.getTitle()

View File

@ -3,6 +3,7 @@ package cache
import ( import (
"context" "context"
"github.com/fthvgb1/wp-go/cache" "github.com/fthvgb1/wp-go/cache"
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/config" "github.com/fthvgb1/wp-go/internal/pkg/config"
"github.com/fthvgb1/wp-go/internal/pkg/dao" "github.com/fthvgb1/wp-go/internal/pkg/dao"
"github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/logs"
@ -11,7 +12,7 @@ import (
"time" "time"
) )
var postContextCache *cache.MapCache[uint64, common.PostContext] var postContextCache *cache.MapCache[uint64, dao.PostContext]
var archivesCaches *Arch var archivesCaches *Arch
var categoryCaches *cache.VarCache[[]models.TermsMy] var categoryCaches *cache.VarCache[[]models.TermsMy]
var recentPostsCaches *cache.VarCache[[]models.Posts] var recentPostsCaches *cache.VarCache[[]models.Posts]
@ -22,8 +23,8 @@ var postsCache *cache.MapCache[uint64, models.Posts]
var postMetaCache *cache.MapCache[uint64, map[string]any] var postMetaCache *cache.MapCache[uint64, map[string]any]
var monthPostsCache *cache.MapCache[string, []uint64] var monthPostsCache *cache.MapCache[string, []uint64]
var postListIdsCache *cache.MapCache[string, common.PostIds] var postListIdsCache *cache.MapCache[string, dao.PostIds]
var searchPostIdsCache *cache.MapCache[string, common.PostIds] var searchPostIdsCache *cache.MapCache[string, dao.PostIds]
var maxPostIdCache *cache.VarCache[uint64] var maxPostIdCache *cache.VarCache[uint64]
var usersCache *cache.MapCache[uint64, models.Users] var usersCache *cache.MapCache[uint64, models.Users]
@ -38,40 +39,44 @@ var commentsFeedCache *cache.VarCache[[]string]
var newCommentCache *cache.MapCache[string, string] var newCommentCache *cache.MapCache[string, string]
var allUsernameCache *cache.VarCache[map[string]struct{}]
var allCategories *cache.VarCache[map[string]struct{}]
func InitActionsCommonCache() { func InitActionsCommonCache() {
c := config.Conf.Load() c := config.Conf.Load()
archivesCaches = &Arch{ archivesCaches = &Arch{
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
setCacheFunc: common.Archives, setCacheFunc: dao.Archives,
} }
searchPostIdsCache = cache.NewMapCacheByFn[string](common.SearchPostIds, c.SearchPostCacheTime) searchPostIdsCache = cache.NewMapCacheByFn[string](dao.SearchPostIds, c.SearchPostCacheTime)
postListIdsCache = cache.NewMapCacheByFn[string](common.SearchPostIds, c.PostListCacheTime) postListIdsCache = cache.NewMapCacheByFn[string](dao.SearchPostIds, c.PostListCacheTime)
monthPostsCache = cache.NewMapCacheByFn[string](common.MonthPost, c.MonthPostCacheTime) monthPostsCache = cache.NewMapCacheByFn[string](dao.MonthPost, c.MonthPostCacheTime)
postContextCache = cache.NewMapCacheByFn[uint64](common.GetPostContext, c.ContextPostCacheTime) postContextCache = cache.NewMapCacheByFn[uint64](dao.GetPostContext, c.ContextPostCacheTime)
postsCache = cache.NewMapCacheByBatchFn(common.GetPostsByIds, c.PostDataCacheTime) postsCache = cache.NewMapCacheByBatchFn(dao.GetPostsByIds, c.PostDataCacheTime)
postMetaCache = cache.NewMapCacheByBatchFn(common.GetPostMetaByPostIds, c.PostDataCacheTime) postMetaCache = cache.NewMapCacheByBatchFn(dao.GetPostMetaByPostIds, c.PostDataCacheTime)
categoryCaches = cache.NewVarCache(common.Categories, c.CategoryCacheTime) categoryCaches = cache.NewVarCache(dao.Categories, c.CategoryCacheTime)
recentPostsCaches = cache.NewVarCache(common.RecentPosts, c.RecentPostCacheTime) recentPostsCaches = cache.NewVarCache(dao.RecentPosts, c.RecentPostCacheTime)
recentCommentsCaches = cache.NewVarCache(common.RecentComments, c.RecentCommentsCacheTime) recentCommentsCaches = cache.NewVarCache(dao.RecentComments, c.RecentCommentsCacheTime)
postCommentCaches = cache.NewMapCacheByFn[uint64](common.PostComments, c.PostCommentsCacheTime) postCommentCaches = cache.NewMapCacheByFn[uint64](dao.PostComments, c.PostCommentsCacheTime)
maxPostIdCache = cache.NewVarCache(common.GetMaxPostId, c.MaxPostIdCacheTime) maxPostIdCache = cache.NewVarCache(dao.GetMaxPostId, c.MaxPostIdCacheTime)
usersCache = cache.NewMapCacheByFn[uint64](common.GetUserById, c.UserInfoCacheTime) usersCache = cache.NewMapCacheByFn[uint64](dao.GetUserById, c.UserInfoCacheTime)
usersNameCache = cache.NewMapCacheByFn[string](common.GetUserByName, c.UserInfoCacheTime) usersNameCache = cache.NewMapCacheByFn[string](dao.GetUserByName, c.UserInfoCacheTime)
commentsCache = cache.NewMapCacheByBatchFn(common.GetCommentByIds, c.CommentsCacheTime) commentsCache = cache.NewMapCacheByBatchFn(dao.GetCommentByIds, c.CommentsCacheTime)
feedCache = cache.NewVarCache(feed, time.Hour) feedCache = cache.NewVarCache(feed, time.Hour)
@ -81,6 +86,15 @@ func InitActionsCommonCache() {
newCommentCache = cache.NewMapCacheByFn[string, string](nil, 15*time.Minute) newCommentCache = cache.NewMapCacheByFn[string, string](nil, 15*time.Minute)
allUsernameCache = cache.NewVarCache(dao.AllUsername, c.UserInfoCacheTime)
allCategories = cache.NewVarCache(func(a ...any) (map[string]struct{}, error) {
ctx := a[0].(context.Context)
return slice.ToMap(Categories(ctx), func(v models.TermsMy) (string, struct{}) {
return v.Name, struct{}{}
}, true), nil
}, c.CategoryCacheTime)
InitFeed() InitFeed()
} }
@ -141,6 +155,11 @@ func (c *Arch) getArchiveCache(ctx context.Context) []models.PostArchive {
func Categories(ctx context.Context) []models.TermsMy { func Categories(ctx context.Context) []models.TermsMy {
r, err := categoryCaches.GetCache(ctx, time.Second, ctx) r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
logs.ErrPrintln(err, "get category ") logs.ErrPrintln(err, "get category err")
return r
}
func AllCategoryNames(ctx context.Context) map[string]struct{} {
r, _ := allCategories.GetCache(ctx, time.Second, ctx)
return r return r
} }

View File

@ -19,6 +19,10 @@ func GetUserByName(ctx context.Context, username string) (models.Users, error) {
return usersNameCache.GetCache(ctx, username, time.Second, ctx, username) return usersNameCache.GetCache(ctx, username, time.Second, ctx, username)
} }
func GetAllUsername(ctx context.Context) (map[string]struct{}, error) {
return allUsernameCache.GetCache(ctx, time.Second, ctx)
}
func GetUserById(ctx context.Context, uid uint64) models.Users { func GetUserById(ctx context.Context, uid uint64) models.Users {
r, err := usersCache.GetCache(ctx, uid, time.Second, ctx, uid) r, err := usersCache.GetCache(ctx, uid, time.Second, ctx, uid)
logs.ErrPrintln(err, "get user", uid) logs.ErrPrintln(err, "get user", uid)

View File

@ -1,4 +1,4 @@
package common package dao
import ( import (
"context" "context"

View File

@ -1,9 +1,9 @@
package common package dao
import ( import (
"context" "context"
"fmt" "fmt"
models2 "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/wpconfig" "github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/model" "github.com/fthvgb1/wp-go/model"
) )
@ -16,20 +16,20 @@ type PostIds struct {
} }
type PostContext struct { type PostContext struct {
Prev models2.Posts Prev models.Posts
Next models2.Posts Next models.Posts
} }
func PasswordProjectTitle(post *models2.Posts) { func PasswordProjectTitle(post *models.Posts) {
if post.PostPassword != "" { if post.PostPassword != "" {
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle) post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
} }
} }
func Categories(a ...any) (terms []models2.TermsMy, err error) { func Categories(a ...any) (terms []models.TermsMy, err error) {
ctx := a[0].(context.Context) ctx := a[0].(context.Context)
var in = []any{"category"} var in = []any{"category"}
terms, err = model.Find[models2.TermsMy](ctx, model.SqlBuilder{ terms, err = model.Find[models.TermsMy](ctx, model.SqlBuilder{
{"tt.count", ">", "0", "int"}, {"tt.count", ">", "0", "int"},
{"tt.taxonomy", "in", ""}, {"tt.taxonomy", "in", ""},
}, "t.term_id", "", model.SqlBuilder{ }, "t.term_id", "", model.SqlBuilder{
@ -48,8 +48,8 @@ func Categories(a ...any) (terms []models2.TermsMy, err error) {
return return
} }
func Archives(ctx context.Context) ([]models2.PostArchive, error) { func Archives(ctx context.Context) ([]models.PostArchive, error) {
return model.Find[models2.PostArchive](ctx, model.SqlBuilder{ return model.Find[models.PostArchive](ctx, model.SqlBuilder{
{"post_type", "post"}, {"post_status", "publish"}, {"post_type", "post"}, {"post_status", "publish"},
}, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", model.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0) }, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", model.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0)
} }

View File

@ -1,4 +1,4 @@
package common package dao
import ( import (
"context" "context"

View File

@ -1,4 +1,4 @@
package common package dao
import ( import (
"context" "context"

View File

@ -1,7 +1,8 @@
package common package dao
import ( import (
"context" "context"
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/model" "github.com/fthvgb1/wp-go/model"
) )
@ -13,6 +14,19 @@ func GetUserById(a ...any) (r models.Users, err error) {
return return
} }
func AllUsername(a ...any) (map[string]struct{}, error) {
ctx := a[0].(context.Context)
r, err := model.SimpleFind[models.Users](ctx, model.SqlBuilder{
{"user_status", "=", "0", "int"},
}, "user_login")
if err != nil {
return nil, err
}
return slice.ToMap(r, func(t models.Users) (string, struct{}) {
return t.UserLogin, struct{}{}
}, true), nil
}
func GetUserByName(a ...any) (r models.Users, err error) { func GetUserByName(a ...any) (r models.Users, err error) {
u := a[1].(string) u := a[1].(string)
ctx := a[0].(context.Context) ctx := a[0].(context.Context)

View File

@ -36,7 +36,7 @@ func digestRaw(arg ...any) (string, error) {
return digest.Raw(str, limit, fmt.Sprintf("/p/%d", id)), nil return digest.Raw(str, limit, fmt.Sprintf("/p/%d", id)), nil
} }
func Digest(p *Plugin[models.Posts], c *gin.Context, post *models.Posts, scene uint) { func Digest(p *Plugin[models.Posts], c *gin.Context, post *models.Posts, scene int) {
if scene == Detail { if scene == Detail {
return return
} }

View File

@ -10,7 +10,11 @@ const (
Category Category
Search Search
Detail Detail
Ok
Empty404 Empty404
Error
InternalErr
) )
var IndexSceneMap = map[int]struct{}{ var IndexSceneMap = map[int]struct{}{
@ -20,22 +24,17 @@ var IndexSceneMap = map[int]struct{}{
Search: {}, Search: {},
} }
var DetailSceneMap = map[int]struct{}{ type Func[T any] func(*Plugin[T], *gin.Context, *T, int)
Detail: {},
Empty404: {},
}
type Func[T any] func(*Plugin[T], *gin.Context, *T, uint)
type Plugin[T any] struct { type Plugin[T any] struct {
calls []Func[T] calls []Func[T]
index int index int
post *T post *T
scene uint scene int
c *gin.Context c *gin.Context
} }
func NewPlugin[T any](calls []Func[T], index int, post *T, scene uint, c *gin.Context) *Plugin[T] { func NewPlugin[T any](calls []Func[T], index int, post *T, scene int, c *gin.Context) *Plugin[T] {
return &Plugin[T]{calls: calls, index: index, post: post, scene: scene, c: c} return &Plugin[T]{calls: calls, index: index, post: post, scene: scene, c: c}
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.Posts] { func NewPostPlugin(ctx *gin.Context, scene int) *Plugin[models.Posts] {
p := NewPlugin[models.Posts](nil, -1, nil, scene, ctx) p := NewPlugin[models.Posts](nil, -1, nil, scene, ctx)
p.Push(Digest) p.Push(Digest)
return p return p

View File

@ -1,24 +1,26 @@
package theme package theme
import ( import (
"errors"
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/plugins" "github.com/fthvgb1/wp-go/internal/plugins"
"github.com/fthvgb1/wp-go/plugin/pagination" "github.com/fthvgb1/wp-go/plugin/pagination"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
var themeMap = map[string]func(int, *gin.Context, gin.H, int){} var themeMap = map[string]func(int, *gin.Context, gin.H, int, int){}
func AddThemeHookFunc(name string, fn func(int, *gin.Context, gin.H, int)) { func AddThemeHookFunc(name string, fn func(int, *gin.Context, gin.H, int, int)) {
if _, ok := themeMap[name]; ok { if _, ok := themeMap[name]; ok {
panic("exists same name theme") panic("exists same name theme")
} }
themeMap[name] = fn themeMap[name] = fn
} }
func Hook(themeName string, status int, c *gin.Context, h gin.H, scene int) { func Hook(themeName string, code int, c *gin.Context, h gin.H, scene, status int) {
fn, ok := themeMap[themeName] fn, ok := themeMap[themeName]
if ok && fn != nil { if ok && fn != nil {
fn(status, c, h, scene) fn(code, c, h, scene, status)
return return
} }
if _, ok := plugins.IndexSceneMap[scene]; ok { if _, ok := plugins.IndexSceneMap[scene]; ok {
@ -29,11 +31,11 @@ func Hook(themeName string, status int, c *gin.Context, h gin.H, scene int) {
h["pagination"] = pagination.Paginate(plugins.TwentyFifteenPagination(), pp) h["pagination"] = pagination.Paginate(plugins.TwentyFifteenPagination(), pp)
} }
} }
c.HTML(status, "twentyfifteen/posts/index.gohtml", h) c.HTML(code, "twentyfifteen/posts/index.gohtml", h)
return return
} else if _, ok := plugins.DetailSceneMap[scene]; ok { } else if scene == plugins.Detail {
c.HTML(status, "twentyfifteen/posts/detail.gohtml", h) c.HTML(code, "twentyfifteen/posts/detail.gohtml", h)
return return
} }
c.HTML(status, "twentyfifteen/posts/index.gohtml", h) logs.ErrPrintln(errors.New("what happening"), " how reached here", themeName, code, h, scene, status)
} }

View File

@ -40,7 +40,7 @@ var paginate = func() plugins.PageEle {
return p return p
}() }()
func Hook(status int, c *gin.Context, h gin.H, scene int) { func Hook(status int, c *gin.Context, h gin.H, scene, stats int) {
templ := "twentyseventeen/posts/index.gohtml" templ := "twentyseventeen/posts/index.gohtml"
if _, ok := plugins.IndexSceneMap[scene]; ok { if _, ok := plugins.IndexSceneMap[scene]; ok {
h["HeaderImage"] = getHeaderImage(c) h["HeaderImage"] = getHeaderImage(c)
@ -51,7 +51,7 @@ func Hook(status int, c *gin.Context, h gin.H, scene int) {
h["pagination"] = pagination.Paginate(paginate, pp) h["pagination"] = pagination.Paginate(paginate, pp)
} }
} }
} else if _, ok := plugins.DetailSceneMap[scene]; ok { } else if scene == plugins.Detail {
templ = "twentyseventeen/posts/detail.gohtml" templ = "twentyseventeen/posts/detail.gohtml"
} }
c.HTML(status, templ, h) c.HTML(status, templ, h)