完善twentyseventeen的 配色

This commit is contained in:
xing 2023-03-01 22:52:05 +08:00
parent 9af2a04a97
commit ae20829209
4 changed files with 92 additions and 10 deletions

View File

@ -11,6 +11,7 @@ func InitTheme() {
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
twentyfifteen.Init(TemplateFs)
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
twentyseventeen.Init(TemplateFs)
}
func GetTemplateName() string {

View File

@ -15,13 +15,15 @@ func colorScheme(h *wp.Handle) (r string) {
}
s := str.NewBuilder()
hue := number.ToString(wpconfig.GetThemeModsVal[int64](ThemeName, "colorscheme_hue", 250))
saturation := fmt.Sprintf("%d%%", int(.8*50))
reducedSaturation := fmt.Sprintf("%d%%", int(.8*50))
saturation := fmt.Sprintf("%d%%", 50)
css := customCss
for k, v := range map[string]string{
"' . $hue . '": hue,
"' . esc_attr( $hue ) . '": hue,
"' . $saturation . '": saturation,
"' . esc_attr( $saturation ) .' ": saturation,
"' . $reduced_saturation . '": reducedSaturation,
} {
css = strings.ReplaceAll(css, k, v)
}

View File

@ -1,17 +1,81 @@
package twentyseventeen
type themeSupport struct {
CustomLineHeight bool `json:"custom-line-height"`
StarterContent StarterContent `json:"starter-content"`
}
type EditorColorPalette struct {
Name string `json:"name"`
Slug string `json:"slug"`
Color string `json:"color"`
type Widgets struct {
Sidebar1 []string `json:"sidebar-1"`
Sidebar2 []string `json:"sidebar-2"`
Sidebar3 []string `json:"sidebar-3"`
}
type EditorGradientPresets struct {
Name string `json:"name"`
Slug string `json:"slug"`
Gradient string `json:"gradient"`
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 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 Options 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 Options `json:"options"`
ThemeMods ThemeMods `json:"theme_mods"`
NavMenus NavMenus `json:"nav_menus"`
}
var themesupport = themeSupport{}
var themesupport themeSupport

View File

@ -1,6 +1,8 @@
package twentyseventeen
import (
"embed"
"encoding/json"
"fmt"
"github.com/fthvgb1/wp-go/helper"
"github.com/fthvgb1/wp-go/helper/maps"
@ -17,6 +19,14 @@ import (
const ThemeName = "twentyseventeen"
func Init(fs embed.FS) {
b, err := fs.ReadFile(str.Join(ThemeName, "/themesupport.json"))
if err != nil {
return
}
err = json.Unmarshal(b, &themesupport)
}
var paginate = func() plugins.PageEle {
p := plugins.TwentyFifteenPagination()
p.PrevEle = `<a class="prev page-numbers" href="%s"><svg class="icon icon-arrow-left" aria-hidden="true" role="img"> <use href="#icon-arrow-left" xlink:href="#icon-arrow-left"></use> </svg>
@ -41,6 +51,11 @@ func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) {
wp.NewComponents(colorScheme, 10),
wp.NewComponents(customHeader, 10),
)
if "dark" == wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light") {
h.PushHeadScript(wp.NewComponents(func(h *wp.Handle) string {
return ` <link rel="stylesheet" id="twentyseventeen-colors-dark-css" href="/wp-content/themes/twentyseventeen/assets/css/colors-dark.css?ver=20191025" media="all">`
}, 10))
}
h.SetData("HeaderImage", getHeaderImage(h))
h.SetData("scene", h.Scene())
next(h)