fix bug and optimize code
This commit is contained in:
parent
73575965d3
commit
af712f06a5
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -112,19 +112,13 @@ 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)
|
||||
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)
|
||||
d.Post.Thumbnail = img
|
||||
}
|
||||
}
|
||||
|
||||
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.Sizes = "100vw"
|
||||
img.Srcset = fmt.Sprintf("%s %dw, %s", img.Path, img.Width, img.Srcset)
|
||||
return img
|
||||
}
|
||||
|
||||
var commentFormat = comment{}
|
||||
|
||||
type comment struct {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user