优化代码
This commit is contained in:
parent
cbf3cabb24
commit
7d27668159
@ -12,14 +12,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handle) CalBodyClass() {
|
func (h *Handle) CalBodyClass() {
|
||||||
h.GinH["bodyClass"] = h.BodyClass(h.Class...)
|
h.ginH["bodyClass"] = h.BodyClass(h.class...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) BodyClass(class ...string) string {
|
func (h *Handle) BodyClass(class ...string) string {
|
||||||
if constraints.Ok != h.Stats {
|
if constraints.Ok != h.Stats {
|
||||||
class = append(class, "error404")
|
class = append(class, "error404")
|
||||||
}
|
}
|
||||||
switch h.Scene {
|
switch h.scene {
|
||||||
case constraints.Home:
|
case constraints.Home:
|
||||||
class = append(class, "home", "blog")
|
class = append(class, "home", "blog")
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ func (h *Handle) BodyClass(class ...string) string {
|
|||||||
case constraints.Category, constraints.Tag:
|
case constraints.Category, constraints.Tag:
|
||||||
class = append(class, "archive", "category")
|
class = append(class, "archive", "category")
|
||||||
cat := h.Index.Param.Category
|
cat := h.Index.Param.Category
|
||||||
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.Scene), func(my models.TermsMy) bool {
|
_, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.scene), func(my models.TermsMy) bool {
|
||||||
return my.Name == cat
|
return my.Name == cat
|
||||||
})
|
})
|
||||||
if cate.Slug[0] != '%' {
|
if cate.Slug[0] != '%' {
|
||||||
@ -56,17 +56,17 @@ func (h *Handle) BodyClass(class ...string) string {
|
|||||||
case constraints.Detail:
|
case constraints.Detail:
|
||||||
class = append(class, "post-template-default", "single", "single-post")
|
class = append(class, "post-template-default", "single", "single-post")
|
||||||
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
|
class = append(class, str.Join("postid-", number.ToString(h.Detail.Post.Id)))
|
||||||
if len(h.ThemeMods.ThemeSupport.PostFormats) > 0 {
|
if len(h.themeMods.ThemeSupport.PostFormats) > 0 {
|
||||||
class = append(class, "single-format-standard")
|
class = append(class, "single-format-standard")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if wpconfig.IsCustomBackground(h.Theme) {
|
if wpconfig.IsCustomBackground(h.theme) {
|
||||||
class = append(class, "custom-background")
|
class = append(class, "custom-background")
|
||||||
}
|
}
|
||||||
if h.ThemeMods.CustomLogo > 0 || str.ToInteger(wpconfig.GetOption("site_logo"), 0) > 0 {
|
if h.themeMods.CustomLogo > 0 || str.ToInteger(wpconfig.GetOption("site_logo"), 0) > 0 {
|
||||||
class = append(class, "wp-custom-logo")
|
class = append(class, "wp-custom-logo")
|
||||||
}
|
}
|
||||||
if h.ThemeMods.ThemeSupport.ResponsiveEmbeds {
|
if h.themeMods.ThemeSupport.ResponsiveEmbeds {
|
||||||
class = append(class, "wp-embed-responsive")
|
class = append(class, "wp-embed-responsive")
|
||||||
}
|
}
|
||||||
return strings.Join(class, " ")
|
return strings.Join(class, " ")
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/fthvgb1/wp-go/helper/maps"
|
||||||
"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/cmd/reload"
|
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||||
@ -17,35 +18,23 @@ type Handle struct {
|
|||||||
Index *IndexHandle
|
Index *IndexHandle
|
||||||
Detail *DetailHandle
|
Detail *DetailHandle
|
||||||
C *gin.Context
|
C *gin.Context
|
||||||
Theme string
|
theme string
|
||||||
Session sessions.Session
|
Session sessions.Session
|
||||||
GinH gin.H
|
ginH gin.H
|
||||||
Password string
|
password string
|
||||||
Scene int
|
scene int
|
||||||
Code int
|
Code int
|
||||||
Stats int
|
Stats int
|
||||||
Templ string
|
templ string
|
||||||
Class []string
|
class []string
|
||||||
Components map[string][]Components
|
components map[string][]Components
|
||||||
ThemeMods wpconfig.ThemeMods
|
themeMods wpconfig.ThemeMods
|
||||||
HandleFns map[int][]HandleCall
|
handleFns map[int][]HandleCall
|
||||||
Error error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
func (h *Handle) CommonThemeMods() wpconfig.ThemeMods {
|
||||||
mods, err := wpconfig.GetThemeMods(theme)
|
return h.themeMods
|
||||||
logs.ErrPrintln(err, "获取mods失败")
|
|
||||||
return &Handle{
|
|
||||||
C: c,
|
|
||||||
Theme: theme,
|
|
||||||
Session: sessions.Default(c),
|
|
||||||
GinH: gin.H{},
|
|
||||||
Scene: scene,
|
|
||||||
Stats: constraints.Ok,
|
|
||||||
ThemeMods: mods,
|
|
||||||
Components: make(map[string][]Components),
|
|
||||||
HandleFns: make(map[int][]HandleCall),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Components Order 为执行顺序,降序执行
|
// Components Order 为执行顺序,降序执行
|
||||||
@ -54,12 +43,68 @@ type Components struct {
|
|||||||
Order int
|
Order int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type HandleFn[T any] func(T)
|
||||||
|
|
||||||
|
type HandlePipeFn[T any] func(HandleFn[T], T)
|
||||||
|
|
||||||
|
type HandleCall struct {
|
||||||
|
Fn HandleFn[*Handle]
|
||||||
|
Order int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) Err() error {
|
||||||
|
return h.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) SetErr(err error) {
|
||||||
|
h.err = err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) Password() string {
|
||||||
|
return h.password
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) SetTempl(templ string) {
|
||||||
|
h.templ = templ
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) Scene() int {
|
||||||
|
return h.scene
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) SetDatas(GinH gin.H) {
|
||||||
|
maps.Merge(h.ginH, GinH)
|
||||||
|
}
|
||||||
|
func (h *Handle) SetData(k string, v any) {
|
||||||
|
h.ginH[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) PushClass(class ...string) {
|
||||||
|
h.class = append(h.class, class...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
||||||
|
mods, err := wpconfig.GetThemeMods(theme)
|
||||||
|
logs.ErrPrintln(err, "获取mods失败")
|
||||||
|
return &Handle{
|
||||||
|
C: c,
|
||||||
|
theme: theme,
|
||||||
|
Session: sessions.Default(c),
|
||||||
|
ginH: gin.H{},
|
||||||
|
scene: scene,
|
||||||
|
Stats: constraints.Ok,
|
||||||
|
themeMods: mods,
|
||||||
|
components: make(map[string][]Components),
|
||||||
|
handleFns: make(map[int][]HandleCall),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewComponents(fn func(*Handle) string, order int) Components {
|
func NewComponents(fn func(*Handle) string, order int) Components {
|
||||||
return Components{Fn: fn, Order: order}
|
return Components{Fn: fn, Order: order}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) PushHandleFn(stats int, fns ...HandleCall) {
|
func (h *Handle) PushHandleFn(stats int, fns ...HandleCall) {
|
||||||
h.HandleFns[stats] = append(h.HandleFns[stats], fns...)
|
h.handleFns[stats] = append(h.handleFns[stats], fns...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) AddComponent(name string, fn func(*Handle) string) {
|
func (h *Handle) AddComponent(name string, fn func(*Handle) string) {
|
||||||
@ -68,25 +113,25 @@ func (h *Handle) AddComponent(name string, fn func(*Handle) string) {
|
|||||||
v = fn(h)
|
v = fn(h)
|
||||||
reload.SetStr(name, v)
|
reload.SetStr(name, v)
|
||||||
}
|
}
|
||||||
h.GinH[name] = v
|
h.ginH[name] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) PushHeadScript(fn ...Components) {
|
func (h *Handle) PushHeadScript(fn ...Components) {
|
||||||
h.Components[constraints.HeadScript] = append(h.Components[constraints.HeadScript], fn...)
|
h.components[constraints.HeadScript] = append(h.components[constraints.HeadScript], fn...)
|
||||||
}
|
}
|
||||||
func (h *Handle) PushFooterScript(fn ...Components) {
|
func (h *Handle) PushFooterScript(fn ...Components) {
|
||||||
h.Components[constraints.FooterScript] = append(h.Components[constraints.FooterScript], fn...)
|
h.components[constraints.FooterScript] = append(h.components[constraints.FooterScript], fn...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) GetPassword() {
|
func (h *Handle) GetPassword() {
|
||||||
pw := h.Session.Get("post_password")
|
pw := h.Session.Get("post_password")
|
||||||
if pw != nil {
|
if pw != nil {
|
||||||
h.Password = pw.(string)
|
h.password = pw.(string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) ExecHandleFns() {
|
func (h *Handle) ExecHandleFns() {
|
||||||
calls, ok := h.HandleFns[h.Stats]
|
calls, ok := h.handleFns[h.Stats]
|
||||||
if ok {
|
if ok {
|
||||||
slice.SortSelf(calls, func(i, j HandleCall) bool {
|
slice.SortSelf(calls, func(i, j HandleCall) bool {
|
||||||
return i.Order > j.Order
|
return i.Order > j.Order
|
||||||
@ -95,7 +140,7 @@ func (h *Handle) ExecHandleFns() {
|
|||||||
call.Fn(h)
|
call.Fn(h)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fns, ok := h.HandleFns[constraints.AllStats]
|
fns, ok := h.handleFns[constraints.AllStats]
|
||||||
if ok {
|
if ok {
|
||||||
for _, fn := range fns {
|
for _, fn := range fns {
|
||||||
fn.Fn(h)
|
fn.Fn(h)
|
||||||
@ -105,10 +150,10 @@ func (h *Handle) ExecHandleFns() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) PreTemplate() {
|
func (h *Handle) PreTemplate() {
|
||||||
if h.Templ == "" {
|
if h.templ == "" {
|
||||||
h.Templ = str.Join(h.Theme, "/posts/index.gohtml")
|
h.templ = str.Join(h.theme, "/posts/index.gohtml")
|
||||||
if h.Scene == constraints.Detail {
|
if h.scene == constraints.Detail {
|
||||||
h.Templ = str.Join(h.Theme, "/posts/detail.gohtml")
|
h.templ = str.Join(h.theme, "/posts/detail.gohtml")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,15 +179,15 @@ func (h *Handle) Render() {
|
|||||||
h.AddComponent("customLogo", CalCustomLogo)
|
h.AddComponent("customLogo", CalCustomLogo)
|
||||||
h.CalMultipleComponents()
|
h.CalMultipleComponents()
|
||||||
h.CalBodyClass()
|
h.CalBodyClass()
|
||||||
h.C.HTML(h.Code, h.Templ, h.GinH)
|
h.C.HTML(h.Code, h.templ, h.ginH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) PushComponents(name string, components ...Components) {
|
func (h *Handle) PushComponents(name string, components ...Components) {
|
||||||
h.Components[name] = append(h.Components[name], components...)
|
h.components[name] = append(h.components[name], components...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) CalMultipleComponents() {
|
func (h *Handle) CalMultipleComponents() {
|
||||||
for k, ss := range h.Components {
|
for k, ss := range h.components {
|
||||||
v, ok := reload.GetStr(k)
|
v, ok := reload.GetStr(k)
|
||||||
if !ok {
|
if !ok {
|
||||||
slice.SortSelf(ss, func(i, j Components) bool {
|
slice.SortSelf(ss, func(i, j Components) bool {
|
||||||
@ -154,19 +199,10 @@ func (h *Handle) CalMultipleComponents() {
|
|||||||
}), "\n")
|
}), "\n")
|
||||||
reload.SetStr(k, v)
|
reload.SetStr(k, v)
|
||||||
}
|
}
|
||||||
h.GinH[k] = v
|
h.ginH[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandleFn[T any] func(T)
|
|
||||||
|
|
||||||
type HandlePipeFn[T any] func(HandleFn[T], T)
|
|
||||||
|
|
||||||
type HandleCall struct {
|
|
||||||
Fn HandleFn[*Handle]
|
|
||||||
Order int
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHandleFn(fn HandleFn[*Handle], order int) HandleCall {
|
func NewHandleFn(fn HandleFn[*Handle], order int) HandleCall {
|
||||||
return HandleCall{Fn: fn, Order: order}
|
return HandleCall{Fn: fn, Order: order}
|
||||||
}
|
}
|
||||||
@ -181,7 +217,7 @@ func HandlePipe[T any](initial func(T), fns ...HandlePipeFn[T]) HandleFn[T] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Render(h *Handle) {
|
func Render(h *Handle) {
|
||||||
switch h.Scene {
|
switch h.scene {
|
||||||
case constraints.Detail:
|
case constraints.Detail:
|
||||||
h.Detail.Render()
|
h.Detail.Render()
|
||||||
default:
|
default:
|
||||||
|
@ -7,10 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CalCustomCss(h *Handle) (r string) {
|
func CalCustomCss(h *Handle) (r string) {
|
||||||
if h.ThemeMods.CustomCssPostId < 1 {
|
if h.themeMods.CustomCssPostId < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post, err := cache.GetPostById(h.C, uint64(h.ThemeMods.CustomCssPostId))
|
post, err := cache.GetPostById(h.C, uint64(h.themeMods.CustomCssPostId))
|
||||||
if err != nil || post.Id < 1 {
|
if err != nil || post.Id < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handle) DisplayHeaderText() bool {
|
func (h *Handle) DisplayHeaderText() bool {
|
||||||
return h.ThemeMods.ThemeSupport.CustomHeader.HeaderText && "blank" != h.ThemeMods.HeaderTextcolor
|
return h.themeMods.ThemeSupport.CustomHeader.HeaderText && "blank" != h.themeMods.HeaderTextcolor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) GetCustomHeader() (r models.PostThumbnail, isRand bool) {
|
func (h *Handle) GetCustomHeader() (r models.PostThumbnail, isRand bool) {
|
||||||
hs, err := cache.GetHeaderImages(h.C, h.Theme)
|
hs, err := cache.GetHeaderImages(h.C, h.theme)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.ErrPrintln(err, "获取页眉背景图失败")
|
logs.ErrPrintln(err, "获取页眉背景图失败")
|
||||||
return
|
return
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func CalCustomLogo(h *Handle) (r string) {
|
func CalCustomLogo(h *Handle) (r string) {
|
||||||
id := uint64(h.ThemeMods.CustomLogo)
|
id := uint64(h.themeMods.CustomLogo)
|
||||||
if id < 1 {
|
if id < 1 {
|
||||||
id = str.ToInteger[uint64](wpconfig.GetOption("site_logo"), 0)
|
id = str.ToInteger[uint64](wpconfig.GetOption("site_logo"), 0)
|
||||||
if id < 1 {
|
if id < 1 {
|
||||||
|
@ -24,7 +24,7 @@ func NewDetailHandle(handle *Handle) *DetailHandle {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) BuildDetailData() (err error) {
|
func (d *DetailHandle) BuildDetailData() (err error) {
|
||||||
d.GinH["title"] = wpconfig.GetOption("blogname")
|
d.ginH["title"] = wpconfig.GetOption("blogname")
|
||||||
err = d.CheckAndGetPost()
|
err = d.CheckAndGetPost()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -41,7 +41,7 @@ func (d *DetailHandle) CheckAndGetPost() (err error) {
|
|||||||
if id > maxId || id <= 0 {
|
if id > maxId || id <= 0 {
|
||||||
d.Stats = constraints.ParamError
|
d.Stats = constraints.ParamError
|
||||||
err = errors.New("无效的文档id")
|
err = errors.New("无效的文档id")
|
||||||
d.Class = append(d.Class, "error404")
|
d.class = append(d.class, "error404")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -55,24 +55,24 @@ func (d *DetailHandle) CheckAndGetPost() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
d.Post = post
|
d.Post = post
|
||||||
d.GinH["user"] = cache.GetUserById(d.C, post.PostAuthor)
|
d.ginH["user"] = cache.GetUserById(d.C, post.PostAuthor)
|
||||||
d.GinH["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.GetOption("blogname"))
|
d.ginH["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.GetOption("blogname"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) PasswordProject() {
|
func (d *DetailHandle) PasswordProject() {
|
||||||
if d.Post.PostPassword != "" {
|
if d.Post.PostPassword != "" {
|
||||||
plugins.PasswordProjectTitle(&d.Post)
|
plugins.PasswordProjectTitle(&d.Post)
|
||||||
if d.Password != d.Post.PostPassword {
|
if d.password != d.Post.PostPassword {
|
||||||
plugins.PasswdProjectContent(&d.Post)
|
plugins.PasswdProjectContent(&d.Post)
|
||||||
}
|
}
|
||||||
d.GinH["post"] = d.Post
|
d.ginH["post"] = d.Post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (d *DetailHandle) Comment() {
|
func (d *DetailHandle) Comment() {
|
||||||
comments, err := cache.PostComments(d.C, d.Post.Id)
|
comments, err := cache.PostComments(d.C, d.Post.Id)
|
||||||
logs.ErrPrintln(err, "get d.Post comment", d.Post.Id)
|
logs.ErrPrintln(err, "get d.Post comment", d.Post.Id)
|
||||||
d.GinH["comments"] = comments
|
d.ginH["comments"] = comments
|
||||||
d.Comments = comments
|
d.Comments = comments
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -83,27 +83,27 @@ func (d *DetailHandle) RenderComment() {
|
|||||||
}
|
}
|
||||||
ableComment := true
|
ableComment := true
|
||||||
if d.Post.CommentStatus != "open" ||
|
if d.Post.CommentStatus != "open" ||
|
||||||
(d.Post.PostPassword != "" && d.Password != d.Post.PostPassword) {
|
(d.Post.PostPassword != "" && d.password != d.Post.PostPassword) {
|
||||||
ableComment = false
|
ableComment = false
|
||||||
}
|
}
|
||||||
d.GinH["showComment"] = ableComment
|
d.ginH["showComment"] = ableComment
|
||||||
if len(d.Comments) > 0 && ableComment {
|
if len(d.Comments) > 0 && ableComment {
|
||||||
dep := str.ToInteger(wpconfig.GetOption("thread_comments_depth"), 5)
|
dep := str.ToInteger(wpconfig.GetOption("thread_comments_depth"), 5)
|
||||||
d.GinH["comments"] = plugins.FormatComments(d.C, d.CommentRender, d.Comments, dep)
|
d.ginH["comments"] = plugins.FormatComments(d.C, d.CommentRender, d.Comments, dep)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) ContextPost() {
|
func (d *DetailHandle) ContextPost() {
|
||||||
prev, next, err := cache.GetContextPost(d.C, d.Post.Id, d.Post.PostDate)
|
prev, next, err := cache.GetContextPost(d.C, d.Post.Id, d.Post.PostDate)
|
||||||
logs.ErrPrintln(err, "get pre and next post", d.Post.Id, d.Post.PostDate)
|
logs.ErrPrintln(err, "get pre and next post", d.Post.Id, d.Post.PostDate)
|
||||||
d.GinH["next"] = next
|
d.ginH["next"] = next
|
||||||
d.GinH["prev"] = prev
|
d.ginH["prev"] = prev
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) Render() {
|
func (d *DetailHandle) Render() {
|
||||||
d.PasswordProject()
|
d.PasswordProject()
|
||||||
d.RenderComment()
|
d.RenderComment()
|
||||||
d.GinH["post"] = d.Post
|
d.ginH["post"] = d.Post
|
||||||
d.Handle.Render()
|
d.Handle.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func NewIndexHandle(handle *Handle) *IndexHandle {
|
|||||||
|
|
||||||
func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
|
func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
|
||||||
i.Param = parm
|
i.Param = parm
|
||||||
switch i.Scene {
|
switch i.scene {
|
||||||
case constraints.Home, constraints.Search:
|
case constraints.Home, constraints.Search:
|
||||||
i.Param.ParseSearch()
|
i.Param.ParseSearch()
|
||||||
case constraints.Category:
|
case constraints.Category:
|
||||||
@ -47,9 +47,9 @@ func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
|
|||||||
}
|
}
|
||||||
i.Param.ParseParams()
|
i.Param.ParseParams()
|
||||||
i.Param.CacheKey = i.Param.getSearchKey()
|
i.Param.CacheKey = i.Param.getSearchKey()
|
||||||
i.GinH["title"] = i.Param.getTitle()
|
i.ginH["title"] = i.Param.getTitle()
|
||||||
i.GinH["search"] = i.Param.Search
|
i.ginH["search"] = i.Param.Search
|
||||||
i.GinH["header"] = i.Param.Header
|
i.ginH["header"] = i.Param.Header
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func (i *IndexHandle) GetIndexData() (posts []models.Posts, totalRaw int, err er
|
|||||||
Join: i.Param.Join,
|
Join: i.Param.Join,
|
||||||
In: [][]any{i.Param.PostType, i.Param.PostStatus},
|
In: [][]any{i.Param.PostType, i.Param.PostStatus},
|
||||||
}
|
}
|
||||||
switch i.Scene {
|
switch i.scene {
|
||||||
case constraints.Home, constraints.Category, constraints.Tag, constraints.Author:
|
case constraints.Home, constraints.Category, constraints.Tag, constraints.Author:
|
||||||
|
|
||||||
posts, totalRaw, err = cache.PostLists(i.C, i.Param.CacheKey, i.C, q, i.Param.Page, i.Param.PageSize)
|
posts, totalRaw, err = cache.PostLists(i.C, i.Param.CacheKey, i.C, q, i.Param.Page, i.Param.PageSize)
|
||||||
@ -88,7 +88,7 @@ func (i *IndexHandle) Pagination() {
|
|||||||
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) {
|
|||||||
i.Posts = posts
|
i.Posts = posts
|
||||||
i.TotalRows = totalRows
|
i.TotalRows = totalRows
|
||||||
|
|
||||||
i.GinH["totalPage"] = number.CalTotalPage(totalRows, i.Param.PageSize)
|
i.ginH["totalPage"] = number.CalTotalPage(totalRows, i.Param.PageSize)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -121,7 +121,7 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
|
|||||||
}
|
}
|
||||||
plugin := GetListPostPlugins(pluginConf, postsPlugins)
|
plugin := GetListPostPlugins(pluginConf, postsPlugins)
|
||||||
|
|
||||||
i.GinH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts](plugin, i.Handle, Defaults(calls...)))
|
i.ginH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts](plugin, i.Handle, Defaults(calls...)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func PasswordProject(next Fn[models.Posts], h *Handle, post models.Posts) (r mod
|
|||||||
r = post
|
r = post
|
||||||
if post.PostPassword != "" {
|
if post.PostPassword != "" {
|
||||||
plugins.PasswordProjectTitle(&r)
|
plugins.PasswordProjectTitle(&r)
|
||||||
if h.Password != post.PostPassword {
|
if h.password != post.PostPassword {
|
||||||
plugins.PasswdProjectContent(&r)
|
plugins.PasswdProjectContent(&r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ func (i *IndexHandle) ExecListPagePlugin(m map[string]Plugin[models.Posts, *Hand
|
|||||||
|
|
||||||
plugin := GetListPostPlugins(pluginConf, m)
|
plugin := GetListPostPlugins(pluginConf, m)
|
||||||
|
|
||||||
i.GinH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts, *Handle](plugin, i.Handle, Defaults(calls...)))
|
i.ginH["posts"] = slice.Map(i.Posts, PluginFn[models.Posts, *Handle](plugin, i.Handle, Defaults(calls...)))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,12 @@
|
|||||||
{{end}}
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{define "common/footer"}}
|
||||||
|
{{if .footerScript}}
|
||||||
|
{{.footerScript|unescaped}}
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{define "common/customLogo"}}
|
{{define "common/customLogo"}}
|
||||||
{{if .customLogo}}
|
{{if .customLogo}}
|
||||||
{{.customLogo|unescaped}}
|
{{.customLogo|unescaped}}
|
||||||
|
@ -7,8 +7,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handle) WidgetAreaData() {
|
func (h *Handle) WidgetAreaData() {
|
||||||
h.GinH["archives"] = cache.Archives(h.C)
|
h.ginH["archives"] = cache.Archives(h.C)
|
||||||
h.GinH["recentPosts"] = slice.Map(cache.RecentPosts(h.C, 5), ProjectTitle)
|
h.ginH["recentPosts"] = slice.Map(cache.RecentPosts(h.C, 5), ProjectTitle)
|
||||||
h.GinH["categories"] = cache.CategoriesTags(h.C, constraints.Category)
|
h.ginH["categories"] = cache.CategoriesTags(h.C, constraints.Category)
|
||||||
h.GinH["recentComments"] = cache.RecentComments(h.C, 5)
|
h.ginH["recentComments"] = cache.RecentComments(h.C, 5)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func colorSchemeCss(h *common.Handle) string {
|
|||||||
}
|
}
|
||||||
func calColorSchemeCss(h *common.Handle) (r string) {
|
func calColorSchemeCss(h *common.Handle) (r string) {
|
||||||
color := getColorScheme(h)
|
color := getColorScheme(h)
|
||||||
if "default" == h.ThemeMods.ColorScheme || len(color) < 1 {
|
if "default" == h.CommonThemeMods().ColorScheme || len(color) < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
textColorRgb := slice.ToAnySlice(Hex2RgbUint8(color[3]))
|
textColorRgb := slice.ToAnySlice(Hex2RgbUint8(color[3]))
|
||||||
@ -48,29 +48,31 @@ func calColorSchemeCss(h *common.Handle) (r string) {
|
|||||||
|
|
||||||
func calSidebarTextColorCss(h *common.Handle) (r string) {
|
func calSidebarTextColorCss(h *common.Handle) (r string) {
|
||||||
colors := getColorScheme(h)
|
colors := getColorScheme(h)
|
||||||
if h.ThemeMods.SidebarTextcolor == "" || h.ThemeMods.SidebarTextcolor == colors[4] {
|
themeMods := h.CommonThemeMods()
|
||||||
|
if themeMods.SidebarTextcolor == "" || themeMods.SidebarTextcolor == colors[4] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
linkColorRgb := Hex2RgbUint8(h.ThemeMods.SidebarTextcolor)
|
linkColorRgb := Hex2RgbUint8(themeMods.SidebarTextcolor)
|
||||||
color := slice.ToAnySlice(linkColorRgb)
|
color := slice.ToAnySlice(linkColorRgb)
|
||||||
textColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.7)`, color...)
|
textColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.7)`, color...)
|
||||||
borderColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.1)`, color...)
|
borderColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.1)`, color...)
|
||||||
borderFocusColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.3)`, color...)
|
borderFocusColor := fmt.Sprintf(`rgba( %[1]v, %[2]v, %[3]v, 0.3)`, color...)
|
||||||
r = fmt.Sprintf(sidebarTextColorTemplate, h.ThemeMods.SidebarTextcolor, textColor, borderColor, borderFocusColor)
|
r = fmt.Sprintf(sidebarTextColorTemplate, themeMods.SidebarTextcolor, textColor, borderColor, borderFocusColor)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func calHeaderBackgroundColorCss(h *common.Handle) (r string) {
|
func calHeaderBackgroundColorCss(h *common.Handle) (r string) {
|
||||||
colors := getColorScheme(h)
|
colors := getColorScheme(h)
|
||||||
if h.ThemeMods.HeaderBackgroundColor == "" || h.ThemeMods.HeaderBackgroundColor == colors[1] {
|
themeMods := h.CommonThemeMods()
|
||||||
|
if themeMods.HeaderBackgroundColor == "" || themeMods.HeaderBackgroundColor == colors[1] {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r = fmt.Sprintf(headerBackgroundColorCssTemplate, h.ThemeMods.HeaderBackgroundColor, h.ThemeMods.HeaderBackgroundColor)
|
r = fmt.Sprintf(headerBackgroundColorCssTemplate, themeMods.HeaderBackgroundColor, themeMods.HeaderBackgroundColor)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getColorScheme(h *common.Handle) (r []string) {
|
func getColorScheme(h *common.Handle) (r []string) {
|
||||||
x, ok := colorscheme[h.ThemeMods.ColorScheme]
|
x, ok := colorscheme[h.CommonThemeMods().ColorScheme]
|
||||||
if ok {
|
if ok {
|
||||||
r = x.Colors
|
r = x.Colors
|
||||||
}
|
}
|
||||||
|
@ -31,29 +31,30 @@ var repeat = map[string]string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func CalCustomBackGround(h *common.Handle) (r string) {
|
func CalCustomBackGround(h *common.Handle) (r string) {
|
||||||
if h.ThemeMods.BackgroundImage == "" && h.ThemeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor {
|
themeMods := h.CommonThemeMods()
|
||||||
|
if themeMods.BackgroundImage == "" && themeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s := str.NewBuilder()
|
s := str.NewBuilder()
|
||||||
if h.ThemeMods.BackgroundImage != "" {
|
if themeMods.BackgroundImage != "" {
|
||||||
s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(h.ThemeMods.BackgroundImage))
|
s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(themeMods.BackgroundImage))
|
||||||
}
|
}
|
||||||
backgroundPositionX := helper.Defaults(h.ThemeMods.BackgroundPositionX, themesupport.CustomBackground.DefaultPositionX)
|
backgroundPositionX := helper.Defaults(themeMods.BackgroundPositionX, themesupport.CustomBackground.DefaultPositionX)
|
||||||
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
|
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
|
||||||
|
|
||||||
backgroundPositionY := helper.Defaults(h.ThemeMods.BackgroundPositionY, themesupport.CustomBackground.DefaultPositionY)
|
backgroundPositionY := helper.Defaults(themeMods.BackgroundPositionY, themesupport.CustomBackground.DefaultPositionY)
|
||||||
backgroundPositionY = maps.WithDefaultVal(posty, backgroundPositionY, "top")
|
backgroundPositionY = maps.WithDefaultVal(posty, backgroundPositionY, "top")
|
||||||
positon := fmt.Sprintf(" background-position: %s %s;", backgroundPositionX, backgroundPositionY)
|
positon := fmt.Sprintf(" background-position: %s %s;", backgroundPositionX, backgroundPositionY)
|
||||||
|
|
||||||
siz := helper.DefaultVal(h.ThemeMods.BackgroundSize, themesupport.CustomBackground.DefaultSize)
|
siz := helper.DefaultVal(themeMods.BackgroundSize, themesupport.CustomBackground.DefaultSize)
|
||||||
siz = maps.WithDefaultVal(size, siz, "auto")
|
siz = maps.WithDefaultVal(size, siz, "auto")
|
||||||
siz = fmt.Sprintf(" background-size: %s;", siz)
|
siz = fmt.Sprintf(" background-size: %s;", siz)
|
||||||
|
|
||||||
repeats := helper.Defaults(h.ThemeMods.BackgroundRepeat, themesupport.CustomBackground.DefaultRepeat)
|
repeats := helper.Defaults(themeMods.BackgroundRepeat, themesupport.CustomBackground.DefaultRepeat)
|
||||||
repeats = maps.WithDefaultVal(repeat, repeats, "repeat")
|
repeats = maps.WithDefaultVal(repeat, repeats, "repeat")
|
||||||
repeats = fmt.Sprintf(" background-repeat: %s;", repeats)
|
repeats = fmt.Sprintf(" background-repeat: %s;", repeats)
|
||||||
|
|
||||||
attachment := helper.Defaults(h.ThemeMods.BackgroundAttachment, themesupport.CustomBackground.DefaultAttachment)
|
attachment := helper.Defaults(themeMods.BackgroundAttachment, themesupport.CustomBackground.DefaultAttachment)
|
||||||
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
|
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
|
||||||
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
|
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
|
||||||
s.WriteString(positon, siz, repeats, attachment)
|
s.WriteString(positon, siz, repeats, attachment)
|
||||||
|
@ -117,6 +117,6 @@ func customHeader(h *common.Handle) {
|
|||||||
header.Store(headers)
|
header.Store(headers)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
h.GinH["customHeader"] = headers
|
h.SetData("customHeader", headers)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
<script id='enlighterjs-js-after'>
|
<script id='enlighterjs-js-after'>
|
||||||
!function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":true,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console);
|
!function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":true,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console);
|
||||||
</script>
|
</script>
|
||||||
{{ block "footer" .}}
|
{{template "common/footer" .}}
|
||||||
{{end}}
|
{{ block "footer" .}}
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
@ -42,7 +42,7 @@ func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) {
|
|||||||
common.NewComponents(colorSchemeCss, 10),
|
common.NewComponents(colorSchemeCss, 10),
|
||||||
)
|
)
|
||||||
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(customHeader, 10))
|
h.PushHandleFn(constraints.AllStats, common.NewHandleFn(customHeader, 10))
|
||||||
switch h.Scene {
|
switch h.Scene() {
|
||||||
case constraints.Detail:
|
case constraints.Detail:
|
||||||
detail(next, h.Detail)
|
detail(next, h.Detail)
|
||||||
default:
|
default:
|
||||||
|
@ -10,11 +10,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func colorScheme(h *common.Handle) (r string) {
|
func colorScheme(h *common.Handle) (r string) {
|
||||||
if "custom" != wpconfig.GetThemeModsVal(h.Theme, "colorscheme", "light") {
|
if "custom" != wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s := str.NewBuilder()
|
s := str.NewBuilder()
|
||||||
hue := number.ToString(wpconfig.GetThemeModsVal[int64](h.Theme, "colorscheme_hue", 250))
|
hue := number.ToString(wpconfig.GetThemeModsVal[int64](ThemeName, "colorscheme_hue", 250))
|
||||||
saturation := fmt.Sprintf("%d%%", int(.8*50))
|
saturation := fmt.Sprintf("%d%%", int(.8*50))
|
||||||
css := customCss
|
css := customCss
|
||||||
for k, v := range map[string]string{
|
for k, v := range map[string]string{
|
||||||
|
@ -6,8 +6,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func customHeader(h *common.Handle) (r string) {
|
func customHeader(h *common.Handle) (r string) {
|
||||||
headerTextColor := h.ThemeMods.HeaderTextcolor
|
themeMods := h.CommonThemeMods()
|
||||||
if headerTextColor == "" || headerTextColor == h.ThemeMods.ThemeSupport.CustomHeader.DefaultTextColor {
|
headerTextColor := themeMods.HeaderTextcolor
|
||||||
|
if headerTextColor == "" || headerTextColor == themeMods.ThemeSupport.CustomHeader.DefaultTextColor {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
css := `
|
css := `
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<script id='enlighterjs-js-after'>
|
<script id='enlighterjs-js-after'>
|
||||||
!function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":true,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console);
|
!function(e,n){if("undefined"!=typeof EnlighterJS){var o={"selectors":{"block":"pre.EnlighterJSRAW","inline":"code.EnlighterJSRAW"},"options":{"indent":4,"ampersandCleanup":true,"linehover":true,"rawcodeDbclick":false,"textOverflow":"break","linenumbers":true,"theme":"enlighter","language":"generic","retainCssClasses":false,"collapse":false,"toolbarOuter":"","toolbarTop":"{BTN_RAW}{BTN_COPY}{BTN_WINDOW}{BTN_WEBSITE}","toolbarBottom":""}};(e.EnlighterJSINIT=function(){EnlighterJS.init(o.selectors.block,o.selectors.inline,o.options)})()}else{(n&&(n.error||n.log)||function(){})("Error: EnlighterJS resources not loaded yet!")}}(window,console);
|
||||||
</script>
|
</script>
|
||||||
{{ block "footer" .}}
|
{{template "common/footer" .}}
|
||||||
{{end}}
|
{{ block "footer" .}}
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
@ -41,13 +41,13 @@ func ready(next common.HandleFn[*common.Handle], h *common.Handle) {
|
|||||||
common.NewComponents(colorScheme, 10),
|
common.NewComponents(colorScheme, 10),
|
||||||
common.NewComponents(customHeader, 10),
|
common.NewComponents(customHeader, 10),
|
||||||
)
|
)
|
||||||
h.GinH["HeaderImage"] = getHeaderImage(h)
|
h.SetData("HeaderImage", getHeaderImage(h))
|
||||||
h.GinH["scene"] = h.Scene
|
h.SetData("scene", h.Scene())
|
||||||
next(h)
|
next(h)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) {
|
func dispatch(next common.HandleFn[*common.Handle], h *common.Handle) {
|
||||||
switch h.Scene {
|
switch h.Scene() {
|
||||||
case constraints.Detail:
|
case constraints.Detail:
|
||||||
detail(next, h.Detail)
|
detail(next, h.Detail)
|
||||||
default:
|
default:
|
||||||
@ -64,7 +64,7 @@ var listPostsPlugins = func() map[string]common.Plugin[models.Posts, *common.Han
|
|||||||
func index(next common.HandleFn[*common.Handle], i *common.IndexHandle) {
|
func index(next common.HandleFn[*common.Handle], i *common.IndexHandle) {
|
||||||
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.Templ = str.Join(ThemeName, "/posts/error.gohtml")
|
i.SetTempl(str.Join(ThemeName, "/posts/error.gohtml"))
|
||||||
i.Render()
|
i.Render()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func index(next common.HandleFn[*common.Handle], i *common.IndexHandle) {
|
|||||||
func detail(next common.HandleFn[*common.Handle], d *common.DetailHandle) {
|
func detail(next common.HandleFn[*common.Handle], d *common.DetailHandle) {
|
||||||
err := d.BuildDetailData()
|
err := d.BuildDetailData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Templ = str.Join(ThemeName, "/posts/error.gohtml")
|
d.SetTempl(str.Join(ThemeName, "/posts/error.gohtml"))
|
||||||
d.Render()
|
d.Render()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ func (c comment) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls
|
|||||||
func postThumbnail(next common.Fn[models.Posts], h *common.Handle, t models.Posts) models.Posts {
|
func postThumbnail(next common.Fn[models.Posts], h *common.Handle, t models.Posts) models.Posts {
|
||||||
if t.Thumbnail.Path != "" {
|
if t.Thumbnail.Path != "" {
|
||||||
t.Thumbnail.Sizes = "(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
|
t.Thumbnail.Sizes = "(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
|
||||||
if h.Scene == constraints.Detail {
|
if h.Scene() == constraints.Detail {
|
||||||
t.Thumbnail.Sizes = "100vw"
|
t.Thumbnail.Sizes = "100vw"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +138,7 @@ func getHeaderImage(h *common.Handle) (r models.PostThumbnail) {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.Path = helper.CutUrlHost(h.ThemeMods.ThemeSupport.CustomHeader.DefaultImage)
|
r.Path = helper.CutUrlHost(h.CommonThemeMods().ThemeSupport.CustomHeader.DefaultImage)
|
||||||
r.Width = 2000
|
r.Width = 2000
|
||||||
r.Height = 1200
|
r.Height = 1200
|
||||||
r.Sizes = "100vw"
|
r.Sizes = "100vw"
|
||||||
@ -147,23 +147,26 @@ func getHeaderImage(h *common.Handle) (r models.PostThumbnail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func calClass(h *common.Handle) {
|
func calClass(h *common.Handle) {
|
||||||
u := wpconfig.GetThemeModsVal(h.Theme, "header_image", h.ThemeMods.ThemeSupport.CustomHeader.DefaultImage)
|
themeMods := h.CommonThemeMods()
|
||||||
|
u := wpconfig.GetThemeModsVal(ThemeName, "header_image", themeMods.ThemeSupport.CustomHeader.DefaultImage)
|
||||||
|
var class []string
|
||||||
if u != "" && u != "remove-header" {
|
if u != "" && u != "remove-header" {
|
||||||
h.Class = append(h.Class, "has-header-image")
|
class = append(class, "has-header-image")
|
||||||
}
|
}
|
||||||
if len(h.ThemeMods.SidebarsWidgets.Data.Sidebar1) > 0 {
|
if len(themeMods.SidebarsWidgets.Data.Sidebar1) > 0 {
|
||||||
h.Class = append(h.Class, "has-sidebar")
|
class = append(class, "has-sidebar")
|
||||||
}
|
}
|
||||||
if h.ThemeMods.HeaderTextcolor == "blank" {
|
if themeMods.HeaderTextcolor == "blank" {
|
||||||
h.Class = append(h.Class, "title-tagline-hidden")
|
class = append(class, "title-tagline-hidden")
|
||||||
}
|
}
|
||||||
h.Class = append(h.Class, "hfeed")
|
class = append(class, "hfeed")
|
||||||
h.Class = append(h.Class, str.Join("colors-", wpconfig.GetThemeModsVal(h.Theme, "colorscheme", "light")))
|
class = append(class, str.Join("colors-", wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light")))
|
||||||
if h.Scene == constraints.Archive {
|
if h.Scene() == constraints.Archive {
|
||||||
if "one-column" == wpconfig.GetThemeModsVal(h.Theme, "page_layout", "") {
|
if "one-column" == wpconfig.GetThemeModsVal(ThemeName, "page_layout", "") {
|
||||||
h.Class = append(h.Class, "page-one-column")
|
class = append(class, "page-one-column")
|
||||||
} else {
|
} else {
|
||||||
h.Class = append(h.Class, "page-two-column")
|
class = append(class, "page-two-column")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
h.PushClass(class...)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user