From f735211a928e6c269f08a7a92dbbb23a054c4396 Mon Sep 17 00:00:00 2001 From: xing Date: Mon, 17 Apr 2023 17:24:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/theme/twentyfifteen/posts/detail.gohtml | 5 +++++ internal/theme/twentyfifteen/twentyfifteen.go | 8 ++++++++ internal/theme/wp/calclass.go | 4 +--- internal/theme/wp/detail.go | 1 - internal/wpconfig/thememods.go | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/internal/theme/twentyfifteen/posts/detail.gohtml b/internal/theme/twentyfifteen/posts/detail.gohtml index 10417a4..3c60d74 100644 --- a/internal/theme/twentyfifteen/posts/detail.gohtml +++ b/internal/theme/twentyfifteen/posts/detail.gohtml @@ -5,6 +5,11 @@
+ {{if .post.Thumbnail.Path }} +
+ +
+ {{end}}

{{.post.PostTitle}}

diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index c0a0ffa..372dd4a 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -12,6 +12,7 @@ import ( "github.com/fthvgb1/wp-go/internal/theme/wp" "github.com/fthvgb1/wp-go/internal/theme/wp/components" "github.com/fthvgb1/wp-go/internal/theme/wp/components/widget" + "github.com/fthvgb1/wp-go/internal/wpconfig" "strings" ) @@ -76,4 +77,11 @@ func configs(h *wp.Handle) { h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10)) h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50)) h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 50)) + h.PushHandleFn(constraints.Detail, wp.NewHandleFn(postThumb, 60)) +} + +func postThumb(h *wp.Handle) { + if h.Detail.Post.Thumbnail.Path != "" { + h.Detail.Post.Thumbnail = wpconfig.Thumbnail(h.Detail.Post.Thumbnail.OriginAttachmentData, "post-thumbnail", "") + } } diff --git a/internal/theme/wp/calclass.go b/internal/theme/wp/calclass.go index b974e64..03f20e5 100644 --- a/internal/theme/wp/calclass.go +++ b/internal/theme/wp/calclass.go @@ -110,12 +110,10 @@ func TermClass(term models.TermsMy) string { termClass = strconv.FormatUint(term.TermTaxonomy.TermId, 10) } switch term.Taxonomy { - case "category": - return str.Join("category-", termClass) case "post_tag": return str.Join("tag-", termClass) case "post_format": return fmt.Sprintf("format-%s", strings.ReplaceAll(term.Slug, "post-format-", "")) } - return fmt.Sprintf("%s-%d", term.Taxonomy, term.TermTaxonomy.TermId) + return str.Join(term.Taxonomy, "-", termClass) } diff --git a/internal/theme/wp/detail.go b/internal/theme/wp/detail.go index b147dd9..64fa5cc 100644 --- a/internal/theme/wp/detail.go +++ b/internal/theme/wp/detail.go @@ -66,7 +66,6 @@ func (d *DetailHandle) PasswordProject() { if d.password != d.Post.PostPassword { wpposts.PasswdProjectContent(&d.Post) } - d.ginH["post"] = d.Post } } func (d *DetailHandle) Comment() { diff --git a/internal/wpconfig/thememods.go b/internal/wpconfig/thememods.go index 0afbda9..a4f4067 100644 --- a/internal/wpconfig/thememods.go +++ b/internal/wpconfig/thememods.go @@ -82,8 +82,8 @@ func Thumbnail(metadata models.WpAttachmentMetadata, Type, host string, except . FileSize: metadata.FileSize, } } - if _, ok := metadata.Sizes[Type]; ok { - r.Path = fmt.Sprintf("%s/wp-content/uploads/%s", host, metadata.File) + if siz, ok := metadata.Sizes[Type]; ok { + r.Path = fmt.Sprintf("%s/wp-content/uploads/%s", host, strings.ReplaceAll(metadata.File, filepath.Base(metadata.File), siz.File)) r.Width = metadata.Sizes[Type].Width r.Height = metadata.Sizes[Type].Height