完善twenty seventeen

This commit is contained in:
xing 2023-02-17 00:20:38 +08:00
parent cd5a9eadd7
commit 7d95109e78
12 changed files with 257 additions and 75 deletions

View File

@ -3,6 +3,7 @@ package common
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/maps"
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"
@ -16,9 +17,12 @@ func (h *Handle) CalCustomLogo() (r string) {
return
}
id := uint64(mods.CustomLogo)
if id < 1 {
id = str.ToInteger[uint64](wpconfig.Options.Value("site_logo"), 0)
if id < 1 {
return
}
}
logo, err := cache.GetPostById(h.C, id)
if err != nil || logo.AttachmentMetadata.File == "" {
return

View File

@ -0,0 +1,21 @@
{{define "common/head"}}
{{if .customBackground}}
{{.customBackground|unescaped}}
{{end}}
{{if .customHeader}}
{{.customHeader|unescaped}}
{{end}}
{{if .siteIcon}}
{{.siteIcon|unescaped}}
{{end}}
{{if .customCss}}
{{.customCss|unescaped}}
{{end}}
{{end}}
{{define "common/customLogo"}}
{{if .customLogo}}
{{.customLogo|unescaped}}
{{end}}
{{end}}

View File

@ -33,7 +33,7 @@ func commonTemplate(t *multipTemplate.MultipleFsTemplate) {
for _, main := range m {
file := filepath.Base(main)
dir := strings.Split(main, "/")[0]
templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml")))
templ := template.Must(template.New(file).Funcs(t.FuncMap).ParseFS(t.Fs, main, filepath.Join(dir, "layout/*.gohtml"), "common/template.gohtml"))
t.SetTemplate(main, templ)
}
}

View File

@ -16,9 +16,7 @@
<div id="sidebar" class="sidebar" style="position: relative; ">
<header id="masthead" class="site-header">
<div class="site-branding">
{{if .customLogo}}
{{.customLogo|unescaped}}
{{end}}
{{template "common/customLogo" .}}
<h1 class="site-title">
<a href="/" rel="home">{{ "blogname"| getOption }}</a>
</h1>

View File

@ -58,18 +58,6 @@
<meta name="generator" content="WordPress 6.0.2" />
<style>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
{{if .customBackground}}
{{.customBackground|unescaped}}
{{end}}
{{if .customHeader}}
{{.customHeader|unescaped}}
{{end}}
{{if .siteIcon}}
{{.siteIcon|unescaped}}
{{end}}
{{if .customCss}}
{{.customCss|unescaped}}
{{end}}
{{template "common/head" .}}
{{end}}

View File

@ -1,13 +1,8 @@
package twentyfifteen
import (
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/pkg/cache"
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"github.com/fthvgb1/wp-go/internal/theme/common"
"github.com/gin-gonic/gin"
)
const ThemeName = "twentyfifteen"
@ -49,27 +44,3 @@ func (h *handle) Detail() {
h.CustomHeader()
h.Details()
}
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
r.Path = "/wp-content/themes/twentyseventeen/assets/images/header.jpg"
r.Width = 2000
r.Height = 1200
hs, err := cache.GetHeaderImages(c, ThemeName)
if err != nil {
logs.ErrPrintln(err, "获取页眉背景图失败")
} else if len(hs) > 0 && err == nil {
_, r = slice.Rand(hs)
}
r.Sizes = "100vw"
return
}
func ThemeSupport() map[string]struct{} {
return map[string]struct{}{
"custom-background": {},
"wp-custom-logo": {},
"responsive-embeds": {},
"post-formats": {},
}
}

View File

@ -22,6 +22,7 @@
<div class="site-branding" style="margin-bottom: 0px;">
<div class="wrap">
{{template "common/customLogo" .}}
<div class="site-branding-text">
<h1 class="site-title">
<a href="/" rel="home">{{ "blogname"| getOption }}</a>

View File

@ -64,4 +64,7 @@
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="/wp-includes/wlwmanifest.xml" />
<meta name="generator" content="WordPress 6.1.1" />
<style>.recentcomments a{display:inline !important;padding:0 !important;margin:0 !important;}</style>
{{template "common/head" .}}
{{end}}

View File

@ -0,0 +1,134 @@
{
"core-block-patterns": true,
"widgets-block-editor": true,
"automatic-feed-links": true,
"title-tag": true,
"custom-line-height": true,
"post-thumbnails": true,
"menus": true,
"html5": [
"comment-form",
"comment-list",
"gallery",
"caption",
"script",
"style",
"navigation-widgets"
],
"post-formats": [
"aside",
"image",
"video",
"quote",
"link",
"gallery",
"audio"
],
"custom-logo": {
"width": 250,
"height": 250,
"flex-width": true,
"flex-height": false,
"header-text": "",
"unlink-homepage-logo": false
},
"customize-selective-refresh-widgets": true,
"editor-style": true,
"editor-styles": true,
"wp-block-styles": true,
"responsive-embeds": true,
"starter-content": {
"widgets": {
"sidebar-1": [
"text_business_info",
"search",
"text_about"
],
"sidebar-2": [
"text_business_info"
],
"sidebar-3": [
"text_about",
"search"
]
},
"posts": {
"0": "home",
"about": {
"thumbnail": "{{image-sandwich}}"
},
"contact": {
"thumbnail": "{{image-espresso}}"
},
"blog": {
"thumbnail": "{{image-coffee}}"
},
"homepage-section": {
"thumbnail": "{{image-espresso}}"
}
},
"attachments": {
"image-espresso": {
"post_title": "浓缩咖啡",
"file": "assets\/images\/espresso.jpg"
},
"image-sandwich": {
"post_title": "三明治",
"file": "assets\/images\/sandwich.jpg"
},
"image-coffee": {
"post_title": "咖啡",
"file": "assets\/images\/coffee.jpg"
}
},
"options": {
"show_on_front": "page",
"page_on_front": "{{home}}",
"page_for_posts": "{{blog}}"
},
"theme_mods": {
"panel_1": "{{homepage-section}}",
"panel_2": "{{about}}",
"panel_3": "{{blog}}",
"panel_4": "{{contact}}"
},
"nav_menus": {
"top": {
"name": "顶部菜单",
"items": [
"link_home",
"page_about",
"page_blog",
"page_contact"
]
},
"social": {
"name": "社交网络链接菜单",
"items": [
"link_yelp",
"link_facebook",
"link_twitter",
"link_instagram",
"link_email"
]
}
}
},
"custom-header": {
"default-image": "http:\/\/wp.test\/wp-content\/themes\/twentyseventeen\/assets\/images\/header.jpg",
"random-default": false,
"width": 2000,
"height": 1200,
"flex-height": true,
"flex-width": false,
"default-text-color": "",
"header-text": true,
"uploads": true,
"wp-head-callback": "twentyseventeen_header_style",
"admin-head-callback": "",
"admin-preview-callback": "",
"video": true,
"video-active-callback": "is_front_page"
},
"widgets": true
}

View File

@ -82,11 +82,9 @@ func (i *indexHandle) Index() {
i.C.HTML(i.Code, i.Templ, i.GinH)
return
}
i.PostsPlugins = pluginFns
i.PageEle = paginate
i.ExecListPagePlugin(pluginFns)
i.Pagination()
i.GinH["bodyClass"] = i.h.bodyClass()
i.C.HTML(i.Code, i.Templ, i.GinH)
i.Render()
}
func (d *detailHandle) Detail() {
@ -105,12 +103,10 @@ func (d *detailHandle) Detail() {
img.Sizes = "100vw"
img.Srcset = fmt.Sprintf("%s %dw, %s", img.Path, img.Width, img.Srcset)
d.Post.Thumbnail = img
d.GinH["post"] = d.Post
d.CommentRender = commentFormat
d.RenderComment()
d.PasswordProject()
d.Templ = "twentyseventeen/posts/detail.gohtml"
d.C.HTML(d.Code, d.Templ, d.GinH)
d.GinH["post"] = d.Post
d.Render()
}
var commentFormat = comment{}
@ -195,12 +191,3 @@ var class = map[int]string{
constraints.Search: "search ",
constraints.Detail: "post-template-default single single-post single-format-standard ",
}
func ThemeSupport() map[string]struct{} {
return map[string]struct{}{
"custom-header": {},
"wp-custom-logo": {},
"responsive-embeds": {},
"post-formats": {},
}
}

View File

@ -18,7 +18,7 @@ func SetTemplateFs(fs embed.FS) {
templateFs = fs
}
type ThemeMods struct {
type ThemeMod struct {
CustomCssPostId int `json:"custom_css_post_id,omitempty"`
NavMenuLocations []string `json:"nav_menu_locations,omitempty"`
CustomLogo int `json:"custom_logo,omitempty"`
@ -103,13 +103,13 @@ func Thumbnail(metadata models.WpAttachmentMetadata, Type, host string, except .
return
}
var themeModes = safety.Map[string, ThemeMods]{}
var themeModes = safety.Map[string, ThemeMod]{}
func FlushModes() {
themeModes.Flush()
}
func GetThemeMods(theme string) (r ThemeMods, err error) {
func GetThemeMods(theme string) (r ThemeMod, err error) {
r, ok := themeModes.Load(theme)
if ok {
return
@ -119,7 +119,7 @@ func GetThemeMods(theme string) (r ThemeMods, err error) {
if !ok || mods == "" {
return
}
r, err = phphelper.UnPHPSerialize[ThemeMods](mods)
r, err = phphelper.UnPHPSerialize[ThemeMod](mods)
if err != nil {
return
}
@ -141,7 +141,7 @@ func IsCustomBackground(theme string) bool {
return false
}
func (m *ThemeMods) setThemeColorScheme(themeName string) {
func (m *ThemeMod) setThemeColorScheme(themeName string) {
bytes, err := templateFs.ReadFile(filepath.Join(themeName, "colorscheme.json"))
if err != nil {
return
@ -153,7 +153,7 @@ func (m *ThemeMods) setThemeColorScheme(themeName string) {
}
m.ColorScheme = scheme
}
func (m *ThemeMods) setThemeSupport(themeName string) {
func (m *ThemeMod) setThemeSupport(themeName string) {
bytes, err := templateFs.ReadFile(filepath.Join(themeName, "themesupport.json"))
if err != nil {
return

View File

@ -4,7 +4,8 @@ type ThemeSupport struct {
CoreBlockPatterns bool `json:"core-block-patterns"`
WidgetsBlockEditor bool `json:"widgets-block-editor"`
AutomaticFeedLinks bool `json:"automatic-feed-links"`
TitleTag bool `json:"title-tag"`
TitleTag bool
CustomLineHeight bool `json:"title-tag"`
PostThumbnails bool `json:"post-thumbnails"`
Menus bool `json:"menus"`
HTML5 []string `json:"html5"`
@ -18,6 +19,7 @@ type ThemeSupport struct {
EditorColorPalette []EditorColorPalette `json:"editor-color-palette"`
EditorGradientPresets []EditorGradientPresets `json:"editor-gradient-presets"`
CustomizeSelectiveRefreshWidgets bool `json:"customize-selective-refresh-widgets"`
StarterContent StarterContent `json:"starter-content"`
CustomHeader CustomHeader `json:"custom-header"`
Widgets bool `json:"widgets"`
}
@ -29,6 +31,23 @@ type CustomLogo struct {
HeaderText string `json:"header-text"`
UnlinkHomepageLogo bool `json:"unlink-homepage-logo"`
}
type Widgets struct {
Sidebar1 []string `json:"sidebar-1"`
Sidebar2 []string `json:"sidebar-2"`
Sidebar3 []string `json:"sidebar-3"`
}
type About struct {
Thumbnail string `json:"thumbnail"`
}
type Contact struct {
Thumbnail string `json:"thumbnail"`
}
type Blog struct {
Thumbnail string `json:"thumbnail"`
}
type HomepageSection struct {
Thumbnail string `json:"thumbnail"`
}
type CustomBackground struct {
DefaultImage string `json:"default-image"`
DefaultPreset string `json:"default-preset"`
@ -52,6 +71,62 @@ type EditorGradientPresets struct {
Slug string `json:"slug"`
Gradient string `json:"gradient"`
}
type Posts struct {
Num0 string `json:"0"`
About About `json:"about"`
Contact Contact `json:"contact"`
Blog Blog `json:"blog"`
HomepageSection HomepageSection `json:"homepage-section"`
}
type ImageEspresso struct {
PostTitle string `json:"post_title"`
File string `json:"file"`
}
type ImageSandwich struct {
PostTitle string `json:"post_title"`
File string `json:"file"`
}
type ImageCoffee struct {
PostTitle string `json:"post_title"`
File string `json:"file"`
}
type Attachments struct {
ImageEspresso ImageEspresso `json:"image-espresso"`
ImageSandwich ImageSandwich `json:"image-sandwich"`
ImageCoffee ImageCoffee `json:"image-coffee"`
}
type Option struct {
ShowOnFront string `json:"show_on_front"`
PageOnFront string `json:"page_on_front"`
PageForPosts string `json:"page_for_posts"`
}
type ThemeMods struct {
Panel1 string `json:"panel_1"`
Panel2 string `json:"panel_2"`
Panel3 string `json:"panel_3"`
Panel4 string `json:"panel_4"`
}
type Top struct {
Name string `json:"name"`
Items []string `json:"items"`
}
type Social struct {
Name string `json:"name"`
Items []string `json:"items"`
}
type NavMenus struct {
Top Top `json:"top"`
Social Social `json:"social"`
}
type StarterContent struct {
Widgets Widgets `json:"widgets"`
Posts Posts `json:"posts"`
Attachments Attachments `json:"attachments"`
Options Option `json:"options"`
ThemeMods ThemeMods `json:"theme_mods"`
NavMenus NavMenus `json:"nav_menus"`
}
type CustomHeader struct {
DefaultImage string `json:"default-image"`
RandomDefault bool `json:"random-default"`