2023-02-09 12:49:33 +00:00
|
|
|
package twentyfifteen
|
|
|
|
|
|
|
|
import (
|
2023-02-13 15:03:17 +00:00
|
|
|
"fmt"
|
|
|
|
"github.com/fthvgb1/wp-go/helper/slice"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
2023-02-10 13:23:30 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
2023-02-13 15:03:17 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
2023-02-09 12:49:33 +00:00
|
|
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
|
|
|
"github.com/fthvgb1/wp-go/internal/theme/common"
|
2023-02-13 15:03:17 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
2023-02-11 15:58:40 +00:00
|
|
|
"net/http"
|
2023-02-09 12:49:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const ThemeName = "twentyfifteen"
|
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
type indexHandle struct {
|
|
|
|
*common.IndexHandle
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
func newIndexHandle(iHandle *common.IndexHandle) *indexHandle {
|
|
|
|
return &indexHandle{iHandle}
|
|
|
|
}
|
2023-02-10 16:32:46 +00:00
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
type detailHandle struct {
|
|
|
|
*common.DetailHandle
|
|
|
|
}
|
|
|
|
|
|
|
|
func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
|
|
|
return &detailHandle{DetailHandle: dHandle}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Hook(h *common.Handle) {
|
|
|
|
h.WidgetAreaData()
|
|
|
|
h.GetPassword()
|
2023-02-10 13:23:30 +00:00
|
|
|
if h.Scene == constraints.Detail {
|
2023-02-11 15:51:07 +00:00
|
|
|
newDetailHandle(common.NewDetailHandle(h)).Detail()
|
2023-02-09 12:49:33 +00:00
|
|
|
return
|
|
|
|
}
|
2023-02-11 15:51:07 +00:00
|
|
|
newIndexHandle(common.NewIndexHandle(h)).Index()
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
func (i *indexHandle) Index() {
|
|
|
|
i.Templ = "twentyfifteen/posts/index.gohtml"
|
2023-02-13 15:03:17 +00:00
|
|
|
img := getHeaderImage(i.C)
|
|
|
|
fmt.Println(img)
|
2023-02-11 15:51:07 +00:00
|
|
|
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
2023-02-10 16:32:46 +00:00
|
|
|
if err != nil {
|
2023-02-11 15:58:40 +00:00
|
|
|
i.Stats = constraints.Error404
|
|
|
|
i.Code = http.StatusNotFound
|
2023-02-11 15:51:07 +00:00
|
|
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
2023-02-10 16:32:46 +00:00
|
|
|
return
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
2023-02-11 15:51:07 +00:00
|
|
|
i.ExecPostsPlugin()
|
|
|
|
i.PageEle = plugins.TwentyFifteenPagination()
|
|
|
|
i.Pagination()
|
|
|
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
func (d *detailHandle) Detail() {
|
|
|
|
d.Templ = "twentyfifteen/posts/detail.gohtml"
|
2023-02-09 12:49:33 +00:00
|
|
|
|
2023-02-11 15:51:07 +00:00
|
|
|
err := d.BuildDetailData()
|
|
|
|
if err != nil {
|
|
|
|
d.Stats = constraints.Error404
|
2023-02-11 15:58:40 +00:00
|
|
|
d.Code = http.StatusNotFound
|
2023-02-11 15:51:07 +00:00
|
|
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
d.PasswordProject()
|
|
|
|
d.CommentRender = plugins.CommentRender()
|
|
|
|
d.RenderComment()
|
|
|
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
2023-02-09 12:49:33 +00:00
|
|
|
}
|
2023-02-13 15:03:17 +00:00
|
|
|
|
|
|
|
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
|
|
|
r.Path = "/wp-content/themes/twentyseventeen/assets/images/header.jpg"
|
|
|
|
r.Width = 2000
|
|
|
|
r.Height = 1200
|
|
|
|
hs, err := cache.GetHeaderImages(c, ThemeName)
|
|
|
|
if err != nil {
|
|
|
|
logs.ErrPrintln(err, "获取页眉背景图失败")
|
|
|
|
} else if len(hs) > 0 && err == nil {
|
|
|
|
_, r = slice.Rand(hs)
|
|
|
|
|
|
|
|
}
|
|
|
|
r.Sizes = "100vw"
|
|
|
|
return
|
|
|
|
}
|