Compare commits
No commits in common. "2a87ebdfd6e6fa19b772fc3c06f9ecfff46a3d64" and "efeeb8b675fcb7ba417a7aa5e8e5641767502fc8" have entirely different histories.
2a87ebdfd6
...
efeeb8b675
|
@ -12,19 +12,19 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var commonClass = map[int]string{
|
var commonClass = map[int]string{
|
||||||
constraints.Home: "home blog ",
|
constraints.Home: "home blog",
|
||||||
constraints.Archive: "archive date ",
|
constraints.Archive: "archive date",
|
||||||
constraints.Category: "archive category ",
|
constraints.Category: "archive category ",
|
||||||
constraints.Tag: "archive category ",
|
constraints.Tag: "archive category ",
|
||||||
constraints.Search: "search ",
|
constraints.Search: "search",
|
||||||
constraints.Detail: "post-template-default single single-post ",
|
constraints.Detail: "post-template-default single single-post ",
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
s := ""
|
s := ""
|
||||||
if constraints.Ok != h.Stats {
|
if constraints.Ok != h.Stats {
|
||||||
return "error404"
|
return "error404"
|
||||||
|
|
|
@ -2,7 +2,6 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
"github.com/fthvgb1/wp-go/internal/cmd/reload"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
|
@ -24,7 +23,7 @@ type Handle struct {
|
||||||
Templ string
|
Templ string
|
||||||
Class []string
|
Class []string
|
||||||
ThemeMods wpconfig.ThemeMods
|
ThemeMods wpconfig.ThemeMods
|
||||||
HandleFns []func(*Handle)
|
Plugins []HandlePluginFn[*Handle]
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
func NewHandle(c *gin.Context, scene int, theme string) *Handle {
|
||||||
|
@ -62,33 +61,19 @@ func (h *Handle) GetPassword() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) Render() {
|
func (h *Handle) ExecHandlePlugin() {
|
||||||
if h.Templ == "" {
|
if len(h.Plugins) > 0 {
|
||||||
h.Templ = str.Join(h.Theme, "/posts/index.gohtml")
|
HandlePlugin(h.Plugins, h)
|
||||||
if h.Scene == constraints.Detail {
|
|
||||||
h.Templ = str.Join(h.Theme, "/posts/detail.gohtml")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for _, fn := range h.HandleFns {
|
|
||||||
fn(h)
|
|
||||||
}
|
|
||||||
h.AutoCal("siteIcon", h.CalSiteIcon)
|
|
||||||
h.AutoCal("customLogo", h.CalCustomLogo)
|
|
||||||
h.AutoCal("customCss", h.CalCustomCss)
|
|
||||||
h.CalBodyClass()
|
|
||||||
|
|
||||||
h.C.HTML(h.Code, h.Templ, h.GinH)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HandleFn[T any] func(T)
|
type HandleFn[T any] func(T)
|
||||||
|
|
||||||
type HandlePipeFn[T any] func(HandleFn[T], T)
|
type HandlePluginFn[T any] func(HandleFn[T], T) HandleFn[T]
|
||||||
|
|
||||||
// HandlePipe 方便把功能写在其它包里
|
// HandlePlugin 方便把功能写在其它包里
|
||||||
func HandlePipe[T any](fns []HandlePipeFn[T], initial func(T)) HandleFn[T] {
|
func HandlePlugin[T any](fns []HandlePluginFn[T], h T) HandleFn[T] {
|
||||||
return slice.ReverseReduce(fns, func(next HandlePipeFn[T], f func(t T)) func(t T) {
|
return slice.ReverseReduce(fns, func(t HandlePluginFn[T], r HandleFn[T]) HandleFn[T] {
|
||||||
return func(t T) {
|
return t(r, h)
|
||||||
next(f, t)
|
}, func(t T) {})
|
||||||
}
|
|
||||||
}, initial)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,25 +17,20 @@ type DetailHandle struct {
|
||||||
CommentRender plugins.CommentHtml
|
CommentRender plugins.CommentHtml
|
||||||
Comments []models.Comments
|
Comments []models.Comments
|
||||||
Post models.Posts
|
Post models.Posts
|
||||||
Pipes []HandlePipeFn[*DetailHandle]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDetailHandle(handle *Handle) *DetailHandle {
|
func NewDetailHandle(handle *Handle) *DetailHandle {
|
||||||
return &DetailHandle{Handle: handle}
|
return &DetailHandle{Handle: handle}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) Pipe(calls ...HandlePipeFn[*DetailHandle]) {
|
|
||||||
HandlePipe[*DetailHandle](append(calls, d.Pipes...), func(d *DetailHandle) {
|
|
||||||
d.Render()
|
|
||||||
})(d)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
d.WidgetAreaData()
|
||||||
|
d.GetPassword()
|
||||||
d.Comment()
|
d.Comment()
|
||||||
d.ContextPost()
|
d.ContextPost()
|
||||||
return
|
return
|
||||||
|
@ -78,9 +73,6 @@ func (d *DetailHandle) Comment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) RenderComment() {
|
func (d *DetailHandle) RenderComment() {
|
||||||
if d.CommentRender == nil {
|
|
||||||
d.CommentRender = plugins.CommentRender()
|
|
||||||
}
|
|
||||||
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) {
|
||||||
|
@ -102,8 +94,19 @@ func (d *DetailHandle) ContextPost() {
|
||||||
|
|
||||||
func (d *DetailHandle) Render() {
|
func (d *DetailHandle) Render() {
|
||||||
d.PasswordProject()
|
d.PasswordProject()
|
||||||
|
if d.CommentRender == nil {
|
||||||
|
d.CommentRender = plugins.CommentRender()
|
||||||
|
}
|
||||||
|
d.CalBodyClass()
|
||||||
|
d.AutoCal("siteIcon", d.CalSiteIcon)
|
||||||
|
d.AutoCal("customLogo", d.CalCustomLogo)
|
||||||
|
d.AutoCal("customCss", d.CalCustomCss)
|
||||||
d.RenderComment()
|
d.RenderComment()
|
||||||
d.Handle.Render()
|
d.CalBodyClass()
|
||||||
|
if d.Templ == "" {
|
||||||
|
d.Templ = fmt.Sprintf("%s/posts/detail.gohtml", d.Theme)
|
||||||
|
}
|
||||||
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DetailHandle) Details() {
|
func (d *DetailHandle) Details() {
|
||||||
|
@ -114,5 +117,6 @@ func (d *DetailHandle) Details() {
|
||||||
d.C.HTML(d.Code, d.Templ, d.GinH)
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
d.ExecHandlePlugin()
|
||||||
d.Render()
|
d.Render()
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,26 +15,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexHandle struct {
|
|
||||||
*Handle
|
|
||||||
Param *IndexParams
|
|
||||||
Posts []models.Posts
|
|
||||||
PageEle pagination.Elements
|
|
||||||
TotalRows int
|
|
||||||
PostsPlugins map[string]Plugin[models.Posts, *Handle]
|
|
||||||
Pipes []HandlePipeFn[*IndexHandle]
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewIndexHandle(handle *Handle) *IndexHandle {
|
|
||||||
return &IndexHandle{Handle: handle}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *IndexHandle) Pipe(calls ...HandlePipeFn[*IndexHandle]) {
|
|
||||||
HandlePipe[*IndexHandle](append(calls, i.Pipes...), func(i *IndexHandle) {
|
|
||||||
i.Render()
|
|
||||||
})(i)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
||||||
|
@ -84,9 +64,6 @@ func (i *IndexHandle) GetIndexData() (posts []models.Posts, totalRaw int, err er
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IndexHandle) Pagination() {
|
func (i *IndexHandle) Pagination() {
|
||||||
if i.PageEle == nil {
|
|
||||||
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)
|
||||||
|
@ -131,8 +108,18 @@ func (i *IndexHandle) ExecPostsPlugin(calls ...func(*models.Posts)) {
|
||||||
|
|
||||||
func (i *IndexHandle) Render() {
|
func (i *IndexHandle) Render() {
|
||||||
i.ExecPostsPlugin()
|
i.ExecPostsPlugin()
|
||||||
|
if i.PageEle == nil {
|
||||||
|
i.PageEle = plugins.TwentyFifteenPagination()
|
||||||
|
}
|
||||||
i.Pagination()
|
i.Pagination()
|
||||||
i.Handle.Render()
|
i.AutoCal("siteIcon", i.CalSiteIcon)
|
||||||
|
i.AutoCal("customLogo", i.CalCustomLogo)
|
||||||
|
i.AutoCal("customCss", i.CalCustomCss)
|
||||||
|
i.CalBodyClass()
|
||||||
|
if i.Templ == "" {
|
||||||
|
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
||||||
|
}
|
||||||
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IndexHandle) Indexs() {
|
func (i *IndexHandle) Indexs() {
|
||||||
|
@ -143,5 +130,6 @@ func (i *IndexHandle) Indexs() {
|
||||||
i.C.HTML(i.Code, i.Templ, i.GinH)
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
i.ExecHandlePlugin()
|
||||||
i.Render()
|
i.Render()
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,10 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/dao"
|
"github.com/fthvgb1/wp-go/internal/pkg/dao"
|
||||||
|
"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"
|
||||||
|
"github.com/fthvgb1/wp-go/plugin/pagination"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -53,6 +55,19 @@ type IndexParams struct {
|
||||||
BlogName string
|
BlogName string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type IndexHandle struct {
|
||||||
|
*Handle
|
||||||
|
Param *IndexParams
|
||||||
|
Posts []models.Posts
|
||||||
|
PageEle pagination.Elements
|
||||||
|
TotalRows int
|
||||||
|
PostsPlugins map[string]Plugin[models.Posts, *Handle]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewIndexHandle(handle *Handle) *IndexHandle {
|
||||||
|
return &IndexHandle{Handle: handle}
|
||||||
|
}
|
||||||
|
|
||||||
var months = slice.SimpleToMap(number.Range(1, 12, 1), func(v int) int {
|
var months = slice.SimpleToMap(number.Range(1, 12, 1), func(v int) int {
|
||||||
return v
|
return v
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
{{block "head" .}}
|
{{block "head" .}}
|
||||||
{{end}}
|
{{end}}
|
||||||
</head>
|
</head>
|
||||||
<body class="{{.bodyClass}} wp-embed-responsive hfeed has-sidebar colors-light">
|
<body class="{{.bodyClass}} wp-embed-responsive hfeed has-header-image has-sidebar colors-light">
|
||||||
{{template "svg"}}
|
{{template "svg"}}
|
||||||
<div id="page" class="site">
|
<div id="page" class="site">
|
||||||
<a class="skip-link screen-reader-text" href="#content">跳至内容</a>
|
<a class="skip-link screen-reader-text" href="#content">跳至内容</a>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{{template "layout/base" .}}
|
{{template "layout/base" .}}
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
{{ if gt .post.Id 0}}
|
{{ if .post.PostContent}}
|
||||||
{{if .post.Thumbnail.Path}}
|
{{if .post.Thumbnail.Path}}
|
||||||
<div class="single-featured-image-header">
|
<div class="single-featured-image-header">
|
||||||
<img width="{{.post.Thumbnail.OriginAttachmentData.Width}}" height="{{.post.Thumbnail.OriginAttachmentData.Height}}" src="{{.post.Thumbnail.Path}}" class="attachment-twentyseventeen-featured-image size-twentyseventeen-featured-image wp-post-image" alt="{{.post.PostTitle}}" decoding="async" loading="lazy" srcset="{{.post.Thumbnail.Srcset}}" sizes="{{.post.Thumbnail.Sizes}}">
|
<img width="{{.post.Thumbnail.OriginAttachmentData.Width}}" height="{{.post.Thumbnail.OriginAttachmentData.Height}}" src="{{.post.Thumbnail.Path}}" class="attachment-twentyseventeen-featured-image size-twentyseventeen-featured-image wp-post-image" alt="{{.post.PostTitle}}" decoding="async" loading="lazy" srcset="{{.post.Thumbnail.Srcset}}" sizes="{{.post.Thumbnail.Sizes}}">
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fthvgb1/wp-go/helper/maps"
|
"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"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
|
@ -28,16 +29,41 @@ var paginate = func() plugins.PageEle {
|
||||||
return p
|
return p
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
type handle struct {
|
||||||
|
*common.Handle
|
||||||
|
}
|
||||||
|
|
||||||
|
func newHandle(h *common.Handle) *handle {
|
||||||
|
return &handle{Handle: h}
|
||||||
|
}
|
||||||
|
|
||||||
|
type indexHandle struct {
|
||||||
|
*common.IndexHandle
|
||||||
|
h *handle
|
||||||
|
}
|
||||||
|
|
||||||
|
func newIndexHandle(iHandle *common.IndexHandle) *indexHandle {
|
||||||
|
return &indexHandle{IndexHandle: iHandle, h: newHandle(iHandle.Handle)}
|
||||||
|
}
|
||||||
|
|
||||||
|
type detailHandle struct {
|
||||||
|
*common.DetailHandle
|
||||||
|
h *handle
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
||||||
|
return &detailHandle{DetailHandle: dHandle, h: newHandle(dHandle.Handle)}
|
||||||
|
}
|
||||||
|
|
||||||
func Hook(h *common.Handle) {
|
func Hook(h *common.Handle) {
|
||||||
h.WidgetAreaData()
|
h.WidgetAreaData()
|
||||||
h.GetPassword()
|
h.GetPassword()
|
||||||
h.HandleFns = append(h.HandleFns, calClass)
|
|
||||||
h.GinH["HeaderImage"] = getHeaderImage(h.C)
|
h.GinH["HeaderImage"] = getHeaderImage(h.C)
|
||||||
if h.Scene == constraints.Detail {
|
if h.Scene == constraints.Detail {
|
||||||
common.NewDetailHandle(h).Pipe(detail)
|
newDetailHandle(common.NewDetailHandle(h)).Detail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
common.NewIndexHandle(h).Pipe(index)
|
newIndexHandle(common.NewIndexHandle(h)).Index()
|
||||||
}
|
}
|
||||||
|
|
||||||
var pluginFns = func() map[string]common.Plugin[models.Posts, *common.Handle] {
|
var pluginFns = func() map[string]common.Plugin[models.Posts, *common.Handle] {
|
||||||
|
@ -46,29 +72,31 @@ var pluginFns = func() map[string]common.Plugin[models.Posts, *common.Handle] {
|
||||||
})
|
})
|
||||||
}()
|
}()
|
||||||
|
|
||||||
func index(next common.HandleFn[*common.IndexHandle], i *common.IndexHandle) {
|
func (i *indexHandle) Index() {
|
||||||
|
i.Templ = "twentyseventeen/posts/index.gohtml"
|
||||||
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.Stats = constraints.Error404
|
i.Stats = constraints.Error404
|
||||||
i.Code = http.StatusNotFound
|
i.Code = http.StatusNotFound
|
||||||
i.CalBodyClass()
|
i.GinH["bodyClass"] = i.h.bodyClass()
|
||||||
i.C.HTML(i.Code, i.Templ, i.GinH)
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.PostsPlugins = pluginFns
|
i.PostsPlugins = pluginFns
|
||||||
i.PageEle = paginate
|
i.PageEle = paginate
|
||||||
next(i)
|
i.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
func detail(next common.HandleFn[*common.DetailHandle], d *common.DetailHandle) {
|
func (d *detailHandle) Detail() {
|
||||||
err := d.BuildDetailData()
|
err := d.BuildDetailData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Code = http.StatusNotFound
|
d.Code = http.StatusNotFound
|
||||||
d.Stats = constraints.Error404
|
d.Stats = constraints.Error404
|
||||||
d.GinH["bodyClass"] = d.BodyClass()
|
d.GinH["bodyClass"] = d.h.bodyClass()
|
||||||
d.C.HTML(d.Code, d.Templ, d.GinH)
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
d.GinH["bodyClass"] = d.h.bodyClass()
|
||||||
img := wpconfig.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "thumbnail", "", "thumbnail", "post-thumbnail")
|
img := wpconfig.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "thumbnail", "", "thumbnail", "post-thumbnail")
|
||||||
img.Width = img.OriginAttachmentData.Width
|
img.Width = img.OriginAttachmentData.Width
|
||||||
img.Height = img.OriginAttachmentData.Height
|
img.Height = img.OriginAttachmentData.Height
|
||||||
|
@ -77,8 +105,8 @@ func detail(next common.HandleFn[*common.DetailHandle], d *common.DetailHandle)
|
||||||
d.Post.Thumbnail = img
|
d.Post.Thumbnail = img
|
||||||
d.CommentRender = commentFormat
|
d.CommentRender = commentFormat
|
||||||
d.GinH["post"] = d.Post
|
d.GinH["post"] = d.Post
|
||||||
|
d.Render()
|
||||||
|
|
||||||
next(d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var commentFormat = comment{}
|
var commentFormat = comment{}
|
||||||
|
@ -120,21 +148,46 @@ func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
||||||
logs.ErrPrintln(err, "获取页眉背景图失败")
|
logs.ErrPrintln(err, "获取页眉背景图失败")
|
||||||
} else if len(hs) > 0 && err == nil {
|
} else if len(hs) > 0 && err == nil {
|
||||||
_, r = slice.Rand(hs)
|
_, r = slice.Rand(hs)
|
||||||
|
|
||||||
}
|
}
|
||||||
r.Sizes = "100vw"
|
r.Sizes = "100vw"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func calClass(h *common.Handle) {
|
func (i *handle) bodyClass() string {
|
||||||
u := wpconfig.GetThemeModsVal(h.Theme, "header_image", h.ThemeMods.ThemeSupport.CustomHeader.DefaultImage)
|
s := ""
|
||||||
if u != "" && u != "remove-header" {
|
if constraints.Ok != i.Stats {
|
||||||
h.Class = append(h.Class, "has-header-image")
|
return "error404"
|
||||||
}
|
}
|
||||||
if h.Scene == constraints.Archive {
|
switch i.Scene {
|
||||||
if "one-column" == wpconfig.GetThemeModsVal(h.Theme, "page_layout", "") {
|
case constraints.Search:
|
||||||
h.Class = append(h.Class, "page-one-column")
|
s = "search-no-results"
|
||||||
} else {
|
if len(i.GinH["posts"].([]models.Posts)) > 0 {
|
||||||
h.Class = append(h.Class, "page-two-column")
|
s = "search-results"
|
||||||
}
|
}
|
||||||
|
case constraints.Category, constraints.Tag:
|
||||||
|
cat := i.C.Param("category")
|
||||||
|
if cat == "" {
|
||||||
|
cat = i.C.Param("tag")
|
||||||
|
}
|
||||||
|
_, cate := slice.SearchFirst(cache.CategoriesTags(i.C, i.Scene), func(my models.TermsMy) bool {
|
||||||
|
return my.Name == cat
|
||||||
|
})
|
||||||
|
if cate.Slug[0] != '%' {
|
||||||
|
s = cate.Slug
|
||||||
|
}
|
||||||
|
s = fmt.Sprintf("category-%d %v", cate.Terms.TermId, s)
|
||||||
|
case constraints.Detail:
|
||||||
|
s = fmt.Sprintf("postid-%d", i.GinH["post"].(models.Posts).Id)
|
||||||
}
|
}
|
||||||
|
return str.Join(class[i.Scene], s)
|
||||||
|
}
|
||||||
|
|
||||||
|
var class = map[int]string{
|
||||||
|
constraints.Home: "home blog ",
|
||||||
|
constraints.Archive: "archive date page-two-column",
|
||||||
|
constraints.Category: "archive category page-two-column",
|
||||||
|
constraints.Tag: "archive category page-two-column ",
|
||||||
|
constraints.Search: "search ",
|
||||||
|
constraints.Detail: "post-template-default single single-post single-format-standard ",
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (w SqlBuilder) parseWhereField(ss []string, s *strings.Builder) {
|
func (w SqlBuilder) parseField(ss []string, s *strings.Builder) {
|
||||||
if strings.Contains(ss[0], ".") && !strings.Contains(ss[0], "(") {
|
if strings.Contains(ss[0], ".") && !strings.Contains(ss[0], "(") {
|
||||||
x := slice.Map(strings.Split(ss[0], "."), func(t string) string {
|
x := slice.Map(strings.Split(ss[0], "."), func(t string) string {
|
||||||
return str.Join("`", t, "`")
|
return str.Join("`", t, "`")
|
||||||
|
@ -81,11 +81,11 @@ func (w SqlBuilder) ParseWhere(in *[][]any) (string, []any, error) {
|
||||||
s.WriteString(ss[0])
|
s.WriteString(ss[0])
|
||||||
s.WriteString(" and ")
|
s.WriteString(" and ")
|
||||||
case 2:
|
case 2:
|
||||||
w.parseWhereField(ss, &s)
|
w.parseField(ss, &s)
|
||||||
s.WriteString("=? and ")
|
s.WriteString("=? and ")
|
||||||
args = append(args, ss[1])
|
args = append(args, ss[1])
|
||||||
case 3, 4:
|
case 3, 4:
|
||||||
w.parseWhereField(ss, &s)
|
w.parseField(ss, &s)
|
||||||
s.WriteString(ss[1])
|
s.WriteString(ss[1])
|
||||||
if w.parseIn(ss, &s, &c, &args, in) {
|
if w.parseIn(ss, &s, &c, &args, in) {
|
||||||
s.WriteString(" and ")
|
s.WriteString(" and ")
|
||||||
|
@ -115,7 +115,7 @@ func (w SqlBuilder) ParseWhere(in *[][]any) (string, []any, error) {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
s.WriteString("( ")
|
s.WriteString("( ")
|
||||||
}
|
}
|
||||||
w.parseWhereField(ss[start+1:end], &s)
|
w.parseField(ss[start+1:end], &s)
|
||||||
s.WriteString(ss[start+2])
|
s.WriteString(ss[start+2])
|
||||||
if w.parseIn(ss[start+1:end], &s, &c, &args, in) {
|
if w.parseIn(ss[start+1:end], &s, &c, &args, in) {
|
||||||
s.WriteString(" and ")
|
s.WriteString(" and ")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user