优化代码
This commit is contained in:
parent
7d27668159
commit
4d50f60c62
@ -174,11 +174,17 @@ func (h *Handle) PreCodeAndStats() {
|
||||
func (h *Handle) Render() {
|
||||
h.PreCodeAndStats()
|
||||
h.PreTemplate()
|
||||
h.ExecHandleFns()
|
||||
h.PushHeadScript(Components{CalSiteIcon, 10}, Components{CalCustomCss, -1})
|
||||
h.AddComponent("customLogo", CalCustomLogo)
|
||||
|
||||
h.PushHeadScript(Components{CalSiteIcon, 100}, Components{CalCustomCss, 0})
|
||||
|
||||
h.PushHandleFn(constraints.AllStats, NewHandleFn(func(h *Handle) {
|
||||
h.CalMultipleComponents()
|
||||
h.CalBodyClass()
|
||||
}, 5))
|
||||
|
||||
h.ExecHandleFns()
|
||||
|
||||
h.C.HTML(h.Code, h.templ, h.ginH)
|
||||
}
|
||||
|
||||
|
@ -101,9 +101,12 @@ func (d *DetailHandle) ContextPost() {
|
||||
}
|
||||
|
||||
func (d *DetailHandle) Render() {
|
||||
d.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
|
||||
d.PasswordProject()
|
||||
d.RenderComment()
|
||||
d.ginH["post"] = d.Post
|
||||
}, 10))
|
||||
|
||||
d.Handle.Render()
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,25 @@ type IndexHandle struct {
|
||||
*Handle
|
||||
Param *IndexParams
|
||||
Posts []models.Posts
|
||||
PageEle pagination.Elements
|
||||
pageEle pagination.Elements
|
||||
TotalRows int
|
||||
PostsPlugins map[string]Plugin[models.Posts, *Handle]
|
||||
postsPlugins map[string]Plugin[models.Posts, *Handle]
|
||||
}
|
||||
|
||||
func (i *IndexHandle) PageEle() pagination.Elements {
|
||||
return i.pageEle
|
||||
}
|
||||
|
||||
func (i *IndexHandle) SetPageEle(pageEle pagination.Elements) {
|
||||
i.pageEle = pageEle
|
||||
}
|
||||
|
||||
func (i *IndexHandle) PostsPlugins() map[string]Plugin[models.Posts, *Handle] {
|
||||
return i.postsPlugins
|
||||
}
|
||||
|
||||
func (i *IndexHandle) SetPostsPlugins(postsPlugins map[string]Plugin[models.Posts, *Handle]) {
|
||||
i.postsPlugins = postsPlugins
|
||||
}
|
||||
|
||||
func NewIndexHandle(handle *Handle) *IndexHandle {
|
||||
@ -80,15 +96,15 @@ func (i *IndexHandle) GetIndexData() (posts []models.Posts, totalRaw int, err er
|
||||
}
|
||||
|
||||
func (i *IndexHandle) Pagination() {
|
||||
if i.PageEle == nil {
|
||||
i.PageEle = plugins.TwentyFifteenPagination()
|
||||
if i.pageEle == nil {
|
||||
i.pageEle = plugins.TwentyFifteenPagination()
|
||||
}
|
||||
q := i.C.Request.URL.Query().Encode()
|
||||
if q != "" {
|
||||
q = fmt.Sprintf("?%s", q)
|
||||
}
|
||||
paginations := pagination.NewParsePagination(i.TotalRows, i.Param.PageSize, i.Param.Page, i.Param.PaginationStep, q, i.C.Request.URL.Path)
|
||||
i.ginH["pagination"] = pagination.Paginate(i.PageEle, paginations)
|
||||
i.ginH["pagination"] = pagination.Paginate(i.pageEle, paginations)
|
||||
|
||||
}
|
||||
|
||||
@ -115,7 +131,7 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
|
||||
|
||||
pluginConf := config.GetConfig().ListPagePlugins
|
||||
|
||||
postsPlugins := i.PostsPlugins
|
||||
postsPlugins := i.postsPlugins
|
||||
if postsPlugins == nil {
|
||||
postsPlugins = pluginFns
|
||||
}
|
||||
@ -126,8 +142,10 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
|
||||
}
|
||||
|
||||
func (i *IndexHandle) Render() {
|
||||
i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
|
||||
i.ExecPostsPlugin()
|
||||
i.Pagination()
|
||||
}, 10))
|
||||
i.Handle.Render()
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ func Hook(h *common.Handle) {
|
||||
func ready(next common.HandleFn[*common.Handle], h *common.Handle) {
|
||||
h.WidgetAreaData()
|
||||
h.GetPassword()
|
||||
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(calClass, 10))
|
||||
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(calClass, 15))
|
||||
h.PushHeadScript(
|
||||
common.NewComponents(colorScheme, 10),
|
||||
common.NewComponents(customHeader, 10),
|
||||
@ -68,8 +68,8 @@ func index(next common.HandleFn[*common.Handle], i *common.IndexHandle) {
|
||||
i.Render()
|
||||
return
|
||||
}
|
||||
i.PostsPlugins = listPostsPlugins
|
||||
i.PageEle = paginate
|
||||
i.SetPageEle(paginate)
|
||||
i.SetPostsPlugins(listPostsPlugins)
|
||||
next(i.Handle)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user