fix bug and optimize code

This commit is contained in:
xing 2024-01-25 14:12:51 +08:00
parent 73575965d3
commit af712f06a5
3 changed files with 6 additions and 19 deletions

View File

@ -3,13 +3,11 @@ package twentyfifteen
import (
"github.com/fthvgb1/wp-go/app/pkg/constraints"
"github.com/fthvgb1/wp-go/app/pkg/constraints/widgets"
"github.com/fthvgb1/wp-go/app/pkg/models"
"github.com/fthvgb1/wp-go/app/plugins"
"github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/app/theme/wp/components"
"github.com/fthvgb1/wp-go/app/theme/wp/middleware"
"github.com/fthvgb1/wp-go/app/wpconfig"
"github.com/fthvgb1/wp-go/cache/reload"
"strings"
)
@ -56,16 +54,10 @@ func setPaginationAndRender(h *wp.Handle) {
func postThumb(h *wp.Handle) {
d := h.GetDetailHandle()
if d.Post.Thumbnail.Path != "" {
d.Post.Thumbnail = getPostThumbs(d.Post.Id, d.Post)
d.Post.Thumbnail = wpconfig.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "post-thumbnail", "")
}
}
var getPostThumbs = reload.BuildMapFn[uint64]("twentyFifteen-post-thumbnail", postThumbs)
func postThumbs(post models.Posts) models.PostThumbnail {
return wpconfig.Thumbnail(post.Thumbnail.OriginAttachmentData, "post-thumbnail", "")
}
func renderCustomHeader(h *wp.Handle) {
h.SetData("customHeader", customHeader(h))
}

View File

@ -112,17 +112,11 @@ func errorsHandle(h *wp.Handle) {
func postThumb(h *wp.Handle) {
d := h.GetDetailHandle()
if d.Post.Thumbnail.Path != "" {
d.Post.Thumbnail = getPostThumbs(d.Post.Id, d.Post)
}
}
var getPostThumbs = reload.BuildMapFn[uint64]("post-thumbnail", postThumbs)
func postThumbs(post models.Posts) models.PostThumbnail {
img := wpconfig.Thumbnail(post.Thumbnail.OriginAttachmentData, "full", "", "thumbnail", "post-thumbnail")
img := wpconfig.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "full", "", "thumbnail", "post-thumbnail")
img.Sizes = "100vw"
img.Srcset = fmt.Sprintf("%s %dw, %s", img.Path, img.Width, img.Srcset)
return img
d.Post.Thumbnail = img
}
}
var commentFormat = comment{}

View File

@ -73,6 +73,7 @@ func Thumbnail(metadata models.WpAttachmentMetadata, Type, host string, except .
up := strings.Split(metadata.File, "/")
if metadata.File != "" && Type == "full" {
mimeType := metadata.Sizes["thumbnail"].MimeType
metadata.Sizes = maps.Copy(metadata.Sizes)
metadata.Sizes["full"] = models.MetaDataFileSize{
File: filepath.Base(metadata.File),
Width: metadata.Width,