This commit is contained in:
xing 2023-04-17 17:24:42 +08:00
parent 5266e85f21
commit f735211a92
5 changed files with 16 additions and 6 deletions

View File

@ -5,6 +5,11 @@
<div id="primary" class="content-area"> <div id="primary" class="content-area">
<main id="main" class="site-main"> <main id="main" class="site-main">
<article class="{{ .post|postsFn .calPostClass}}"> <article class="{{ .post|postsFn .calPostClass}}">
{{if .post.Thumbnail.Path }}
<div class="post-thumbnail">
<img width="{{.post.Thumbnail.Width}}" height="{{.post.Thumbnail.Height}}" src="{{.post.Thumbnail.Path}}" class="attachment-post-thumbnail size-post-thumbnail wp-post-image" alt="" decoding="async">
</div>
{{end}}
<header class="entry-header"> <header class="entry-header">
<h1 class="entry-title">{{.post.PostTitle}}</h1></header><!-- .entry-header --> <h1 class="entry-title">{{.post.PostTitle}}</h1></header><!-- .entry-header -->

View File

@ -12,6 +12,7 @@ import (
"github.com/fthvgb1/wp-go/internal/theme/wp" "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"
"github.com/fthvgb1/wp-go/internal/theme/wp/components/widget" "github.com/fthvgb1/wp-go/internal/theme/wp/components/widget"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"strings" "strings"
) )
@ -76,4 +77,11 @@ func configs(h *wp.Handle) {
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10)) h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(customHeader, 10))
h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50)) h.PushHandleFn(constraints.AllStats, wp.NewHandleFn(wp.IndexRender, 50))
h.PushHandleFn(constraints.Detail, wp.NewHandleFn(wp.DetailRender, 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", "")
}
} }

View File

@ -110,12 +110,10 @@ func TermClass(term models.TermsMy) string {
termClass = strconv.FormatUint(term.TermTaxonomy.TermId, 10) termClass = strconv.FormatUint(term.TermTaxonomy.TermId, 10)
} }
switch term.Taxonomy { switch term.Taxonomy {
case "category":
return str.Join("category-", termClass)
case "post_tag": case "post_tag":
return str.Join("tag-", termClass) return str.Join("tag-", termClass)
case "post_format": case "post_format":
return fmt.Sprintf("format-%s", strings.ReplaceAll(term.Slug, "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)
} }

View File

@ -66,7 +66,6 @@ func (d *DetailHandle) PasswordProject() {
if d.password != d.Post.PostPassword { if d.password != d.Post.PostPassword {
wpposts.PasswdProjectContent(&d.Post) wpposts.PasswdProjectContent(&d.Post)
} }
d.ginH["post"] = d.Post
} }
} }
func (d *DetailHandle) Comment() { func (d *DetailHandle) Comment() {

View File

@ -82,8 +82,8 @@ func Thumbnail(metadata models.WpAttachmentMetadata, Type, host string, except .
FileSize: metadata.FileSize, FileSize: metadata.FileSize,
} }
} }
if _, ok := metadata.Sizes[Type]; ok { if siz, ok := metadata.Sizes[Type]; ok {
r.Path = fmt.Sprintf("%s/wp-content/uploads/%s", host, metadata.File) 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.Width = metadata.Sizes[Type].Width
r.Height = metadata.Sizes[Type].Height r.Height = metadata.Sizes[Type].Height