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