sitelogo
This commit is contained in:
parent
1d80534333
commit
3c21187ee3
|
@ -97,6 +97,7 @@ func (d *DetailHandle) Render() {
|
||||||
if d.CommentRender == nil {
|
if d.CommentRender == nil {
|
||||||
d.CommentRender = plugins.CommentRender()
|
d.CommentRender = plugins.CommentRender()
|
||||||
}
|
}
|
||||||
|
d.SiteIcon()
|
||||||
d.RenderComment()
|
d.RenderComment()
|
||||||
d.CalBodyClass()
|
d.CalBodyClass()
|
||||||
if d.Templ == "" {
|
if d.Templ == "" {
|
||||||
|
|
|
@ -112,6 +112,7 @@ func (i *IndexHandle) Render() {
|
||||||
i.PageEle = plugins.TwentyFifteenPagination()
|
i.PageEle = plugins.TwentyFifteenPagination()
|
||||||
}
|
}
|
||||||
i.Pagination()
|
i.Pagination()
|
||||||
|
i.SiteIcon()
|
||||||
i.CalBodyClass()
|
i.CalBodyClass()
|
||||||
if i.Templ == "" {
|
if i.Templ == "" {
|
||||||
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
i.Templ = fmt.Sprintf("%s/posts/index.gohtml", i.Theme)
|
||||||
|
|
52
internal/theme/common/siteicon.go
Normal file
52
internal/theme/common/siteicon.go
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/fthvgb1/wp-go/helper/slice"
|
||||||
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
|
"github.com/fthvgb1/wp-go/safety"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
var icon = safety.NewVar("default")
|
||||||
|
var sizes = []string{"site_icon-270", "site_icon-32", "site_icon-192", "site_icon-180"}
|
||||||
|
|
||||||
|
func (h *Handle) CalSiteIcon() (r string) {
|
||||||
|
id := str.ToInteger[uint64](wpconfig.Options.Value("site_icon"), 0)
|
||||||
|
if id < 1 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
icon, err := cache.GetPostById(h.C, id)
|
||||||
|
if err != nil || icon.AttachmentMetadata.File == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
m := strings.Join(strings.Split(icon.AttachmentMetadata.File, "/")[:2], "/")
|
||||||
|
size := slice.FilterAndMap(sizes, func(t string) (string, bool) {
|
||||||
|
s, ok := icon.AttachmentMetadata.Sizes[t]
|
||||||
|
if !ok {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
switch t {
|
||||||
|
case "site_icon-270":
|
||||||
|
return fmt.Sprintf(`<meta name="msapplication-TileImage" content="/wp-content/uploads/%s/%s" />`, m, s.File), true
|
||||||
|
case "site_icon-180":
|
||||||
|
return fmt.Sprintf(`<link rel="apple-touch-icon" href="/wp-content/uploads/%s/%s" />"`, m, s.File), true
|
||||||
|
default:
|
||||||
|
ss := strings.Replace(t, "site_icon-", "", 1)
|
||||||
|
return fmt.Sprintf(`<link rel="icon" href="/wp-content/uploads/%s/%s" sizes="%sx%s" />`, m, s.File, ss, ss), true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
r = strings.Join(size, "\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *Handle) SiteIcon() {
|
||||||
|
s := icon.Load()
|
||||||
|
if s == "default" {
|
||||||
|
s = h.CalSiteIcon()
|
||||||
|
icon.Store(s)
|
||||||
|
}
|
||||||
|
h.GinH["siteIcon"] = s
|
||||||
|
}
|
|
@ -64,4 +64,9 @@
|
||||||
{{if .customHeader}}
|
{{if .customHeader}}
|
||||||
{{.customHeader|unescaped}}
|
{{.customHeader|unescaped}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|
||||||
|
{{if .siteIcon}}
|
||||||
|
{{.siteIcon|unescaped}}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{end}}
|
{{end}}
|
Loading…
Reference in New Issue
Block a user