🤮🤮 todo .....

This commit is contained in:
xing 2023-07-17 22:43:15 +08:00
parent 6137502ef9
commit 74c88b1385
9 changed files with 1305 additions and 1125 deletions

View File

@ -21,9 +21,9 @@ func pushScripts(h *wp.Handle) {
[]string{"twentyseventeen-style"}, "20191025", "") []string{"twentyseventeen-style"}, "20191025", "")
} }
scriptloader.AddData("twentyseventeen-ie8", "conditional", "lt IE 9") scriptloader.AddScriptData("twentyseventeen-ie8", "conditional", "lt IE 9")
scriptloader.EnqueueScripts("html5", "/assets/js/html5.js", nil, "20161020", false) scriptloader.EnqueueScripts("html5", "/assets/js/html5.js", nil, "20161020", false)
scriptloader.AddData("html5", "conditional", "lt IE 9") scriptloader.AddScriptData("html5", "conditional", "lt IE 9")
scriptloader.EnqueueScripts("twentyseventeen-skip-link-focus-fix", "/assets/js/skip-link-focus-fix.js", scriptloader.EnqueueScripts("twentyseventeen-skip-link-focus-fix", "/assets/js/skip-link-focus-fix.js",
nil, "20161114", true) nil, "20161114", true)

View File

@ -43,7 +43,7 @@ func configs(h *wp.Handle) {
components.WidgetArea(h) components.WidgetArea(h)
pushScripts(h) pushScripts(h)
h.PushRender(constraints.AllStats, wp.NewHandleFn(calCustomHeader, 10.005, "calCustomHeader")) h.PushRender(constraints.AllStats, wp.NewHandleFn(calCustomHeader, 10.005, "calCustomHeader"))
h.SetComponentsArgs(widgets.Widget, map[string]string{ wp.SetComponentsArgs(h, widgets.Widget, map[string]string{
"{$before_widget}": `<section id="%s" class="%s">`, "{$before_widget}": `<section id="%s" class="%s">`,
"{$after_widget}": `</section>`, "{$after_widget}": `</section>`,
}) })

View File

@ -190,7 +190,7 @@ func MergeComponentsArgsForMap[K comparable, V any](h *Handle, name string, m ma
} }
} }
func (h *Handle) SetComponentsArgs(key string, value any) { func SetComponentsArgs(h *Handle, key string, value any) {
h.componentsArgs[key] = value h.componentsArgs[key] = value
} }

View File

@ -366,121 +366,121 @@ func defaultTranslate() {
} }
func defaultAddData() { func defaultAddData() {
AddData("json2", "conditional", `lt IE 8`) AddScriptData("json2", "conditional", `lt IE 8`)
AddData("wp-embed-template-ie", "conditional", `lte IE 8`) AddScriptData("wp-embed-template-ie", "conditional", `lte IE 8`)
AddData("wp-block-library-theme", "path", `wp-includes/css/dist/block-library/theme.min.css`) AddScriptData("wp-block-library-theme", "path", `wp-includes/css/dist/block-library/theme.min.css`)
AddData("wp-block-editor", "path", `/wp-includes/css/dist/block-editor/style.min.css`) AddScriptData("wp-block-editor", "path", `/wp-includes/css/dist/block-editor/style.min.css`)
AddData("wp-block-library", "path", `/wp-includes/css/dist/block-library/style.min.css`) AddScriptData("wp-block-library", "path", `/wp-includes/css/dist/block-library/style.min.css`)
AddData("wp-block-directory", "path", `/wp-includes/css/dist/block-directory/style.min.css`) AddScriptData("wp-block-directory", "path", `/wp-includes/css/dist/block-directory/style.min.css`)
AddData("wp-components", "path", `/wp-includes/css/dist/components/style.min.css`) AddScriptData("wp-components", "path", `/wp-includes/css/dist/components/style.min.css`)
AddData("wp-edit-post", "path", `/wp-includes/css/dist/edit-post/style.min.css`) AddScriptData("wp-edit-post", "path", `/wp-includes/css/dist/edit-post/style.min.css`)
AddData("wp-editor", "path", `/wp-includes/css/dist/editor/style.min.css`) AddScriptData("wp-editor", "path", `/wp-includes/css/dist/editor/style.min.css`)
AddData("wp-format-library", "path", `/wp-includes/css/dist/format-library/style.min.css`) AddScriptData("wp-format-library", "path", `/wp-includes/css/dist/format-library/style.min.css`)
AddData("wp-list-reusable-blocks", "path", `/wp-includes/css/dist/list-reusable-blocks/style.min.css`) AddScriptData("wp-list-reusable-blocks", "path", `/wp-includes/css/dist/list-reusable-blocks/style.min.css`)
AddData("wp-reusable-blocks", "path", `/wp-includes/css/dist/reusable-blocks/style.min.css`) AddScriptData("wp-reusable-blocks", "path", `/wp-includes/css/dist/reusable-blocks/style.min.css`)
AddData("wp-nux", "path", `/wp-includes/css/dist/nux/style.min.css`) AddScriptData("wp-nux", "path", `/wp-includes/css/dist/nux/style.min.css`)
AddData("wp-widgets", "path", `/wp-includes/css/dist/widgets/style.min.css`) AddScriptData("wp-widgets", "path", `/wp-includes/css/dist/widgets/style.min.css`)
AddData("wp-edit-widgets", "path", `/wp-includes/css/dist/edit-widgets/style.min.css`) AddScriptData("wp-edit-widgets", "path", `/wp-includes/css/dist/edit-widgets/style.min.css`)
AddData("wp-customize-widgets", "path", `/wp-includes/css/dist/customize-widgets/style.min.css`) AddScriptData("wp-customize-widgets", "path", `/wp-includes/css/dist/customize-widgets/style.min.css`)
AddData("wp-edit-site", "path", `/wp-includes/css/dist/edit-site/style.min.css`) AddScriptData("wp-edit-site", "path", `/wp-includes/css/dist/edit-site/style.min.css`)
AddData("common", "rtl", `replace`) AddScriptData("common", "rtl", `replace`)
AddData("common", "suffix", `.min`) AddScriptData("common", "suffix", `.min`)
AddData("forms", "rtl", `replace`) AddScriptData("forms", "rtl", `replace`)
AddData("forms", "suffix", `.min`) AddScriptData("forms", "suffix", `.min`)
AddData("admin-menu", "rtl", `replace`) AddScriptData("admin-menu", "rtl", `replace`)
AddData("admin-menu", "suffix", `.min`) AddScriptData("admin-menu", "suffix", `.min`)
AddData("dashboard", "rtl", `replace`) AddScriptData("dashboard", "rtl", `replace`)
AddData("dashboard", "suffix", `.min`) AddScriptData("dashboard", "suffix", `.min`)
AddData("list-tables", "rtl", `replace`) AddScriptData("list-tables", "rtl", `replace`)
AddData("list-tables", "suffix", `.min`) AddScriptData("list-tables", "suffix", `.min`)
AddData("edit", "rtl", `replace`) AddScriptData("edit", "rtl", `replace`)
AddData("edit", "suffix", `.min`) AddScriptData("edit", "suffix", `.min`)
AddData("revisions", "rtl", `replace`) AddScriptData("revisions", "rtl", `replace`)
AddData("revisions", "suffix", `.min`) AddScriptData("revisions", "suffix", `.min`)
AddData("media", "rtl", `replace`) AddScriptData("media", "rtl", `replace`)
AddData("media", "suffix", `.min`) AddScriptData("media", "suffix", `.min`)
AddData("themes", "rtl", `replace`) AddScriptData("themes", "rtl", `replace`)
AddData("themes", "suffix", `.min`) AddScriptData("themes", "suffix", `.min`)
AddData("about", "rtl", `replace`) AddScriptData("about", "rtl", `replace`)
AddData("about", "suffix", `.min`) AddScriptData("about", "suffix", `.min`)
AddData("nav-menus", "rtl", `replace`) AddScriptData("nav-menus", "rtl", `replace`)
AddData("nav-menus", "suffix", `.min`) AddScriptData("nav-menus", "suffix", `.min`)
AddData("widgets", "rtl", `replace`) AddScriptData("widgets", "rtl", `replace`)
AddData("widgets", "suffix", `.min`) AddScriptData("widgets", "suffix", `.min`)
AddData("site-icon", "rtl", `replace`) AddScriptData("site-icon", "rtl", `replace`)
AddData("site-icon", "suffix", `.min`) AddScriptData("site-icon", "suffix", `.min`)
AddData("l10n", "rtl", `replace`) AddScriptData("l10n", "rtl", `replace`)
AddData("l10n", "suffix", `.min`) AddScriptData("l10n", "suffix", `.min`)
AddData("install", "rtl", `replace`) AddScriptData("install", "rtl", `replace`)
AddData("install", "suffix", `.min`) AddScriptData("install", "suffix", `.min`)
AddData("wp-color-picker", "rtl", `replace`) AddScriptData("wp-color-picker", "rtl", `replace`)
AddData("wp-color-picker", "suffix", `.min`) AddScriptData("wp-color-picker", "suffix", `.min`)
AddData("customize-controls", "rtl", `replace`) AddScriptData("customize-controls", "rtl", `replace`)
AddData("customize-controls", "suffix", `.min`) AddScriptData("customize-controls", "suffix", `.min`)
AddData("customize-widgets", "rtl", `replace`) AddScriptData("customize-widgets", "rtl", `replace`)
AddData("customize-widgets", "suffix", `.min`) AddScriptData("customize-widgets", "suffix", `.min`)
AddData("customize-nav-menus", "rtl", `replace`) AddScriptData("customize-nav-menus", "rtl", `replace`)
AddData("customize-nav-menus", "suffix", `.min`) AddScriptData("customize-nav-menus", "suffix", `.min`)
AddData("customize-preview", "rtl", `replace`) AddScriptData("customize-preview", "rtl", `replace`)
AddData("customize-preview", "suffix", `.min`) AddScriptData("customize-preview", "suffix", `.min`)
AddData("login", "rtl", `replace`) AddScriptData("login", "rtl", `replace`)
AddData("login", "suffix", `.min`) AddScriptData("login", "suffix", `.min`)
AddData("site-health", "rtl", `replace`) AddScriptData("site-health", "rtl", `replace`)
AddData("site-health", "suffix", `.min`) AddScriptData("site-health", "suffix", `.min`)
AddData("buttons", "rtl", `replace`) AddScriptData("buttons", "rtl", `replace`)
AddData("buttons", "suffix", `.min`) AddScriptData("buttons", "suffix", `.min`)
AddData("admin-bar", "rtl", `replace`) AddScriptData("admin-bar", "rtl", `replace`)
AddData("admin-bar", "suffix", `.min`) AddScriptData("admin-bar", "suffix", `.min`)
AddData("wp-auth-check", "rtl", `replace`) AddScriptData("wp-auth-check", "rtl", `replace`)
AddData("wp-auth-check", "suffix", `.min`) AddScriptData("wp-auth-check", "suffix", `.min`)
AddData("editor-buttons", "rtl", `replace`) AddScriptData("editor-buttons", "rtl", `replace`)
AddData("editor-buttons", "suffix", `.min`) AddScriptData("editor-buttons", "suffix", `.min`)
AddData("media-views", "rtl", `replace`) AddScriptData("media-views", "rtl", `replace`)
AddData("media-views", "suffix", `.min`) AddScriptData("media-views", "suffix", `.min`)
AddData("wp-pointer", "rtl", `replace`) AddScriptData("wp-pointer", "rtl", `replace`)
AddData("wp-pointer", "suffix", `.min`) AddScriptData("wp-pointer", "suffix", `.min`)
AddData("wp-jquery-ui-dialog", "rtl", `replace`) AddScriptData("wp-jquery-ui-dialog", "rtl", `replace`)
AddData("wp-jquery-ui-dialog", "suffix", `.min`) AddScriptData("wp-jquery-ui-dialog", "suffix", `.min`)
AddData("wp-reset-editor-styles", "rtl", `replace`) AddScriptData("wp-reset-editor-styles", "rtl", `replace`)
AddData("wp-reset-editor-styles", "suffix", `.min`) AddScriptData("wp-reset-editor-styles", "suffix", `.min`)
AddData("wp-editor-classic-layout-styles", "rtl", `replace`) AddScriptData("wp-editor-classic-layout-styles", "rtl", `replace`)
AddData("wp-editor-classic-layout-styles", "suffix", `.min`) AddScriptData("wp-editor-classic-layout-styles", "suffix", `.min`)
AddData("wp-block-library-theme", "rtl", `replace`) AddScriptData("wp-block-library-theme", "rtl", `replace`)
AddData("wp-block-library-theme", "suffix", `.min`) AddScriptData("wp-block-library-theme", "suffix", `.min`)
AddData("wp-edit-blocks", "rtl", `replace`) AddScriptData("wp-edit-blocks", "rtl", `replace`)
AddData("wp-edit-blocks", "suffix", `.min`) AddScriptData("wp-edit-blocks", "suffix", `.min`)
AddData("wp-block-editor", "rtl", `replace`) AddScriptData("wp-block-editor", "rtl", `replace`)
AddData("wp-block-editor", "suffix", `.min`) AddScriptData("wp-block-editor", "suffix", `.min`)
AddData("wp-block-library", "rtl", `replace`) AddScriptData("wp-block-library", "rtl", `replace`)
AddData("wp-block-library", "suffix", `.min`) AddScriptData("wp-block-library", "suffix", `.min`)
AddData("wp-block-directory", "rtl", `replace`) AddScriptData("wp-block-directory", "rtl", `replace`)
AddData("wp-block-directory", "suffix", `.min`) AddScriptData("wp-block-directory", "suffix", `.min`)
AddData("wp-components", "rtl", `replace`) AddScriptData("wp-components", "rtl", `replace`)
AddData("wp-components", "suffix", `.min`) AddScriptData("wp-components", "suffix", `.min`)
AddData("wp-customize-widgets", "rtl", `replace`) AddScriptData("wp-customize-widgets", "rtl", `replace`)
AddData("wp-customize-widgets", "suffix", `.min`) AddScriptData("wp-customize-widgets", "suffix", `.min`)
AddData("wp-edit-post", "rtl", `replace`) AddScriptData("wp-edit-post", "rtl", `replace`)
AddData("wp-edit-post", "suffix", `.min`) AddScriptData("wp-edit-post", "suffix", `.min`)
AddData("wp-edit-site", "rtl", `replace`) AddScriptData("wp-edit-site", "rtl", `replace`)
AddData("wp-edit-site", "suffix", `.min`) AddScriptData("wp-edit-site", "suffix", `.min`)
AddData("wp-edit-widgets", "rtl", `replace`) AddScriptData("wp-edit-widgets", "rtl", `replace`)
AddData("wp-edit-widgets", "suffix", `.min`) AddScriptData("wp-edit-widgets", "suffix", `.min`)
AddData("wp-editor", "rtl", `replace`) AddScriptData("wp-editor", "rtl", `replace`)
AddData("wp-editor", "suffix", `.min`) AddScriptData("wp-editor", "suffix", `.min`)
AddData("wp-format-library", "rtl", `replace`) AddScriptData("wp-format-library", "rtl", `replace`)
AddData("wp-format-library", "suffix", `.min`) AddScriptData("wp-format-library", "suffix", `.min`)
AddData("wp-list-reusable-blocks", "rtl", `replace`) AddScriptData("wp-list-reusable-blocks", "rtl", `replace`)
AddData("wp-list-reusable-blocks", "suffix", `.min`) AddScriptData("wp-list-reusable-blocks", "suffix", `.min`)
AddData("wp-reusable-blocks", "rtl", `replace`) AddScriptData("wp-reusable-blocks", "rtl", `replace`)
AddData("wp-reusable-blocks", "suffix", `.min`) AddScriptData("wp-reusable-blocks", "suffix", `.min`)
AddData("wp-nux", "rtl", `replace`) AddScriptData("wp-nux", "rtl", `replace`)
AddData("wp-nux", "suffix", `.min`) AddScriptData("wp-nux", "suffix", `.min`)
AddData("wp-widgets", "rtl", `replace`) AddScriptData("wp-widgets", "rtl", `replace`)
AddData("wp-widgets", "suffix", `.min`) AddScriptData("wp-widgets", "suffix", `.min`)
AddData("deprecated-media", "rtl", `replace`) AddScriptData("deprecated-media", "rtl", `replace`)
AddData("deprecated-media", "suffix", `.min`) AddScriptData("deprecated-media", "suffix", `.min`)
AddData("farbtastic", "rtl", `replace`) AddScriptData("farbtastic", "rtl", `replace`)
AddData("farbtastic", "suffix", `.min`) AddScriptData("farbtastic", "suffix", `.min`)
} }

View File

@ -2,6 +2,6 @@ package scriptloader
import "github.com/fthvgb1/wp-go/safety" import "github.com/fthvgb1/wp-go/safety"
func defaultStyles(m *safety.Map[string, *Script], suffix string) { func defaultStyles(m *safety.Map[string, *Style], suffix string) {
} }

View File

@ -1,10 +1,15 @@
package scriptloader package scriptloader
import ( import (
"encoding/json"
"github.com/fthvgb1/wp-go/app/cmd/reload"
"github.com/fthvgb1/wp-go/app/pkg/config"
"github.com/fthvgb1/wp-go/app/pkg/logs" "github.com/fthvgb1/wp-go/app/pkg/logs"
"github.com/fthvgb1/wp-go/app/theme/wp" "github.com/fthvgb1/wp-go/app/theme/wp"
"github.com/fthvgb1/wp-go/helper/slice" "github.com/fthvgb1/wp-go/helper/slice"
str "github.com/fthvgb1/wp-go/helper/strings"
"os" "os"
"path/filepath"
) )
type _style struct { type _style struct {
@ -50,13 +55,62 @@ func MaybeInlineStyles(h *wp.Handle) {
if totalInlineSize+i.size > totalInlineLimit { if totalInlineSize+i.size > totalInlineLimit {
break break
} }
css, err := os.ReadFile(i.path) path := filepath.Join(i.path)
if err != nil { css := reload.GetAnyValMapBy("script-loader-MaybeInlineStyles", i.handle, path, func(a string) string {
logs.Error(err, "read file ", i.path) css, err := os.ReadFile(i.path)
continue if err != nil {
} logs.Error(err, "read file ", i.path)
return ""
}
return string(css)
})
s, _ := __styles.Load(i.handle) s, _ := __styles.Load(i.handle)
s.Src = "" s.Src = ""
s.Extra["after"] = append(s.Extra["after"], string(css)) a := s.Extra["after"]
if a == nil {
a = []string{}
}
slice.Unshift(&a, css)
s.Extra["after"] = a
} }
} }
func emojiDetectionScript(h *wp.Handle) {
settings := map[string]any{
"baseUrl": "https://s.w.org/images/core/emoji/14.0.0/72x72/",
"ext": ".png",
"svgUrl": "https://s.w.org/images/core/emoji/14.0.0/svg/", "svgExt": ".svg",
"source": map[string]any{
"concatemoji": "/wp-includes/js/wp-emoji-release.min.js?ver=6.2.2",
},
}
setting, _ := json.Marshal(settings)
dir := config.GetConfig().WpDir
emotion := reload.GetAnyValBys("script-loader-emoji", struct{}{}, func(_ struct{}) string {
f, err := os.ReadFile(dir)
if err != nil {
logs.Error(err, "load emoji css fail", dir)
return ""
}
return string(f)
})
s := str.Join("window._wpemojiSettings = ", string(setting), "\n", emotion)
PrintInlineScriptTag(h, s, nil)
}
func PrintInlineScriptTag(h *wp.Handle, script string, attr map[string]string) {
ss := wp.GetComponentsArgs(h, "inlineScript", "")
s := str.NewBuilder()
s.WriteString(ss)
s.WriteString("<script")
for k, v := range attr {
s.Sprintf(` %s="%s"`, k, v)
}
s.Sprintf(">%s</script>\n", script)
wp.SetComponentsArgs(h, "inlineScript", s.String())
}
func PrintStyles(h *wp.Handle) {
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -390,6 +390,15 @@ func (m *Map[K, V]) Range(f func(key K, value V) bool) {
} }
} }
func (m *Map[K, V]) Keys() []K {
var r []K
m.Range(func(key K, _ V) bool {
r = append(r, key)
return true
})
return r
}
func (m *Map[K, V]) missLocked() { func (m *Map[K, V]) missLocked() {
m.misses++ m.misses++
if m.misses < len(m.dirty) { if m.misses < len(m.dirty) {