优化代码

This commit is contained in:
xing 2023-02-28 23:59:17 +08:00
parent 7d27668159
commit 4d50f60c62
4 changed files with 45 additions and 18 deletions

View File

@ -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.CalMultipleComponents()
h.CalBodyClass()
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)
}

View File

@ -101,9 +101,12 @@ func (d *DetailHandle) ContextPost() {
}
func (d *DetailHandle) Render() {
d.PasswordProject()
d.RenderComment()
d.ginH["post"] = d.Post
d.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
d.PasswordProject()
d.RenderComment()
d.ginH["post"] = d.Post
}, 10))
d.Handle.Render()
}

View File

@ -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.ExecPostsPlugin()
i.Pagination()
i.PushHandleFn(constraints.Ok, NewHandleFn(func(h *Handle) {
i.ExecPostsPlugin()
i.Pagination()
}, 10))
i.Handle.Render()
}

View File

@ -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)
}