Compare commits
9 Commits
master
...
scriptload
Author | SHA1 | Date | |
---|---|---|---|
b8112bb970 | |||
cd5a12c9fd | |||
74c88b1385 | |||
6137502ef9 | |||
25bf1dd1f7 | |||
b247b8640d | |||
e44caae780 | |||
d81b484916 | |||
1d837d4bf8 |
|
@ -14,6 +14,7 @@ import (
|
|||
"github.com/fthvgb1/wp-go/app/plugins"
|
||||
"github.com/fthvgb1/wp-go/app/plugins/wphandle"
|
||||
"github.com/fthvgb1/wp-go/app/theme"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp/scriptloader"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/model"
|
||||
"log"
|
||||
|
@ -30,6 +31,12 @@ var address string
|
|||
var intReg = regexp.MustCompile(`^\d`)
|
||||
|
||||
func init() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println(r)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}()
|
||||
flag.StringVar(&confPath, "c", "config.yaml", "config file support json,yaml or url")
|
||||
flag.StringVar(&address, "p", "", "listen address and port")
|
||||
flag.Parse()
|
||||
|
@ -43,6 +50,7 @@ func init() {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
scriptloader.InitDefaultScriptSetting()
|
||||
cache.InitActionsCommonCache()
|
||||
plugins.InitDigestCache()
|
||||
theme.InitTheme()
|
||||
|
@ -116,6 +124,7 @@ func reloads() {
|
|||
logs.IfError(err, "获取网站设置WpOption失败")
|
||||
err = wpconfig.InitTerms()
|
||||
logs.IfError(err, "获取WpTerms表失败")
|
||||
scriptloader.InitDefaultScriptSetting()
|
||||
wphandle.LoadPlugins()
|
||||
reload.Reload()
|
||||
flushCache()
|
||||
|
@ -136,6 +145,12 @@ func signalNotify() {
|
|||
}
|
||||
|
||||
func main() {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
fmt.Println(r)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}()
|
||||
go signalNotify()
|
||||
Gin := route.SetupRouter()
|
||||
c := config.GetConfig()
|
||||
|
|
|
@ -169,6 +169,27 @@ func VarsBy[T any](fn func() T) *safety.Var[T] {
|
|||
})
|
||||
return ss
|
||||
}
|
||||
func MapBy[K comparable, T any](fn func(*safety.Map[K, T])) *safety.Map[K, T] {
|
||||
m := safety.NewMap[K, T]()
|
||||
if fn != nil {
|
||||
fn(m)
|
||||
}
|
||||
calls = append(calls, func() {
|
||||
m.Flush()
|
||||
if fn != nil {
|
||||
fn(m)
|
||||
}
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
func SafeMap[K comparable, T any]() *safety.Map[K, T] {
|
||||
m := safety.NewMap[K, T]()
|
||||
calls = append(calls, func() {
|
||||
m.Flush()
|
||||
})
|
||||
return m
|
||||
}
|
||||
|
||||
func Push(fn ...func()) {
|
||||
calls = append(calls, fn...)
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/soxfmr/gomail"
|
||||
"gopkg.in/gomail.v2"
|
||||
"mime"
|
||||
"path"
|
||||
)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
@ -32,13 +31,12 @@ type CommentHtml interface {
|
|||
|
||||
func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, maxDepth int) string {
|
||||
tree := treeComments(comments)
|
||||
u := c.Request.Header.Get("Referer")
|
||||
|
||||
var isTls bool
|
||||
if u != "" {
|
||||
uu, _ := url.Parse(u)
|
||||
if uu.Scheme == "https" {
|
||||
isTls = true
|
||||
}
|
||||
if c.Request.TLS != nil {
|
||||
isTls = true
|
||||
} else {
|
||||
isTls = "https" == strings.ToLower(c.Request.Header.Get("X-Forwarded-Proto"))
|
||||
}
|
||||
h := CommentHandler{
|
||||
Context: c,
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
func HiddenLogin(h *wp.Handle) {
|
||||
h.PushComponentFilterFn(widgets.Meta, func(h *wp.Handle, s string, args ...any) string {
|
||||
h.AddActionFilter(widgets.Meta, func(h *wp.Handle, s string, args ...any) string {
|
||||
return str.Replace(s, map[string]string{
|
||||
`<li><a href="/wp-login.php">登录</a></li>`: "",
|
||||
`<li><a href="/feed">登录</a></li>`: "",
|
||||
|
|
|
@ -18,12 +18,12 @@ func Hook(h *wp.Handle) {
|
|||
}
|
||||
|
||||
func configs(h *wp.Handle) {
|
||||
h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string, args ...any) string {
|
||||
h.AddActionFilter(widgets.Search, func(h *wp.Handle, s string, args ...any) string {
|
||||
return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`)
|
||||
})
|
||||
wp.InitPipe(h)
|
||||
h.PushHandler(constraints.PipeMiddleware, constraints.Home,
|
||||
wp.NewHandleFn(widget.IsCategory, 100, "widget.IsCategory"))
|
||||
wp.NewHandleFn(widget.CheckCategory, 100, "widget.CheckCategory"))
|
||||
|
||||
h.Index.SetPageEle(plugins.TwentyFifteenPagination())
|
||||
h.PushCacheGroupHeadScript(constraints.AllScene, "CalCustomBackGround", 10.005, CalCustomBackGround)
|
||||
|
|
|
@ -4,10 +4,56 @@ import (
|
|||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp/scriptloader"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/number"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
||||
func pushScripts(h *wp.Handle) {
|
||||
scriptloader.EnqueueStyle("twentyseventeen-style", scriptloader.GetStylesheetUri(), nil, "20230328", "")
|
||||
scriptloader.EnqueueStyles("twentyseventeen-block-style", "/assets/css/blocks.css", []string{"twentyseventeen-style"}, "20220912", "")
|
||||
|
||||
if "dark" == wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light") {
|
||||
scriptloader.EnqueueStyles("twentyseventeen-colors-dark", "/assets/css/colors-dark.css",
|
||||
[]string{"twentyseventeen-style"}, "20191025", "")
|
||||
}
|
||||
|
||||
scriptloader.AddScriptData("twentyseventeen-ie8", "conditional", "lt IE 9")
|
||||
scriptloader.EnqueueScripts("html5", "/assets/js/html5.js", nil, "20161020", false)
|
||||
scriptloader.AddScriptData("html5", "conditional", "lt IE 9")
|
||||
|
||||
scriptloader.EnqueueScripts("twentyseventeen-skip-link-focus-fix", "/assets/js/skip-link-focus-fix.js",
|
||||
nil, "20161114", true)
|
||||
|
||||
l10n := map[string]any{
|
||||
"quote": svg(h, map[string]string{"icon": "quote-right"}),
|
||||
}
|
||||
|
||||
scriptloader.EnqueueScripts("twentyseventeen-global", "/assets/js/global.js",
|
||||
[]string{"jquery"}, "20211130", true)
|
||||
|
||||
scriptloader.EnqueueScripts("jquery-scrollto", "/assets/js/jquery.scrollTo.js",
|
||||
[]string{"jquery"}, "2.1.3", true)
|
||||
scriptloader.EnqueueScripts("comment-reply", "", nil, "", false)
|
||||
|
||||
//todo menu top
|
||||
|
||||
scriptloader.AddStaticLocalize("twentyseventeen-skip-link-focus-fix", "twentyseventeenScreenReaderText", l10n)
|
||||
scriptloader.AddStaticLocalize("wp-custom-header", "_wpCustomHeaderSettings", map[string]any{
|
||||
"mimeType": `video/mp4`,
|
||||
"posterUrl": `/wp-content/uploads/2023/01/cropped-wallhaven-9dm7dd-1.png`,
|
||||
"videoUrl": `/wp-content/uploads/2023/06/BloodMoon_GettyRM_495644264_1080_HD_ZH-CN.mp4`,
|
||||
"width": `2000`,
|
||||
"height": `1199`,
|
||||
"minWidth": `900`,
|
||||
"minHeight": `500`,
|
||||
"l10n": map[string]any{
|
||||
"pause": `<span class="screen-reader-text">暂停背景视频</span><svg class="icon icon-pause" aria-hidden="true" role="img"> <use href="#icon-pause" xlink:href="#icon-pause"></use> </svg>`, "play": `<span class="screen-reader-text">播放背景视频</span><svg class="icon icon-play" aria-hidden="true" role="img"> <use href="#icon-play" xlink:href="#icon-play"></use> </svg>`, "pauseSpeak": `视频已暂停。`, "playSpeak": `视频正在播放。`,
|
||||
},
|
||||
})
|
||||
h.PushCacheGroupHeadScript(constraints.AllScene, "{theme}.head", 30, func(h *wp.Handle) string {
|
||||
head := headScript
|
||||
if "dark" == wpconfig.GetThemeModsVal(ThemeName, "colorscheme", "light") {
|
||||
|
@ -41,3 +87,37 @@ var footerScript = `<script id="twentyseventeen-skip-link-focus-fix-js-extra">
|
|||
<script src="/wp-content/themes/twentyseventeen/assets/js/skip-link-focus-fix.js?ver=20161114" id="twentyseventeen-skip-link-focus-fix-js"></script>
|
||||
<script src="/wp-content/themes/twentyseventeen/assets/js/global.js?ver=20211130" id="twentyseventeen-global-js"></script>
|
||||
<script src="/wp-content/themes/twentyseventeen/assets/js/jquery.scrollTo.js?ver=2.1.3" id="jquery-scrollto-js"></script>`
|
||||
|
||||
func svg(h *wp.Handle, m map[string]string) string {
|
||||
if !maps.IsExists(m, "icon") {
|
||||
return ""
|
||||
}
|
||||
ariaHidden := ` aria-hidden="true"`
|
||||
ariaLabelledby := ""
|
||||
uniqueId := ""
|
||||
if m["title"] != "" {
|
||||
ariaHidden = ""
|
||||
id := helper.GetContextVal(h.C, "svg", 0)
|
||||
uniqueId = number.IntToString(id)
|
||||
id++
|
||||
h.C.Set("svg", id)
|
||||
ariaLabelledby = str.Join(" aria-labelledby=\"title-", uniqueId, "\"")
|
||||
if m["desc"] != "" {
|
||||
ariaLabelledby = str.Join(" aria-labelledby=\"title-", uniqueId, " desc-", uniqueId, "\"")
|
||||
}
|
||||
}
|
||||
s := str.NewBuilder()
|
||||
s.WriteString("<svg class=\"icon icon-", m["icon"], "\"", ariaHidden, ariaLabelledby, " role=\"img\">")
|
||||
if m["title"] != "" {
|
||||
s.WriteString(`<title id="title-`, uniqueId, `">`, m["title"], "</title>")
|
||||
if m["desc"] != "" {
|
||||
s.WriteString(`<desc id="desc-`, uniqueId, `">`, m["desc"], `</desc>`)
|
||||
}
|
||||
}
|
||||
s.WriteString(` <use href="#icon-`, m["icon"], `" xlink:href="#icon-`, m["icon"], `"></use> `)
|
||||
if m["fallback"] != "" {
|
||||
s.WriteString(`<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>`)
|
||||
}
|
||||
s.WriteString(`<span class="svg-fallback icon-`, m["icon"], `"></span></svg>`)
|
||||
return s.String()
|
||||
}
|
||||
|
|
|
@ -37,13 +37,13 @@ func Hook(h *wp.Handle) {
|
|||
func configs(h *wp.Handle) {
|
||||
wp.InitPipe(h)
|
||||
h.PushHandler(constraints.PipeMiddleware, constraints.Home,
|
||||
wp.NewHandleFn(widget.IsCategory, 100.006, "widget.IsCategory"))
|
||||
h.PushComponentFilterFn("bodyClass", calClass)
|
||||
wp.NewHandleFn(widget.CheckCategory, 100.006, "widget.CheckCategory"))
|
||||
h.AddActionFilter("bodyClass", calClass)
|
||||
h.PushCacheGroupHeadScript(constraints.AllScene, "colorScheme-customHeader", 10, colorScheme, customHeader)
|
||||
components.WidgetArea(h)
|
||||
pushScripts(h)
|
||||
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">`,
|
||||
"{$after_widget}": `</section>`,
|
||||
})
|
||||
|
@ -176,7 +176,7 @@ func calClass(h *wp.Handle, s string, _ ...any) string {
|
|||
}
|
||||
|
||||
func videoHeader(h *wp.Handle) {
|
||||
h.PushComponentFilterFn("videoSetting", videoPlay)
|
||||
h.AddActionFilter("videoSetting", videoPlay)
|
||||
wp.CustomVideo(h, constraints.Home)
|
||||
}
|
||||
|
||||
|
|
|
@ -77,7 +77,7 @@ func (h *Handle) BodyClass() string {
|
|||
if h.themeMods.ThemeSupport.ResponsiveEmbeds {
|
||||
class = append(class, "wp-embed-responsive")
|
||||
}
|
||||
return h.ComponentFilterFnHook("bodyClass", strings.Join(class, " "))
|
||||
return h.DoActionFilter("bodyClass", strings.Join(class, " "))
|
||||
}
|
||||
|
||||
func postClass(h *Handle) func(posts models.Posts) string {
|
||||
|
@ -113,7 +113,7 @@ func (h *Handle) PostClass(posts models.Posts) string {
|
|||
class = append(class, TermClass(term))
|
||||
}
|
||||
|
||||
return h.ComponentFilterFnHook("postClass", strings.Join(class, " "))
|
||||
return h.DoActionFilter("postClass", strings.Join(class, " "))
|
||||
}
|
||||
|
||||
func TermClass(term models.TermsMy) string {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -199,10 +199,10 @@ func (h *Handle) ComponentFilterFn(name string) ([]func(*Handle, string, ...any)
|
|||
return fn, ok
|
||||
}
|
||||
|
||||
func (h *Handle) PushComponentFilterFn(name string, fns ...func(*Handle, string, ...any) string) {
|
||||
func (h *Handle) AddActionFilter(name string, fns ...func(*Handle, string, ...any) string) {
|
||||
h.componentFilterFn[name] = append(h.componentFilterFn[name], fns...)
|
||||
}
|
||||
func (h *Handle) ComponentFilterFnHook(name, s string, args ...any) string {
|
||||
func (h *Handle) DoActionFilter(name, s string, args ...any) string {
|
||||
calls, ok := h.componentFilterFn[name]
|
||||
if ok {
|
||||
return slice.Reduce(calls, func(fn func(*Handle, string, ...any) string, r string) string {
|
||||
|
|
|
@ -62,7 +62,7 @@ func Archive(h *wp.Handle, id string) string {
|
|||
} else {
|
||||
s = strings.ReplaceAll(s, "{$html}", archiveUl(h, conf, args, cache.Archives(h.C)))
|
||||
}
|
||||
return h.ComponentFilterFnHook(widgets.Archive, str.Replace(s, args))
|
||||
return h.DoActionFilter(widgets.Archive, str.Replace(s, args))
|
||||
}
|
||||
|
||||
var dropdownScript = `
|
||||
|
|
|
@ -69,7 +69,7 @@ func Category(h *wp.Handle, id string) string {
|
|||
} else {
|
||||
t = strings.ReplaceAll(t, "{$html}", categoryUL(h, args, conf, categories))
|
||||
}
|
||||
return h.ComponentFilterFnHook(widgets.Categories, str.Replace(t, args))
|
||||
return h.DoActionFilter(widgets.Categories, str.Replace(t, args))
|
||||
}
|
||||
|
||||
func CategoryLi(h *wp.Handle, conf map[any]any, categories []models.TermsMy) string {
|
||||
|
@ -232,10 +232,10 @@ func DropdownCategories(h *wp.Handle, args map[string]string, conf map[any]any,
|
|||
})
|
||||
}
|
||||
s.WriteString(" </select>\n")
|
||||
return h.ComponentFilterFnHook("wp_dropdown_cats", s.String())
|
||||
return h.DoActionFilter("wp_dropdown_cats", s.String())
|
||||
}
|
||||
|
||||
func IsCategory(h *wp.Handle) {
|
||||
func CheckCategory(h *wp.Handle) {
|
||||
name, ok := parseDropdownCate(h)
|
||||
if ok {
|
||||
h.C.Redirect(http.StatusMovedPermanently, fmt.Sprintf("/p/category/%s", name))
|
||||
|
@ -267,3 +267,28 @@ func parseDropdownCate(h *wp.Handle) (cateName string, r bool) {
|
|||
cateName = cc.Name
|
||||
return
|
||||
}
|
||||
|
||||
func IsCategory(h *wp.Handle) (category models.TermsMy, r bool) {
|
||||
cate := wp.GetComponentsArgs[map[string]string](h, widgets.Categories, categoryArgs())
|
||||
name, ok := cate["{$name}"]
|
||||
if !ok || name == "" {
|
||||
return
|
||||
}
|
||||
cat := h.C.Query(name)
|
||||
if cat == "" {
|
||||
return
|
||||
}
|
||||
id := str.ToInteger[uint64](cat, 0)
|
||||
if id < 1 {
|
||||
return
|
||||
}
|
||||
i, cc := slice.SearchFirst(cache.CategoriesTags(h.C, constraints.Category), func(my models.TermsMy) bool {
|
||||
return id == my.Terms.TermId
|
||||
})
|
||||
if i < 0 {
|
||||
return
|
||||
}
|
||||
r = true
|
||||
category = cc
|
||||
return
|
||||
}
|
||||
|
|
|
@ -57,5 +57,5 @@ func Meta(h *wp.Handle, id string) string {
|
|||
ss.Sprintf(`<li><a href="%s">条目feed</a></li>`, "/feed")
|
||||
ss.Sprintf(`<li><a href="%s">评论feed</a></li>`, "/comments/feed")
|
||||
s := strings.ReplaceAll(metaTemplate, "{$li}", ss.String())
|
||||
return h.ComponentFilterFnHook(widgets.Meta, str.Replace(s, args))
|
||||
return h.DoActionFilter(widgets.Meta, str.Replace(s, args))
|
||||
}
|
||||
|
|
|
@ -64,5 +64,5 @@ func RecentComments(h *wp.Handle, id string) string {
|
|||
</li>`, t.CommentAuthor, t.CommentPostId, t.CommentId, t.PostTitle)
|
||||
})
|
||||
s := strings.ReplaceAll(recentCommentsTemplate, "{$li}", strings.Join(comments, "\n"))
|
||||
return h.ComponentFilterFnHook(widgets.RecentComments, str.Replace(s, args))
|
||||
return h.DoActionFilter(widgets.RecentComments, str.Replace(s, args))
|
||||
}
|
||||
|
|
|
@ -85,5 +85,5 @@ func RecentPosts(h *wp.Handle, id string) string {
|
|||
</li>`, t.Id, ariaCurrent, t.PostTitle, date)
|
||||
})
|
||||
s := strings.ReplaceAll(recentPostsTemplate, "{$li}", strings.Join(posts, "\n"))
|
||||
return h.ComponentFilterFnHook(widgets.RecentPosts, str.Replace(s, args))
|
||||
return h.DoActionFilter(widgets.RecentPosts, str.Replace(s, args))
|
||||
}
|
||||
|
|
|
@ -77,5 +77,5 @@ func Search(h *wp.Handle, id string) string {
|
|||
val = html.SpecialChars(h.Index.Param.Search)
|
||||
}
|
||||
s = strings.ReplaceAll(s, "{$value}", val)
|
||||
return h.ComponentFilterFnHook(widgets.Search, str.Replace(s, args))
|
||||
return h.DoActionFilter(widgets.Search, str.Replace(s, args))
|
||||
}
|
||||
|
|
23
app/theme/wp/components/widget/tag.go
Normal file
23
app/theme/wp/components/widget/tag.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package widget
|
||||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/app/pkg/cache"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
)
|
||||
|
||||
func IsTag(h *wp.Handle) (models.TermsMy, bool) {
|
||||
if h.Scene() == constraints.Tag {
|
||||
id := str.ToInt[uint64](h.C.Query("tag"))
|
||||
i, t := slice.SearchFirst(cache.CategoriesTags(h.C, constraints.Tag), func(my models.TermsMy) bool {
|
||||
return id == my.Terms.TermId
|
||||
})
|
||||
if i > 0 {
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return models.TermsMy{}, false
|
||||
}
|
|
@ -85,7 +85,7 @@ func GetVideoSetting(h *Handle, u string) (string, error) {
|
|||
if is := videoReg.FindString(u); is != "" {
|
||||
v.MimeType = "video/x-youtube"
|
||||
}
|
||||
_ = h.ComponentFilterFnHook("videoSetting", "", &v)
|
||||
_ = h.DoActionFilter("videoSetting", "", &v)
|
||||
s, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
@ -122,7 +122,7 @@ func CustomVideo(h *Handle, scene ...string) (ok bool) {
|
|||
logs.Error(err, "get headerVideo fail", mod.HeaderVideo)
|
||||
return
|
||||
}
|
||||
scripts := []string{
|
||||
scriptss := []string{
|
||||
"/wp-includes/js/dist/vendor/wp-polyfill-inert.min.js",
|
||||
"/wp-includes/js/dist/vendor/regenerator-runtime.min.js",
|
||||
"/wp-includes/js/dist/vendor/wp-polyfill.min.js",
|
||||
|
@ -132,15 +132,10 @@ func CustomVideo(h *Handle, scene ...string) (ok bool) {
|
|||
"/wp-includes/js/dist/a11y.min.js",
|
||||
"/wp-includes/js/wp-custom-header.min.js",
|
||||
}
|
||||
scripts = slice.Map(scripts, func(t string) string {
|
||||
scriptss = slice.Map(scriptss, func(t string) string {
|
||||
return fmt.Sprintf(`<script src="%s" id="wp-%s-js"></script>
|
||||
`, t, str.Replaces(t, [][]string{
|
||||
{"/wp-includes/js/dist/vendor/"},
|
||||
{"/wp-includes/js/dist/"},
|
||||
{"/wp-includes/js/"},
|
||||
{".min.js"},
|
||||
{".js"},
|
||||
{"wp-", ""},
|
||||
`, t, str.Replaces(t, []string{
|
||||
"/wp-includes/js/dist/vendor/", "/wp-includes/js/dist/", "/wp-includes/js/", ".min.js", ".js", "wp-", "",
|
||||
}))
|
||||
})
|
||||
|
||||
|
@ -159,10 +154,10 @@ wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );
|
|||
c := []Components[string]{
|
||||
NewComponent("wp-a11y-js-translations", tr, true, 10.0065, nil),
|
||||
NewComponent("VideoSetting", hs, true, 10.0064, nil),
|
||||
NewComponent("header-script", scripts[len(scripts)-1], true, 10.0063, nil),
|
||||
NewComponent("header-script", scriptss[len(scriptss)-1], true, 10.0063, nil),
|
||||
}
|
||||
for _, s := range scene {
|
||||
h.PushGroupFooterScript(s, "wp-custom-header", 10.0066, scripts[0:len(scripts)-2]...)
|
||||
h.PushGroupFooterScript(s, "wp-custom-header", 10.0066, scriptss[0:len(scriptss)-2]...)
|
||||
h.PushFooterScript(s, c...)
|
||||
}
|
||||
ok = true
|
||||
|
|
106
app/theme/wp/defaultScriptLoad.php
Normal file
106
app/theme/wp/defaultScriptLoad.php
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* wordpress/wp-includes/script-loader.php:632
|
||||
* @var $scripts
|
||||
*/
|
||||
$con = 'package wp
|
||||
import "github.com/fthvgb1/wp-go/safety"
|
||||
|
||||
func defaultScripts(m *safety.Map[string, *Script], suffix string){
|
||||
|
||||
';
|
||||
foreach ($scripts->registered as $handle => $h) {
|
||||
$dep = 'nil';
|
||||
if ($h->deps) {
|
||||
$dep = '[]string{';
|
||||
$dep .= implode(',', array_map(fn($v) => '"' . $v . '"', $h->deps));
|
||||
$dep .= '}';
|
||||
}
|
||||
$con .= sprintf('m.Store("%s", NewScript("%s", "%s"+suffix+".js", %s, "%s", %s))
|
||||
', $handle, $h->handle, str_replace('.min.js', '', $h->src), $dep, $h->ver, $h->args ?: 'nil');
|
||||
}
|
||||
$con .= '}';
|
||||
file_put_contents('/tmp/scriptLoad.go', $con);
|
||||
|
||||
|
||||
/**
|
||||
* put code to wordpress/wp-includes/class-wp-scripts.php:504
|
||||
* @param $handle
|
||||
* @param $object_name
|
||||
* @param $l10n
|
||||
* @return void
|
||||
*/
|
||||
function parseLocalize($handle, $object_name, $l10n): void
|
||||
{
|
||||
if ('utils' != $handle) {
|
||||
$s = array_map('parseArr', array_keys($l10n), array_values($l10n));
|
||||
$m = implode("\n", $s);
|
||||
$x = sprintf('AddStaticLocalize("%s","%s",map[string]any{
|
||||
%s
|
||||
})
|
||||
', $handle, $object_name, $m);
|
||||
file_put_contents('/tmp/bb.go', $x, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
|
||||
function parseArr($k, $v): string
|
||||
{
|
||||
/**
|
||||
* @var $this object
|
||||
*/
|
||||
if (is_array($v)) {
|
||||
if (array_diff_key(array_values($v), $v)) {
|
||||
$x = '';
|
||||
foreach ($v as $kk => $vv) {
|
||||
$x .= parseArr($kk, $vv);
|
||||
}
|
||||
return sprintf('"%s":map[string]any{
|
||||
%s
|
||||
},', $k, $x);
|
||||
} else {
|
||||
$s = array_map(fn($ss) => sprintf('"%s"', $ss), $v);
|
||||
return sprintf('"%s":[]string{%s},', $k, implode(',', $s));
|
||||
}
|
||||
|
||||
} else {
|
||||
return sprintf('"%s":`%s`,', $k, $v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* /var/www/html/wordpress/wp-includes/class-wp-theme-json.php:1712
|
||||
* @return void
|
||||
*/
|
||||
function presetsMetadata()
|
||||
{
|
||||
$ss = <<<go
|
||||
{
|
||||
path: []string{%s},
|
||||
preventOverride: []string{%s},
|
||||
useDefaultNames: %s,
|
||||
valueKey: "%s",
|
||||
valueFunc: %s,
|
||||
cssVars: "%s",
|
||||
classes: map[string]string{
|
||||
%s
|
||||
},
|
||||
properties: []string{%s},
|
||||
},
|
||||
go;
|
||||
$s = '';
|
||||
foreach (static::PRESETS_METADATA as $val) {
|
||||
$arr = [];
|
||||
$arr[] = implode(',', array_map(fn($v) => '"' . $v . '"', $val['path']));
|
||||
$arr[] = (!$val['prevent_override']) ? '' : implode(',', array_map(fn($v) => '"' . $v . '"', $val['prevent_override']));
|
||||
$arr[] = $val['use_default_names'] ? 'true' : 'false';
|
||||
$arr[] = $val['value_key'] ?? '';
|
||||
$arr[] = $val['value_func'] ?? 'nil';
|
||||
$arr[] = $val['css_vars'];
|
||||
$arr[] = implode(",\n", array_map(fn($k, $v) => sprintf('"%s":"%s"', $k, $v), array_keys($val['classes']), array_values($val['classes'])));
|
||||
$arr[] = implode(',', array_map(fn($v) => '"' . $v . '"', $val['properties']));
|
||||
$s .= sprintf($ss, ...$arr);
|
||||
}
|
||||
echo $s;
|
||||
}
|
|
@ -100,7 +100,7 @@ func BuildPipe(pipeScene string, keyFn func(*Handle, string) string, fn func(*Ha
|
|||
|
||||
func PipeKey(h *Handle, pipScene string) string {
|
||||
key := str.Join("pipekey", "-", pipScene, "-", h.scene, "-", h.Stats)
|
||||
return h.ComponentFilterFnHook("pipeKey", key, pipScene)
|
||||
return h.DoActionFilter("pipeKey", key, pipScene)
|
||||
}
|
||||
|
||||
func Run(h *Handle, conf func(*Handle)) {
|
||||
|
@ -133,7 +133,7 @@ func Run(h *Handle, conf func(*Handle)) {
|
|||
}
|
||||
|
||||
func MiddlewareKey(h *Handle, pipScene string) string {
|
||||
return h.ComponentFilterFnHook("middleware", "middleware", pipScene)
|
||||
return h.DoActionFilter("middleware", "middleware", pipScene)
|
||||
}
|
||||
|
||||
func PipeMiddlewareHandle(h *Handle, middlewares map[string][]HandleCall, key string) (handlers []HandleCall) {
|
||||
|
|
739
app/theme/wp/scriptloader/defaultscriptload.go
Normal file
739
app/theme/wp/scriptloader/defaultscriptload.go
Normal file
|
@ -0,0 +1,739 @@
|
|||
package scriptloader
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func defaultScripts(m *safety.Map[string, *Script], suffix string) {
|
||||
m.Store("utils", NewScript("utils", "/wp-includes/js/utils"+suffix+".js", nil, "", nil))
|
||||
m.Store("common", NewScript("common", "/wp-admin/js/common"+suffix+".js", []string{"jquery", "hoverIntent", "utils", "wp-i18n"}, "", 1))
|
||||
m.Store("wp-sanitize", NewScript("wp-sanitize", "/wp-includes/js/wp-sanitize"+suffix+".js", nil, "", 1))
|
||||
m.Store("sack", NewScript("sack", "/wp-includes/js/tw-sack"+suffix+".js", nil, "1.6.1", 1))
|
||||
m.Store("quicktags", NewScript("quicktags", "/wp-includes/js/quicktags"+suffix+".js", nil, "", 1))
|
||||
m.Store("colorpicker", NewScript("colorpicker", "/wp-includes/js/colorpicker"+suffix+".js", []string{"prototype"}, "3517m", nil))
|
||||
m.Store("editor", NewScript("editor", "/wp-admin/js/editor"+suffix+".js", []string{"utils", "jquery"}, "", 1))
|
||||
m.Store("clipboard", NewScript("clipboard", "/wp-includes/js/clipboard"+suffix+".js", nil, "2.0.11", 1))
|
||||
m.Store("wp-ajax-response", NewScript("wp-ajax-response", "/wp-includes/js/wp-ajax-response"+suffix+".js", []string{"jquery", "wp-a11y"}, "", 1))
|
||||
m.Store("wp-api-request", NewScript("wp-api-request", "/wp-includes/js/api-request"+suffix+".js", []string{"jquery"}, "", 1))
|
||||
m.Store("wp-pointer", NewScript("wp-pointer", "/wp-includes/js/wp-pointer"+suffix+".js", []string{"jquery-ui-core", "wp-i18n"}, "", 1))
|
||||
m.Store("autosave", NewScript("autosave", "/wp-includes/js/autosave"+suffix+".js", []string{"heartbeat"}, "", 1))
|
||||
m.Store("heartbeat", NewScript("heartbeat", "/wp-includes/js/heartbeat"+suffix+".js", []string{"jquery", "wp-hooks"}, "", 1))
|
||||
m.Store("wp-auth-check", NewScript("wp-auth-check", "/wp-includes/js/wp-auth-check"+suffix+".js", []string{"heartbeat", "wp-i18n"}, "", 1))
|
||||
m.Store("wp-lists", NewScript("wp-lists", "/wp-includes/js/wp-lists"+suffix+".js", []string{"wp-ajax-response", "jquery-color"}, "", 1))
|
||||
m.Store("prototype", NewScript("prototype", "https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"+suffix+".js", nil, "1.7.1", nil))
|
||||
m.Store("scriptaculous-root", NewScript("scriptaculous-root", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js"+suffix+".js", []string{"prototype"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-builder", NewScript("scriptaculous-builder", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js"+suffix+".js", []string{"scriptaculous-root"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-dragdrop", NewScript("scriptaculous-dragdrop", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js"+suffix+".js", []string{"scriptaculous-builder", "scriptaculous-effects"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-effects", NewScript("scriptaculous-effects", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js"+suffix+".js", []string{"scriptaculous-root"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-slider", NewScript("scriptaculous-slider", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js"+suffix+".js", []string{"scriptaculous-effects"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-sound", NewScript("scriptaculous-sound", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js"+suffix+".js", []string{"scriptaculous-root"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous-controls", NewScript("scriptaculous-controls", "https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js"+suffix+".js", []string{"scriptaculous-root"}, "1.9.0", nil))
|
||||
m.Store("scriptaculous", NewScript("scriptaculous", ""+suffix+".js", []string{"scriptaculous-dragdrop", "scriptaculous-slider", "scriptaculous-controls"}, "", nil))
|
||||
m.Store("cropper", NewScript("cropper", "/wp-includes/js/crop/cropper.js"+suffix+".js", []string{"scriptaculous-dragdrop"}, "", nil))
|
||||
m.Store("jquery", NewScript("jquery", ""+suffix+".js", []string{"jquery-core", "jquery-migrate"}, "3.6.4", nil))
|
||||
m.Store("jquery-core", NewScript("jquery-core", "/wp-includes/js/jquery/jquery"+suffix+".js", nil, "3.6.4", nil))
|
||||
m.Store("jquery-migrate", NewScript("jquery-migrate", "/wp-includes/js/jquery/jquery-migrate"+suffix+".js", nil, "3.4.0", nil))
|
||||
m.Store("jquery-ui-core", NewScript("jquery-ui-core", "/wp-includes/js/jquery/ui/core"+suffix+".js", []string{"jquery"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-core", NewScript("jquery-effects-core", "/wp-includes/js/jquery/ui/effect"+suffix+".js", []string{"jquery"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-blind", NewScript("jquery-effects-blind", "/wp-includes/js/jquery/ui/effect-blind"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-bounce", NewScript("jquery-effects-bounce", "/wp-includes/js/jquery/ui/effect-bounce"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-clip", NewScript("jquery-effects-clip", "/wp-includes/js/jquery/ui/effect-clip"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-drop", NewScript("jquery-effects-drop", "/wp-includes/js/jquery/ui/effect-drop"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-explode", NewScript("jquery-effects-explode", "/wp-includes/js/jquery/ui/effect-explode"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-fade", NewScript("jquery-effects-fade", "/wp-includes/js/jquery/ui/effect-fade"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-fold", NewScript("jquery-effects-fold", "/wp-includes/js/jquery/ui/effect-fold"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-highlight", NewScript("jquery-effects-highlight", "/wp-includes/js/jquery/ui/effect-highlight"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-puff", NewScript("jquery-effects-puff", "/wp-includes/js/jquery/ui/effect-puff"+suffix+".js", []string{"jquery-effects-core", "jquery-effects-scale"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-pulsate", NewScript("jquery-effects-pulsate", "/wp-includes/js/jquery/ui/effect-pulsate"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-scale", NewScript("jquery-effects-scale", "/wp-includes/js/jquery/ui/effect-scale"+suffix+".js", []string{"jquery-effects-core", "jquery-effects-size"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-shake", NewScript("jquery-effects-shake", "/wp-includes/js/jquery/ui/effect-shake"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-size", NewScript("jquery-effects-size", "/wp-includes/js/jquery/ui/effect-size"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-slide", NewScript("jquery-effects-slide", "/wp-includes/js/jquery/ui/effect-slide"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-effects-transfer", NewScript("jquery-effects-transfer", "/wp-includes/js/jquery/ui/effect-transfer"+suffix+".js", []string{"jquery-effects-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-accordion", NewScript("jquery-ui-accordion", "/wp-includes/js/jquery/ui/accordion"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-autocomplete", NewScript("jquery-ui-autocomplete", "/wp-includes/js/jquery/ui/autocomplete"+suffix+".js", []string{"jquery-ui-menu", "wp-a11y"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-button", NewScript("jquery-ui-button", "/wp-includes/js/jquery/ui/button"+suffix+".js", []string{"jquery-ui-core", "jquery-ui-controlgroup", "jquery-ui-checkboxradio"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-datepicker", NewScript("jquery-ui-datepicker", "/wp-includes/js/jquery/ui/datepicker"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-dialog", NewScript("jquery-ui-dialog", "/wp-includes/js/jquery/ui/dialog"+suffix+".js", []string{"jquery-ui-resizable", "jquery-ui-draggable", "jquery-ui-button"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-menu", NewScript("jquery-ui-menu", "/wp-includes/js/jquery/ui/menu"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-mouse", NewScript("jquery-ui-mouse", "/wp-includes/js/jquery/ui/mouse"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-progressbar", NewScript("jquery-ui-progressbar", "/wp-includes/js/jquery/ui/progressbar"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-selectmenu", NewScript("jquery-ui-selectmenu", "/wp-includes/js/jquery/ui/selectmenu"+suffix+".js", []string{"jquery-ui-menu"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-slider", NewScript("jquery-ui-slider", "/wp-includes/js/jquery/ui/slider"+suffix+".js", []string{"jquery-ui-mouse"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-spinner", NewScript("jquery-ui-spinner", "/wp-includes/js/jquery/ui/spinner"+suffix+".js", []string{"jquery-ui-button"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-tabs", NewScript("jquery-ui-tabs", "/wp-includes/js/jquery/ui/tabs"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-tooltip", NewScript("jquery-ui-tooltip", "/wp-includes/js/jquery/ui/tooltip"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-checkboxradio", NewScript("jquery-ui-checkboxradio", "/wp-includes/js/jquery/ui/checkboxradio"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-controlgroup", NewScript("jquery-ui-controlgroup", "/wp-includes/js/jquery/ui/controlgroup"+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-draggable", NewScript("jquery-ui-draggable", "/wp-includes/js/jquery/ui/draggable"+suffix+".js", []string{"jquery-ui-mouse"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-droppable", NewScript("jquery-ui-droppable", "/wp-includes/js/jquery/ui/droppable"+suffix+".js", []string{"jquery-ui-draggable"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-resizable", NewScript("jquery-ui-resizable", "/wp-includes/js/jquery/ui/resizable"+suffix+".js", []string{"jquery-ui-mouse"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-selectable", NewScript("jquery-ui-selectable", "/wp-includes/js/jquery/ui/selectable"+suffix+".js", []string{"jquery-ui-mouse"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-sortable", NewScript("jquery-ui-sortable", "/wp-includes/js/jquery/ui/sortable"+suffix+".js", []string{"jquery-ui-mouse"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-position", NewScript("jquery-ui-position", ""+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-ui-widget", NewScript("jquery-ui-widget", ""+suffix+".js", []string{"jquery-ui-core"}, "1.13.2", 1))
|
||||
m.Store("jquery-form", NewScript("jquery-form", "/wp-includes/js/jquery/jquery.form"+suffix+".js", []string{"jquery"}, "4.3.0", 1))
|
||||
m.Store("jquery-color", NewScript("jquery-color", "/wp-includes/js/jquery/jquery.color"+suffix+".js", []string{"jquery"}, "2.2.0", 1))
|
||||
m.Store("schedule", NewScript("schedule", "/wp-includes/js/jquery/jquery.schedule.js"+suffix+".js", []string{"jquery"}, "20m", 1))
|
||||
m.Store("jquery-query", NewScript("jquery-query", "/wp-includes/js/jquery/jquery.query.js"+suffix+".js", []string{"jquery"}, "2.2.3", 1))
|
||||
m.Store("jquery-serialize-object", NewScript("jquery-serialize-object", "/wp-includes/js/jquery/jquery.serialize-object.js"+suffix+".js", []string{"jquery"}, "0.2-wp", 1))
|
||||
m.Store("jquery-hotkeys", NewScript("jquery-hotkeys", "/wp-includes/js/jquery/jquery.hotkeys"+suffix+".js", []string{"jquery"}, "0.0.2m", 1))
|
||||
m.Store("jquery-table-hotkeys", NewScript("jquery-table-hotkeys", "/wp-includes/js/jquery/jquery.table-hotkeys"+suffix+".js", []string{"jquery", "jquery-hotkeys"}, "", 1))
|
||||
m.Store("jquery-touch-punch", NewScript("jquery-touch-punch", "/wp-includes/js/jquery/jquery.ui.touch-punch.js"+suffix+".js", []string{"jquery-ui-core", "jquery-ui-mouse"}, "0.2.2", 1))
|
||||
m.Store("suggest", NewScript("suggest", "/wp-includes/js/jquery/suggest"+suffix+".js", []string{"jquery"}, "1.1-20110113", 1))
|
||||
m.Store("imagesloaded", NewScript("imagesloaded", "/wp-includes/js/imagesloaded"+suffix+".js", nil, "4.1.4", 1))
|
||||
m.Store("masonry", NewScript("masonry", "/wp-includes/js/masonry"+suffix+".js", []string{"imagesloaded"}, "4.2.2", 1))
|
||||
m.Store("jquery-masonry", NewScript("jquery-masonry", "/wp-includes/js/jquery/jquery.masonry"+suffix+".js", []string{"jquery", "masonry"}, "3.1.2b", 1))
|
||||
m.Store("thickbox", NewScript("thickbox", "/wp-includes/js/thickbox/thickbox.js"+suffix+".js", []string{"jquery"}, "3.1-20121105", 1))
|
||||
m.Store("jcrop", NewScript("jcrop", "/wp-includes/js/jcrop/jquery.Jcrop"+suffix+".js", []string{"jquery"}, "0.9.15", nil))
|
||||
m.Store("swfobject", NewScript("swfobject", "/wp-includes/js/swfobject.js"+suffix+".js", nil, "2.2-20120417", nil))
|
||||
m.Store("moxiejs", NewScript("moxiejs", "/wp-includes/js/plupload/moxie"+suffix+".js", nil, "1.3.5", nil))
|
||||
m.Store("plupload", NewScript("plupload", "/wp-includes/js/plupload/plupload"+suffix+".js", []string{"moxiejs"}, "2.1.9", nil))
|
||||
m.Store("plupload-all", NewScript("plupload-all", ""+suffix+".js", []string{"plupload"}, "2.1.1", nil))
|
||||
m.Store("plupload-html5", NewScript("plupload-html5", ""+suffix+".js", []string{"plupload"}, "2.1.1", nil))
|
||||
m.Store("plupload-flash", NewScript("plupload-flash", ""+suffix+".js", []string{"plupload"}, "2.1.1", nil))
|
||||
m.Store("plupload-silverlight", NewScript("plupload-silverlight", ""+suffix+".js", []string{"plupload"}, "2.1.1", nil))
|
||||
m.Store("plupload-html4", NewScript("plupload-html4", ""+suffix+".js", []string{"plupload"}, "2.1.1", nil))
|
||||
m.Store("plupload-handlers", NewScript("plupload-handlers", "/wp-includes/js/plupload/handlers"+suffix+".js", []string{"clipboard", "jquery", "plupload", "underscore", "wp-a11y", "wp-i18n"}, "", nil))
|
||||
m.Store("wp-plupload", NewScript("wp-plupload", "/wp-includes/js/plupload/wp-plupload"+suffix+".js", []string{"plupload", "jquery", "json2", "media-models"}, "", 1))
|
||||
m.Store("swfupload", NewScript("swfupload", "/wp-includes/js/swfupload/swfupload.js"+suffix+".js", nil, "2201-20110113", nil))
|
||||
m.Store("swfupload-all", NewScript("swfupload-all", ""+suffix+".js", []string{"swfupload"}, "2201", nil))
|
||||
m.Store("swfupload-handlers", NewScript("swfupload-handlers", "/wp-includes/js/swfupload/handlers"+suffix+".js", []string{"swfupload-all", "jquery"}, "2201-20110524", nil))
|
||||
m.Store("comment-reply", NewScript("comment-reply", "/wp-includes/js/comment-reply"+suffix+".js", nil, "", 1))
|
||||
m.Store("json2", NewScript("json2", "/wp-includes/js/json2"+suffix+".js", nil, "2015-05-03", nil))
|
||||
m.Store("underscore", NewScript("underscore", "/wp-includes/js/underscore"+suffix+".js", nil, "1.13.4", 1))
|
||||
m.Store("backbone", NewScript("backbone", "/wp-includes/js/backbone"+suffix+".js", []string{"underscore", "jquery"}, "1.4.1", 1))
|
||||
m.Store("wp-util", NewScript("wp-util", "/wp-includes/js/wp-util"+suffix+".js", []string{"underscore", "jquery"}, "", 1))
|
||||
m.Store("wp-backbone", NewScript("wp-backbone", "/wp-includes/js/wp-backbone"+suffix+".js", []string{"backbone", "wp-util"}, "", 1))
|
||||
m.Store("revisions", NewScript("revisions", "/wp-admin/js/revisions"+suffix+".js", []string{"wp-backbone", "jquery-ui-slider", "hoverIntent"}, "", 1))
|
||||
m.Store("imgareaselect", NewScript("imgareaselect", "/wp-includes/js/imgareaselect/jquery.imgareaselect"+suffix+".js", []string{"jquery"}, "", 1))
|
||||
m.Store("mediaelement", NewScript("mediaelement", ""+suffix+".js", []string{"jquery", "mediaelement-core", "mediaelement-migrate"}, "4.2.17", 1))
|
||||
m.Store("mediaelement-core", NewScript("mediaelement-core", "/wp-includes/js/mediaelement/mediaelement-and-player"+suffix+".js", nil, "4.2.17", 1))
|
||||
m.Store("mediaelement-migrate", NewScript("mediaelement-migrate", "/wp-includes/js/mediaelement/mediaelement-migrate"+suffix+".js", nil, "", 1))
|
||||
m.Store("mediaelement-vimeo", NewScript("mediaelement-vimeo", "/wp-includes/js/mediaelement/renderers/vimeo"+suffix+".js", []string{"mediaelement"}, "4.2.17", 1))
|
||||
m.Store("wp-mediaelement", NewScript("wp-mediaelement", "/wp-includes/js/mediaelement/wp-mediaelement"+suffix+".js", []string{"mediaelement"}, "", 1))
|
||||
m.Store("wp-codemirror", NewScript("wp-codemirror", "/wp-includes/js/codemirror/codemirror"+suffix+".js", nil, "5.29.1-alpha-ee20357", nil))
|
||||
m.Store("csslint", NewScript("csslint", "/wp-includes/js/codemirror/csslint.js"+suffix+".js", nil, "1.0.5", nil))
|
||||
m.Store("esprima", NewScript("esprima", "/wp-includes/js/codemirror/esprima.js"+suffix+".js", nil, "4.0.0", nil))
|
||||
m.Store("jshint", NewScript("jshint", "/wp-includes/js/codemirror/fakejshint.js"+suffix+".js", []string{"esprima"}, "2.9.5", nil))
|
||||
m.Store("jsonlint", NewScript("jsonlint", "/wp-includes/js/codemirror/jsonlint.js"+suffix+".js", nil, "1.6.2", nil))
|
||||
m.Store("htmlhint", NewScript("htmlhint", "/wp-includes/js/codemirror/htmlhint.js"+suffix+".js", nil, "0.9.14-xwp", nil))
|
||||
m.Store("htmlhint-kses", NewScript("htmlhint-kses", "/wp-includes/js/codemirror/htmlhint-kses.js"+suffix+".js", []string{"htmlhint"}, "", nil))
|
||||
m.Store("code-editor", NewScript("code-editor", "/wp-admin/js/code-editor"+suffix+".js", []string{"jquery", "wp-codemirror", "underscore"}, "", nil))
|
||||
m.Store("wp-theme-plugin-editor", NewScript("wp-theme-plugin-editor", "/wp-admin/js/theme-plugin-editor"+suffix+".js", []string{"common", "wp-util", "wp-sanitize", "jquery", "jquery-ui-core", "wp-a11y", "underscore", "wp-i18n"}, "", 1))
|
||||
m.Store("wp-playlist", NewScript("wp-playlist", "/wp-includes/js/mediaelement/wp-playlist"+suffix+".js", []string{"wp-util", "backbone", "mediaelement"}, "", 1))
|
||||
m.Store("zxcvbn-async", NewScript("zxcvbn-async", "/wp-includes/js/zxcvbn-async"+suffix+".js", nil, "1.0", nil))
|
||||
m.Store("password-strength-meter", NewScript("password-strength-meter", "/wp-admin/js/password-strength-meter"+suffix+".js", []string{"jquery", "zxcvbn-async", "wp-i18n"}, "", 1))
|
||||
m.Store("application-passwords", NewScript("application-passwords", "/wp-admin/js/application-passwords"+suffix+".js", []string{"jquery", "wp-util", "wp-api-request", "wp-date", "wp-i18n", "wp-hooks"}, "", 1))
|
||||
m.Store("auth-app", NewScript("auth-app", "/wp-admin/js/auth-app"+suffix+".js", []string{"jquery", "wp-api-request", "wp-i18n", "wp-hooks"}, "", 1))
|
||||
m.Store("user-profile", NewScript("user-profile", "/wp-admin/js/user-profile"+suffix+".js", []string{"jquery", "password-strength-meter", "wp-util", "wp-i18n"}, "", 1))
|
||||
m.Store("language-chooser", NewScript("language-chooser", "/wp-admin/js/language-chooser"+suffix+".js", []string{"jquery"}, "", 1))
|
||||
m.Store("user-suggest", NewScript("user-suggest", "/wp-admin/js/user-suggest"+suffix+".js", []string{"jquery-ui-autocomplete"}, "", 1))
|
||||
m.Store("admin-bar", NewScript("admin-bar", "/wp-includes/js/admin-bar"+suffix+".js", []string{"hoverintent-js"}, "", 1))
|
||||
m.Store("wplink", NewScript("wplink", "/wp-includes/js/wplink"+suffix+".js", []string{"jquery", "wp-a11y"}, "", 1))
|
||||
m.Store("wpdialogs", NewScript("wpdialogs", "/wp-includes/js/wpdialog"+suffix+".js", []string{"jquery-ui-dialog"}, "", 1))
|
||||
m.Store("word-count", NewScript("word-count", "/wp-admin/js/word-count"+suffix+".js", nil, "", 1))
|
||||
m.Store("media-upload", NewScript("media-upload", "/wp-admin/js/media-upload"+suffix+".js", []string{"thickbox", "shortcode"}, "", 1))
|
||||
m.Store("hoverIntent", NewScript("hoverIntent", "/wp-includes/js/hoverIntent"+suffix+".js", []string{"jquery"}, "1.10.2", 1))
|
||||
m.Store("hoverintent-js", NewScript("hoverintent-js", "/wp-includes/js/hoverintent-js"+suffix+".js", nil, "2.2.1", 1))
|
||||
m.Store("customize-base", NewScript("customize-base", "/wp-includes/js/customize-base"+suffix+".js", []string{"jquery", "json2", "underscore"}, "", 1))
|
||||
m.Store("customize-loader", NewScript("customize-loader", "/wp-includes/js/customize-loader"+suffix+".js", []string{"customize-base"}, "", 1))
|
||||
m.Store("customize-preview", NewScript("customize-preview", "/wp-includes/js/customize-preview"+suffix+".js", []string{"wp-a11y", "customize-base"}, "", 1))
|
||||
m.Store("customize-models", NewScript("customize-models", "/wp-includes/js/customize-models.js"+suffix+".js", []string{"underscore", "backbone"}, "", 1))
|
||||
m.Store("customize-views", NewScript("customize-views", "/wp-includes/js/customize-views.js"+suffix+".js", []string{"jquery", "underscore", "imgareaselect", "customize-models", "media-editor", "media-views"}, "", 1))
|
||||
m.Store("customize-controls", NewScript("customize-controls", "/wp-admin/js/customize-controls"+suffix+".js", []string{"customize-base", "wp-a11y", "wp-util", "jquery-ui-core"}, "", 1))
|
||||
m.Store("customize-selective-refresh", NewScript("customize-selective-refresh", "/wp-includes/js/customize-selective-refresh"+suffix+".js", []string{"jquery", "wp-util", "customize-preview"}, "", 1))
|
||||
m.Store("customize-widgets", NewScript("customize-widgets", "/wp-admin/js/customize-widgets"+suffix+".js", []string{"jquery", "jquery-ui-sortable", "jquery-ui-droppable", "wp-backbone", "customize-controls"}, "", 1))
|
||||
m.Store("customize-preview-widgets", NewScript("customize-preview-widgets", "/wp-includes/js/customize-preview-widgets"+suffix+".js", []string{"jquery", "wp-util", "customize-preview", "customize-selective-refresh"}, "", 1))
|
||||
m.Store("customize-nav-menus", NewScript("customize-nav-menus", "/wp-admin/js/customize-nav-menus"+suffix+".js", []string{"jquery", "wp-backbone", "customize-controls", "accordion", "nav-menu", "wp-sanitize"}, "", 1))
|
||||
m.Store("customize-preview-nav-menus", NewScript("customize-preview-nav-menus", "/wp-includes/js/customize-preview-nav-menus"+suffix+".js", []string{"jquery", "wp-util", "customize-preview", "customize-selective-refresh"}, "", 1))
|
||||
m.Store("wp-custom-header", NewScript("wp-custom-header", "/wp-includes/js/wp-custom-header"+suffix+".js", []string{"wp-a11y"}, "", 1))
|
||||
m.Store("accordion", NewScript("accordion", "/wp-admin/js/accordion"+suffix+".js", []string{"jquery"}, "", 1))
|
||||
m.Store("shortcode", NewScript("shortcode", "/wp-includes/js/shortcode"+suffix+".js", []string{"underscore"}, "", 1))
|
||||
m.Store("media-models", NewScript("media-models", "/wp-includes/js/media-models"+suffix+".js", []string{"wp-backbone"}, "", 1))
|
||||
m.Store("wp-embed", NewScript("wp-embed", "/wp-includes/js/wp-embed"+suffix+".js", nil, "", 1))
|
||||
m.Store("media-views", NewScript("media-views", "/wp-includes/js/media-views"+suffix+".js", []string{"utils", "media-models", "wp-plupload", "jquery-ui-sortable", "wp-mediaelement", "wp-api-request", "wp-a11y", "clipboard", "wp-i18n"}, "", 1))
|
||||
m.Store("media-editor", NewScript("media-editor", "/wp-includes/js/media-editor"+suffix+".js", []string{"shortcode", "media-views", "wp-i18n"}, "", 1))
|
||||
m.Store("media-audiovideo", NewScript("media-audiovideo", "/wp-includes/js/media-audiovideo"+suffix+".js", []string{"media-editor"}, "", 1))
|
||||
m.Store("mce-view", NewScript("mce-view", "/wp-includes/js/mce-view"+suffix+".js", []string{"shortcode", "jquery", "media-views", "media-audiovideo"}, "", 1))
|
||||
m.Store("wp-api", NewScript("wp-api", "/wp-includes/js/wp-api"+suffix+".js", []string{"jquery", "backbone", "underscore", "wp-api-request"}, "", 1))
|
||||
m.Store("react", NewScript("react", "/wp-includes/js/dist/vendor/react"+suffix+".js", []string{"wp-polyfill"}, "18.2.0", 1))
|
||||
m.Store("react-dom", NewScript("react-dom", "/wp-includes/js/dist/vendor/react-dom"+suffix+".js", []string{"react"}, "18.2.0", 1))
|
||||
m.Store("regenerator-runtime", NewScript("regenerator-runtime", "/wp-includes/js/dist/vendor/regenerator-runtime"+suffix+".js", nil, "0.13.11", 1))
|
||||
m.Store("moment", NewScript("moment", "/wp-includes/js/dist/vendor/moment"+suffix+".js", nil, "2.29.4", 1))
|
||||
m.Store("lodash", NewScript("lodash", "/wp-includes/js/dist/vendor/lodash"+suffix+".js", nil, "4.17.19", 1))
|
||||
m.Store("wp-polyfill-fetch", NewScript("wp-polyfill-fetch", "/wp-includes/js/dist/vendor/wp-polyfill-fetch"+suffix+".js", nil, "3.6.2", 1))
|
||||
m.Store("wp-polyfill-formdata", NewScript("wp-polyfill-formdata", "/wp-includes/js/dist/vendor/wp-polyfill-formdata"+suffix+".js", nil, "4.0.10", 1))
|
||||
m.Store("wp-polyfill-node-contains", NewScript("wp-polyfill-node-contains", "/wp-includes/js/dist/vendor/wp-polyfill-node-contains"+suffix+".js", nil, "4.6.0", 1))
|
||||
m.Store("wp-polyfill-url", NewScript("wp-polyfill-url", "/wp-includes/js/dist/vendor/wp-polyfill-url"+suffix+".js", nil, "3.6.4", 1))
|
||||
m.Store("wp-polyfill-dom-rect", NewScript("wp-polyfill-dom-rect", "/wp-includes/js/dist/vendor/wp-polyfill-dom-rect"+suffix+".js", nil, "4.6.0", 1))
|
||||
m.Store("wp-polyfill-element-closest", NewScript("wp-polyfill-element-closest", "/wp-includes/js/dist/vendor/wp-polyfill-element-closest"+suffix+".js", nil, "3.0.2", 1))
|
||||
m.Store("wp-polyfill-object-fit", NewScript("wp-polyfill-object-fit", "/wp-includes/js/dist/vendor/wp-polyfill-object-fit"+suffix+".js", nil, "2.3.5", 1))
|
||||
m.Store("wp-polyfill-inert", NewScript("wp-polyfill-inert", "/wp-includes/js/dist/vendor/wp-polyfill-inert"+suffix+".js", nil, "3.1.2", 1))
|
||||
m.Store("wp-polyfill", NewScript("wp-polyfill", "/wp-includes/js/dist/vendor/wp-polyfill"+suffix+".js", []string{"wp-polyfill-inert", "regenerator-runtime"}, "3.15.0", 1))
|
||||
m.Store("wp-tinymce-root", NewScript("wp-tinymce-root", "http://wp.test/wp-includes/js/tinymce/tinymce"+suffix+".js", nil, "49110-20201110", nil))
|
||||
m.Store("wp-tinymce", NewScript("wp-tinymce", "http://wp.test/wp-includes/js/tinymce/plugins/compat3x/plugin"+suffix+".js", []string{"wp-tinymce-root"}, "49110-20201110", nil))
|
||||
m.Store("wp-tinymce-lists", NewScript("wp-tinymce-lists", "http://wp.test/wp-includes/js/tinymce/plugins/lists/plugin"+suffix+".js", []string{"wp-tinymce"}, "49110-20201110", nil))
|
||||
m.Store("wp-a11y", NewScript("wp-a11y", "/wp-includes/js/dist/a11y"+suffix+".js", []string{"wp-dom-ready", "wp-i18n", "wp-polyfill"}, "ecce20f002eda4c19664", 1))
|
||||
m.Store("wp-annotations", NewScript("wp-annotations", "/wp-includes/js/dist/annotations"+suffix+".js", []string{"wp-data", "wp-hooks", "wp-i18n", "wp-polyfill", "wp-rich-text"}, "1720fc5d5c76f53a1740", 1))
|
||||
m.Store("wp-api-fetch", NewScript("wp-api-fetch", "/wp-includes/js/dist/api-fetch"+suffix+".js", []string{"wp-i18n", "wp-polyfill", "wp-url"}, "bc0029ca2c943aec5311", 1))
|
||||
m.Store("wp-autop", NewScript("wp-autop", "/wp-includes/js/dist/autop"+suffix+".js", []string{"wp-polyfill"}, "43197d709df445ccf849", 1))
|
||||
m.Store("wp-blob", NewScript("wp-blob", "/wp-includes/js/dist/blob"+suffix+".js", []string{"wp-polyfill"}, "e7b4ea96175a89b263e2", 1))
|
||||
m.Store("wp-block-directory", NewScript("wp-block-directory", "/wp-includes/js/dist/block-directory"+suffix+".js", []string{"wp-a11y", "wp-api-fetch", "wp-block-editor", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-editor", "wp-element", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-notices", "wp-plugins", "wp-polyfill", "wp-primitives", "wp-url"}, "9c45b8d28fc867ceed45", 1))
|
||||
m.Store("wp-block-editor", NewScript("wp-block-editor", "/wp-includes/js/dist/block-editor"+suffix+".js", []string{"lodash", "react", "react-dom", "wp-a11y", "wp-api-fetch", "wp-blob", "wp-blocks", "wp-components", "wp-compose", "wp-data", "wp-date", "wp-deprecated", "wp-dom", "wp-element", "wp-escape-html", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-is-shallow-equal", "wp-keyboard-shortcuts", "wp-keycodes", "wp-notices", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-rich-text", "wp-shortcode", "wp-style-engine", "wp-token-list", "wp-url", "wp-warning", "wp-wordcount"}, "43e40e04f77d598ede94", 1))
|
||||
m.Store("wp-block-library", NewScript("wp-block-library", "/wp-includes/js/dist/block-library"+suffix+".js", []string{"lodash", "wp-a11y", "wp-api-fetch", "wp-autop", "wp-blob", "wp-block-editor", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-date", "wp-deprecated", "wp-dom", "wp-element", "wp-escape-html", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-keycodes", "wp-notices", "wp-polyfill", "wp-primitives", "wp-private-apis", "wp-reusable-blocks", "wp-rich-text", "wp-server-side-render", "wp-url", "wp-viewport", "editor"}, "3115f0b5551a55bb6d3b", 1))
|
||||
m.Store("wp-block-serialization-default-parser", NewScript("wp-block-serialization-default-parser", "/wp-includes/js/dist/block-serialization-default-parser"+suffix+".js", []string{"wp-polyfill"}, "30ffd7e7e199f10b2a6d", 1))
|
||||
m.Store("wp-blocks", NewScript("wp-blocks", "/wp-includes/js/dist/blocks"+suffix+".js", []string{"lodash", "wp-autop", "wp-blob", "wp-block-serialization-default-parser", "wp-compose", "wp-data", "wp-deprecated", "wp-dom", "wp-element", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-is-shallow-equal", "wp-polyfill", "wp-shortcode"}, "639e14271099dc3d85bf", 1))
|
||||
m.Store("wp-components", NewScript("wp-components", "/wp-includes/js/dist/components"+suffix+".js", []string{"lodash", "react", "react-dom", "wp-a11y", "wp-compose", "wp-date", "wp-deprecated", "wp-dom", "wp-element", "wp-escape-html", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-is-shallow-equal", "wp-keycodes", "wp-polyfill", "wp-primitives", "wp-private-apis", "wp-rich-text", "wp-warning"}, "bf6e0ec3089253604b52", 1))
|
||||
m.Store("wp-compose", NewScript("wp-compose", "/wp-includes/js/dist/compose"+suffix+".js", []string{"react", "wp-deprecated", "wp-dom", "wp-element", "wp-is-shallow-equal", "wp-keycodes", "wp-polyfill", "wp-priority-queue"}, "7d5916e3b2ef0ea01400", 1))
|
||||
m.Store("wp-core-data", NewScript("wp-core-data", "/wp-includes/js/dist/core-data"+suffix+".js", []string{"lodash", "wp-api-fetch", "wp-blocks", "wp-compose", "wp-data", "wp-deprecated", "wp-element", "wp-html-entities", "wp-i18n", "wp-is-shallow-equal", "wp-polyfill", "wp-url"}, "fc0de6bb17aa25caf698", 1))
|
||||
m.Store("wp-customize-widgets", NewScript("wp-customize-widgets", "/wp-includes/js/dist/customize-widgets"+suffix+".js", []string{"wp-block-editor", "wp-block-library", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-deprecated", "wp-dom", "wp-element", "wp-hooks", "wp-i18n", "wp-is-shallow-equal", "wp-keyboard-shortcuts", "wp-keycodes", "wp-media-utils", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-widgets"}, "7ae69cc350436c0cf301", 1))
|
||||
m.Store("wp-data", NewScript("wp-data", "/wp-includes/js/dist/data"+suffix+".js", []string{"lodash", "wp-compose", "wp-deprecated", "wp-element", "wp-is-shallow-equal", "wp-polyfill", "wp-priority-queue", "wp-private-apis", "wp-redux-routine"}, "90cebfec01d1a3f0368e", 1))
|
||||
m.Store("wp-data-controls", NewScript("wp-data-controls", "/wp-includes/js/dist/data-controls"+suffix+".js", []string{"wp-api-fetch", "wp-data", "wp-deprecated", "wp-polyfill"}, "e10d473d392daa8501e8", 1))
|
||||
m.Store("wp-date", NewScript("wp-date", "/wp-includes/js/dist/date"+suffix+".js", []string{"moment", "wp-deprecated", "wp-polyfill"}, "f8550b1212d715fbf745", 1))
|
||||
m.Store("wp-deprecated", NewScript("wp-deprecated", "/wp-includes/js/dist/deprecated"+suffix+".js", []string{"wp-hooks", "wp-polyfill"}, "6c963cb9494ba26b77eb", 1))
|
||||
m.Store("wp-dom", NewScript("wp-dom", "/wp-includes/js/dist/dom"+suffix+".js", []string{"wp-deprecated", "wp-polyfill"}, "e03c89e1dd68aee1cb3a", 1))
|
||||
m.Store("wp-dom-ready", NewScript("wp-dom-ready", "/wp-includes/js/dist/dom-ready"+suffix+".js", []string{"wp-polyfill"}, "392bdd43726760d1f3ca", 1))
|
||||
m.Store("wp-edit-post", NewScript("wp-edit-post", "/wp-includes/js/dist/edit-post"+suffix+".js", []string{"lodash", "wp-a11y", "wp-api-fetch", "wp-block-editor", "wp-block-library", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-deprecated", "wp-editor", "wp-element", "wp-hooks", "wp-i18n", "wp-keyboard-shortcuts", "wp-keycodes", "wp-media-utils", "wp-notices", "wp-plugins", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-url", "wp-viewport", "wp-warning", "wp-widgets", "media-models", "media-views", "postbox", "wp-dom-ready"}, "d098b8ee5bdffa238c03", 1))
|
||||
m.Store("wp-edit-site", NewScript("wp-edit-site", "/wp-includes/js/dist/edit-site"+suffix+".js", []string{"lodash", "react", "wp-a11y", "wp-api-fetch", "wp-block-editor", "wp-block-library", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-deprecated", "wp-editor", "wp-element", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-keyboard-shortcuts", "wp-keycodes", "wp-media-utils", "wp-notices", "wp-plugins", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-reusable-blocks", "wp-url", "wp-viewport", "wp-widgets"}, "fcf81e803ab1af60d4f8", 1))
|
||||
m.Store("wp-edit-widgets", NewScript("wp-edit-widgets", "/wp-includes/js/dist/edit-widgets"+suffix+".js", []string{"wp-api-fetch", "wp-block-editor", "wp-block-library", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-deprecated", "wp-dom", "wp-element", "wp-hooks", "wp-i18n", "wp-keyboard-shortcuts", "wp-keycodes", "wp-media-utils", "wp-notices", "wp-plugins", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-reusable-blocks", "wp-url", "wp-viewport", "wp-widgets"}, "d683d5fc75e655fdf974", 1))
|
||||
m.Store("wp-editor", NewScript("wp-editor", "/wp-includes/js/dist/editor"+suffix+".js", []string{"lodash", "react", "wp-a11y", "wp-api-fetch", "wp-blob", "wp-block-editor", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-date", "wp-deprecated", "wp-dom", "wp-element", "wp-hooks", "wp-html-entities", "wp-i18n", "wp-keyboard-shortcuts", "wp-keycodes", "wp-media-utils", "wp-notices", "wp-polyfill", "wp-preferences", "wp-primitives", "wp-private-apis", "wp-reusable-blocks", "wp-rich-text", "wp-server-side-render", "wp-url", "wp-wordcount"}, "1fb5fcf129627da4939e", 1))
|
||||
m.Store("wp-element", NewScript("wp-element", "/wp-includes/js/dist/element"+suffix+".js", []string{"react", "react-dom", "wp-escape-html", "wp-polyfill"}, "b3bda690cfc516378771", 1))
|
||||
m.Store("wp-escape-html", NewScript("wp-escape-html", "/wp-includes/js/dist/escape-html"+suffix+".js", []string{"wp-polyfill"}, "03e27a7b6ae14f7afaa6", 1))
|
||||
m.Store("wp-format-library", NewScript("wp-format-library", "/wp-includes/js/dist/format-library"+suffix+".js", []string{"wp-a11y", "wp-block-editor", "wp-components", "wp-data", "wp-element", "wp-html-entities", "wp-i18n", "wp-polyfill", "wp-primitives", "wp-rich-text", "wp-url"}, "cd4a10ec005e2f001978", 1))
|
||||
m.Store("wp-hooks", NewScript("wp-hooks", "/wp-includes/js/dist/hooks"+suffix+".js", []string{"wp-polyfill"}, "4169d3cf8e8d95a3d6d5", 1))
|
||||
m.Store("wp-html-entities", NewScript("wp-html-entities", "/wp-includes/js/dist/html-entities"+suffix+".js", []string{"wp-polyfill"}, "36a4a255da7dd2e1bf8e", 1))
|
||||
m.Store("wp-i18n", NewScript("wp-i18n", "/wp-includes/js/dist/i18n"+suffix+".js", []string{"wp-hooks", "wp-polyfill"}, "9e794f35a71bb98672ae", 1))
|
||||
m.Store("wp-is-shallow-equal", NewScript("wp-is-shallow-equal", "/wp-includes/js/dist/is-shallow-equal"+suffix+".js", []string{"wp-polyfill"}, "20c2b06ecf04afb14fee", 1))
|
||||
m.Store("wp-keyboard-shortcuts", NewScript("wp-keyboard-shortcuts", "/wp-includes/js/dist/keyboard-shortcuts"+suffix+".js", []string{"wp-data", "wp-element", "wp-keycodes", "wp-polyfill"}, "b696c16720133edfc065", 1))
|
||||
m.Store("wp-keycodes", NewScript("wp-keycodes", "/wp-includes/js/dist/keycodes"+suffix+".js", []string{"wp-i18n", "wp-polyfill"}, "184b321fa2d3bc7fd173", 1))
|
||||
m.Store("wp-list-reusable-blocks", NewScript("wp-list-reusable-blocks", "/wp-includes/js/dist/list-reusable-blocks"+suffix+".js", []string{"wp-api-fetch", "wp-components", "wp-compose", "wp-element", "wp-i18n", "wp-polyfill"}, "6ba78be26d660b6af113", 1))
|
||||
m.Store("wp-media-utils", NewScript("wp-media-utils", "/wp-includes/js/dist/media-utils"+suffix+".js", []string{"wp-api-fetch", "wp-blob", "wp-element", "wp-i18n", "wp-polyfill"}, "f837b6298c83612cd6f6", 1))
|
||||
m.Store("wp-notices", NewScript("wp-notices", "/wp-includes/js/dist/notices"+suffix+".js", []string{"wp-data", "wp-polyfill"}, "9c1575b7a31659f45a45", 1))
|
||||
m.Store("wp-nux", NewScript("wp-nux", "/wp-includes/js/dist/nux"+suffix+".js", []string{"wp-components", "wp-compose", "wp-data", "wp-deprecated", "wp-element", "wp-i18n", "wp-polyfill", "wp-primitives"}, "038c48e26a91639ae8ab", 1))
|
||||
m.Store("wp-plugins", NewScript("wp-plugins", "/wp-includes/js/dist/plugins"+suffix+".js", []string{"wp-compose", "wp-element", "wp-hooks", "wp-polyfill", "wp-primitives"}, "0d1b90278bae7df6ecf9", 1))
|
||||
m.Store("wp-preferences", NewScript("wp-preferences", "/wp-includes/js/dist/preferences"+suffix+".js", []string{"wp-a11y", "wp-components", "wp-data", "wp-element", "wp-i18n", "wp-polyfill", "wp-primitives", "wp-preferences-persistence"}, "c66e137a7e588dab54c3", 1))
|
||||
m.Store("wp-preferences-persistence", NewScript("wp-preferences-persistence", "/wp-includes/js/dist/preferences-persistence"+suffix+".js", []string{"wp-api-fetch", "wp-polyfill"}, "c5543628aa7ff5bd5be4", 1))
|
||||
m.Store("wp-primitives", NewScript("wp-primitives", "/wp-includes/js/dist/primitives"+suffix+".js", []string{"wp-element", "wp-polyfill"}, "dfac1545e52734396640", 1))
|
||||
m.Store("wp-priority-queue", NewScript("wp-priority-queue", "/wp-includes/js/dist/priority-queue"+suffix+".js", []string{"wp-polyfill"}, "422e19e9d48b269c5219", 1))
|
||||
m.Store("wp-private-apis", NewScript("wp-private-apis", "/wp-includes/js/dist/private-apis"+suffix+".js", []string{"wp-polyfill"}, "6f247ed2bc3571743bba", 1))
|
||||
m.Store("wp-redux-routine", NewScript("wp-redux-routine", "/wp-includes/js/dist/redux-routine"+suffix+".js", []string{"wp-polyfill"}, "d86e7e9f062d7582f76b", 1))
|
||||
m.Store("wp-reusable-blocks", NewScript("wp-reusable-blocks", "/wp-includes/js/dist/reusable-blocks"+suffix+".js", []string{"wp-block-editor", "wp-blocks", "wp-components", "wp-core-data", "wp-data", "wp-element", "wp-i18n", "wp-notices", "wp-polyfill", "wp-primitives", "wp-url"}, "a7367a6154c724b51b31", 1))
|
||||
m.Store("wp-rich-text", NewScript("wp-rich-text", "/wp-includes/js/dist/rich-text"+suffix+".js", []string{"wp-a11y", "wp-compose", "wp-data", "wp-deprecated", "wp-element", "wp-escape-html", "wp-i18n", "wp-keycodes", "wp-polyfill"}, "9307ec04c67d79b6e813", 1))
|
||||
m.Store("wp-server-side-render", NewScript("wp-server-side-render", "/wp-includes/js/dist/server-side-render"+suffix+".js", []string{"wp-api-fetch", "wp-blocks", "wp-components", "wp-compose", "wp-data", "wp-element", "wp-i18n", "wp-polyfill", "wp-url"}, "d1bc93277666143a3f5e", 1))
|
||||
m.Store("wp-shortcode", NewScript("wp-shortcode", "/wp-includes/js/dist/shortcode"+suffix+".js", []string{"wp-polyfill"}, "7539044b04e6bca57f2e", 1))
|
||||
m.Store("wp-style-engine", NewScript("wp-style-engine", "/wp-includes/js/dist/style-engine"+suffix+".js", []string{"lodash", "wp-polyfill"}, "528e6cf281ffc9b7bd3c", 1))
|
||||
m.Store("wp-token-list", NewScript("wp-token-list", "/wp-includes/js/dist/token-list"+suffix+".js", []string{"wp-polyfill"}, "f2cf0bb3ae80de227e43", 1))
|
||||
m.Store("wp-url", NewScript("wp-url", "/wp-includes/js/dist/url"+suffix+".js", []string{"wp-polyfill"}, "16185fce2fb043a0cfed", 1))
|
||||
m.Store("wp-viewport", NewScript("wp-viewport", "/wp-includes/js/dist/viewport"+suffix+".js", []string{"wp-compose", "wp-data", "wp-element", "wp-polyfill"}, "4f6bd168b2b8b45c8a6b", 1))
|
||||
m.Store("wp-warning", NewScript("wp-warning", "/wp-includes/js/dist/warning"+suffix+".js", []string{"wp-polyfill"}, "4acee5fc2fd9a24cefc2", 1))
|
||||
m.Store("wp-widgets", NewScript("wp-widgets", "/wp-includes/js/dist/widgets"+suffix+".js", []string{"wp-api-fetch", "wp-block-editor", "wp-blocks", "wp-components", "wp-compose", "wp-core-data", "wp-data", "wp-element", "wp-i18n", "wp-notices", "wp-polyfill", "wp-primitives"}, "040ac8be5e0cfc4b52df", 1))
|
||||
m.Store("wp-wordcount", NewScript("wp-wordcount", "/wp-includes/js/dist/wordcount"+suffix+".js", []string{"wp-polyfill"}, "feb9569307aec24292f2", 1))
|
||||
}
|
||||
|
||||
func defaultLocalize() {
|
||||
/*AddDynamicLocalize(h, "utils", "userSettings", map[string]any{
|
||||
"url": h.C.Request.RequestURI,
|
||||
"uid": "0",
|
||||
"time": number.IntToString(time.Now().Unix()),
|
||||
"secure": h.IsHttps(),
|
||||
})*/
|
||||
|
||||
AddStaticLocalize("wp-ajax-response", "wpAjax", map[string]any{
|
||||
"noPerm": `抱歉,您不能这么做。`,
|
||||
"broken": `出现了问题。`,
|
||||
})
|
||||
AddStaticLocalize("wp-api-request", "wpApiSettings", map[string]any{
|
||||
"root": `/wp-json/`,
|
||||
"nonce": `9a3ce0a5d7`,
|
||||
"versionString": `wp/v2/`,
|
||||
})
|
||||
AddStaticLocalize("jquery-ui-autocomplete", "uiAutocompleteL10n", map[string]any{
|
||||
"noResults": `未找到结果。`,
|
||||
"oneResult": `找到1个结果。使用上下方向键来导航。`,
|
||||
"manyResults": `找到%d个结果。使用上下方向键来导航。`,
|
||||
"itemSelected": `已选择项目。`,
|
||||
})
|
||||
AddStaticLocalize("thickbox", "thickboxL10n", map[string]any{
|
||||
"next": `下一页 >`,
|
||||
"prev": `< 上一页`,
|
||||
"image": `图片`,
|
||||
"of": `/`,
|
||||
"close": `关闭`,
|
||||
"noiframes": `这个功能需要iframe的支持。您可能禁止了iframe的显示,或您的浏览器不支持此功能。`,
|
||||
"loadingAnimation": `/wp-includes/js/thickbox/loadingAnimation.gif`,
|
||||
})
|
||||
|
||||
AddStaticLocalize("mediaelement", "_wpmejsSettings", map[string]any{
|
||||
"pluginPath": `/wp-includes/js/mediaelement/`,
|
||||
"classPrefix": `mejs-`,
|
||||
"stretching": `responsive`,
|
||||
"audioShortcodeLibrary": `mediaelement`,
|
||||
"videoShortcodeLibrary": `mediaelement`,
|
||||
})
|
||||
AddStaticLocalize("zxcvbn-async", "_zxcvbnSettings", map[string]any{
|
||||
"src": `/wp-includes/js/zxcvbn.min.js`,
|
||||
})
|
||||
|
||||
AddStaticLocalize("mce-view", "mceViewL10n", map[string]any{
|
||||
"shortcodes": []string{"wp_caption", "caption", "gallery", "playlist", "audio", "video", "embed"},
|
||||
})
|
||||
AddStaticLocalize("word-count", "wordCountL10n", map[string]any{
|
||||
"type": `characters_excluding_spaces`,
|
||||
"shortcodes": []string{"wp_caption", "caption", "gallery", "playlist", "audio", "video", "embed"},
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func defaultTranslate() {
|
||||
SetTranslation("common", "default", "")
|
||||
SetTranslation("wp-pointer", "default", "")
|
||||
SetTranslation("wp-auth-check", "default", "")
|
||||
SetTranslation("wp-theme-plugin-editor", "default", "")
|
||||
SetTranslation("password-strength-meter", "default", "")
|
||||
SetTranslation("application-passwords", "default", "")
|
||||
SetTranslation("auth-app", "default", "")
|
||||
SetTranslation("user-profile", "default", "")
|
||||
SetTranslation("media-views", "default", "")
|
||||
SetTranslation("media-editor", "default", "")
|
||||
SetTranslation("wp-a11y", "default", "")
|
||||
SetTranslation("wp-annotations", "default", "")
|
||||
SetTranslation("wp-api-fetch", "default", "")
|
||||
SetTranslation("wp-block-directory", "default", "")
|
||||
SetTranslation("wp-block-editor", "default", "")
|
||||
SetTranslation("wp-block-library", "default", "")
|
||||
SetTranslation("wp-blocks", "default", "")
|
||||
SetTranslation("wp-components", "default", "")
|
||||
SetTranslation("wp-core-data", "default", "")
|
||||
SetTranslation("wp-customize-widgets", "default", "")
|
||||
SetTranslation("wp-edit-post", "default", "")
|
||||
SetTranslation("wp-edit-site", "default", "")
|
||||
SetTranslation("wp-edit-widgets", "default", "")
|
||||
SetTranslation("wp-editor", "default", "")
|
||||
SetTranslation("wp-format-library", "default", "")
|
||||
SetTranslation("wp-keycodes", "default", "")
|
||||
SetTranslation("wp-list-reusable-blocks", "default", "")
|
||||
SetTranslation("wp-media-utils", "default", "")
|
||||
SetTranslation("wp-nux", "default", "")
|
||||
SetTranslation("wp-preferences", "default", "")
|
||||
SetTranslation("wp-reusable-blocks", "default", "")
|
||||
SetTranslation("wp-rich-text", "default", "")
|
||||
SetTranslation("wp-server-side-render", "default", "")
|
||||
SetTranslation("wp-widgets", "default", "")
|
||||
SetTranslation("common", "default", "")
|
||||
SetTranslation("wp-pointer", "default", "")
|
||||
SetTranslation("wp-auth-check", "default", "")
|
||||
SetTranslation("wp-theme-plugin-editor", "default", "")
|
||||
SetTranslation("password-strength-meter", "default", "")
|
||||
SetTranslation("application-passwords", "default", "")
|
||||
SetTranslation("auth-app", "default", "")
|
||||
SetTranslation("user-profile", "default", "")
|
||||
SetTranslation("media-views", "default", "")
|
||||
SetTranslation("media-editor", "default", "")
|
||||
SetTranslation("wp-a11y", "default", "")
|
||||
SetTranslation("wp-annotations", "default", "")
|
||||
SetTranslation("wp-api-fetch", "default", "")
|
||||
SetTranslation("wp-block-directory", "default", "")
|
||||
SetTranslation("wp-block-editor", "default", "")
|
||||
SetTranslation("wp-block-library", "default", "")
|
||||
SetTranslation("wp-blocks", "default", "")
|
||||
SetTranslation("wp-components", "default", "")
|
||||
SetTranslation("wp-core-data", "default", "")
|
||||
SetTranslation("wp-customize-widgets", "default", "")
|
||||
SetTranslation("wp-edit-post", "default", "")
|
||||
SetTranslation("wp-edit-site", "default", "")
|
||||
SetTranslation("wp-edit-widgets", "default", "")
|
||||
SetTranslation("wp-editor", "default", "")
|
||||
SetTranslation("wp-format-library", "default", "")
|
||||
SetTranslation("wp-keycodes", "default", "")
|
||||
SetTranslation("wp-list-reusable-blocks", "default", "")
|
||||
SetTranslation("wp-media-utils", "default", "")
|
||||
SetTranslation("wp-nux", "default", "")
|
||||
SetTranslation("wp-preferences", "default", "")
|
||||
SetTranslation("wp-reusable-blocks", "default", "")
|
||||
SetTranslation("wp-rich-text", "default", "")
|
||||
SetTranslation("wp-server-side-render", "default", "")
|
||||
SetTranslation("wp-widgets", "default", "")
|
||||
}
|
||||
|
||||
func defaultAddData() {
|
||||
AddScriptData("json2", "conditional", `lt IE 8`)
|
||||
AddScriptData("wp-embed-template-ie", "conditional", `lte IE 8`)
|
||||
AddScriptData("wp-block-library-theme", "path", `wp-includes/css/dist/block-library/theme.min.css`)
|
||||
AddScriptData("wp-block-editor", "path", `/wp-includes/css/dist/block-editor/style.min.css`)
|
||||
AddScriptData("wp-block-library", "path", `/wp-includes/css/dist/block-library/style.min.css`)
|
||||
AddScriptData("wp-block-directory", "path", `/wp-includes/css/dist/block-directory/style.min.css`)
|
||||
AddScriptData("wp-components", "path", `/wp-includes/css/dist/components/style.min.css`)
|
||||
AddScriptData("wp-edit-post", "path", `/wp-includes/css/dist/edit-post/style.min.css`)
|
||||
AddScriptData("wp-editor", "path", `/wp-includes/css/dist/editor/style.min.css`)
|
||||
AddScriptData("wp-format-library", "path", `/wp-includes/css/dist/format-library/style.min.css`)
|
||||
AddScriptData("wp-list-reusable-blocks", "path", `/wp-includes/css/dist/list-reusable-blocks/style.min.css`)
|
||||
AddScriptData("wp-reusable-blocks", "path", `/wp-includes/css/dist/reusable-blocks/style.min.css`)
|
||||
AddScriptData("wp-nux", "path", `/wp-includes/css/dist/nux/style.min.css`)
|
||||
AddScriptData("wp-widgets", "path", `/wp-includes/css/dist/widgets/style.min.css`)
|
||||
AddScriptData("wp-edit-widgets", "path", `/wp-includes/css/dist/edit-widgets/style.min.css`)
|
||||
AddScriptData("wp-customize-widgets", "path", `/wp-includes/css/dist/customize-widgets/style.min.css`)
|
||||
AddScriptData("wp-edit-site", "path", `/wp-includes/css/dist/edit-site/style.min.css`)
|
||||
AddScriptData("common", "rtl", `replace`)
|
||||
AddScriptData("common", "suffix", `.min`)
|
||||
AddScriptData("forms", "rtl", `replace`)
|
||||
AddScriptData("forms", "suffix", `.min`)
|
||||
AddScriptData("admin-menu", "rtl", `replace`)
|
||||
AddScriptData("admin-menu", "suffix", `.min`)
|
||||
AddScriptData("dashboard", "rtl", `replace`)
|
||||
AddScriptData("dashboard", "suffix", `.min`)
|
||||
AddScriptData("list-tables", "rtl", `replace`)
|
||||
AddScriptData("list-tables", "suffix", `.min`)
|
||||
AddScriptData("edit", "rtl", `replace`)
|
||||
AddScriptData("edit", "suffix", `.min`)
|
||||
AddScriptData("revisions", "rtl", `replace`)
|
||||
AddScriptData("revisions", "suffix", `.min`)
|
||||
AddScriptData("media", "rtl", `replace`)
|
||||
AddScriptData("media", "suffix", `.min`)
|
||||
AddScriptData("themes", "rtl", `replace`)
|
||||
AddScriptData("themes", "suffix", `.min`)
|
||||
AddScriptData("about", "rtl", `replace`)
|
||||
AddScriptData("about", "suffix", `.min`)
|
||||
AddScriptData("nav-menus", "rtl", `replace`)
|
||||
AddScriptData("nav-menus", "suffix", `.min`)
|
||||
AddScriptData("widgets", "rtl", `replace`)
|
||||
AddScriptData("widgets", "suffix", `.min`)
|
||||
AddScriptData("site-icon", "rtl", `replace`)
|
||||
AddScriptData("site-icon", "suffix", `.min`)
|
||||
AddScriptData("l10n", "rtl", `replace`)
|
||||
AddScriptData("l10n", "suffix", `.min`)
|
||||
AddScriptData("install", "rtl", `replace`)
|
||||
AddScriptData("install", "suffix", `.min`)
|
||||
AddScriptData("wp-color-picker", "rtl", `replace`)
|
||||
AddScriptData("wp-color-picker", "suffix", `.min`)
|
||||
AddScriptData("customize-controls", "rtl", `replace`)
|
||||
AddScriptData("customize-controls", "suffix", `.min`)
|
||||
AddScriptData("customize-widgets", "rtl", `replace`)
|
||||
AddScriptData("customize-widgets", "suffix", `.min`)
|
||||
AddScriptData("customize-nav-menus", "rtl", `replace`)
|
||||
AddScriptData("customize-nav-menus", "suffix", `.min`)
|
||||
AddScriptData("customize-preview", "rtl", `replace`)
|
||||
AddScriptData("customize-preview", "suffix", `.min`)
|
||||
AddScriptData("login", "rtl", `replace`)
|
||||
AddScriptData("login", "suffix", `.min`)
|
||||
AddScriptData("site-health", "rtl", `replace`)
|
||||
AddScriptData("site-health", "suffix", `.min`)
|
||||
AddScriptData("buttons", "rtl", `replace`)
|
||||
AddScriptData("buttons", "suffix", `.min`)
|
||||
AddScriptData("admin-bar", "rtl", `replace`)
|
||||
AddScriptData("admin-bar", "suffix", `.min`)
|
||||
AddScriptData("wp-auth-check", "rtl", `replace`)
|
||||
AddScriptData("wp-auth-check", "suffix", `.min`)
|
||||
AddScriptData("editor-buttons", "rtl", `replace`)
|
||||
AddScriptData("editor-buttons", "suffix", `.min`)
|
||||
AddScriptData("media-views", "rtl", `replace`)
|
||||
AddScriptData("media-views", "suffix", `.min`)
|
||||
AddScriptData("wp-pointer", "rtl", `replace`)
|
||||
AddScriptData("wp-pointer", "suffix", `.min`)
|
||||
AddScriptData("wp-jquery-ui-dialog", "rtl", `replace`)
|
||||
AddScriptData("wp-jquery-ui-dialog", "suffix", `.min`)
|
||||
AddScriptData("wp-reset-editor-styles", "rtl", `replace`)
|
||||
AddScriptData("wp-reset-editor-styles", "suffix", `.min`)
|
||||
AddScriptData("wp-editor-classic-layout-styles", "rtl", `replace`)
|
||||
AddScriptData("wp-editor-classic-layout-styles", "suffix", `.min`)
|
||||
AddScriptData("wp-block-library-theme", "rtl", `replace`)
|
||||
AddScriptData("wp-block-library-theme", "suffix", `.min`)
|
||||
AddScriptData("wp-edit-blocks", "rtl", `replace`)
|
||||
AddScriptData("wp-edit-blocks", "suffix", `.min`)
|
||||
AddScriptData("wp-block-editor", "rtl", `replace`)
|
||||
AddScriptData("wp-block-editor", "suffix", `.min`)
|
||||
AddScriptData("wp-block-library", "rtl", `replace`)
|
||||
AddScriptData("wp-block-library", "suffix", `.min`)
|
||||
AddScriptData("wp-block-directory", "rtl", `replace`)
|
||||
AddScriptData("wp-block-directory", "suffix", `.min`)
|
||||
AddScriptData("wp-components", "rtl", `replace`)
|
||||
AddScriptData("wp-components", "suffix", `.min`)
|
||||
AddScriptData("wp-customize-widgets", "rtl", `replace`)
|
||||
AddScriptData("wp-customize-widgets", "suffix", `.min`)
|
||||
AddScriptData("wp-edit-post", "rtl", `replace`)
|
||||
AddScriptData("wp-edit-post", "suffix", `.min`)
|
||||
AddScriptData("wp-edit-site", "rtl", `replace`)
|
||||
AddScriptData("wp-edit-site", "suffix", `.min`)
|
||||
AddScriptData("wp-edit-widgets", "rtl", `replace`)
|
||||
AddScriptData("wp-edit-widgets", "suffix", `.min`)
|
||||
AddScriptData("wp-editor", "rtl", `replace`)
|
||||
AddScriptData("wp-editor", "suffix", `.min`)
|
||||
AddScriptData("wp-format-library", "rtl", `replace`)
|
||||
AddScriptData("wp-format-library", "suffix", `.min`)
|
||||
AddScriptData("wp-list-reusable-blocks", "rtl", `replace`)
|
||||
AddScriptData("wp-list-reusable-blocks", "suffix", `.min`)
|
||||
AddScriptData("wp-reusable-blocks", "rtl", `replace`)
|
||||
AddScriptData("wp-reusable-blocks", "suffix", `.min`)
|
||||
AddScriptData("wp-nux", "rtl", `replace`)
|
||||
AddScriptData("wp-nux", "suffix", `.min`)
|
||||
AddScriptData("wp-widgets", "rtl", `replace`)
|
||||
AddScriptData("wp-widgets", "suffix", `.min`)
|
||||
AddScriptData("deprecated-media", "rtl", `replace`)
|
||||
AddScriptData("deprecated-media", "suffix", `.min`)
|
||||
AddScriptData("farbtastic", "rtl", `replace`)
|
||||
AddScriptData("farbtastic", "suffix", `.min`)
|
||||
|
||||
}
|
||||
|
||||
func defaultAddInLineScript() {
|
||||
AddInlineScript("mediaelement-core", `var mejsL10n = {"language":"zh","strings":{"mejs.download-file":"\u4e0b\u8f7d\u6587\u4ef6","mejs.install-flash":"\u60a8\u6b63\u5728\u4f7f\u7528\u7684\u6d4f\u89c8\u5668\u672a\u5b89\u88c5\u6216\u542f\u7528Flash\u64ad\u653e\u5668\uff0c\u8bf7\u542f\u7528\u60a8\u7684Flash\u64ad\u653e\u5668\u63d2\u4ef6\uff0c\u6216\u4ece https:\/\/get.adobe.com\/flashplayer\/ \u4e0b\u8f7d\u6700\u65b0\u7248\u3002","mejs.fullscreen":"\u5168\u5c4f","mejs.play":"\u64ad\u653e","mejs.pause":"\u6682\u505c","mejs.time-slider":"\u65f6\u95f4\u8f74","mejs.time-help-text":"\u4f7f\u7528\u5de6\/\u53f3\u7bad\u5934\u952e\u6765\u524d\u8fdb\u4e00\u79d2\uff0c\u4e0a\/\u4e0b\u7bad\u5934\u952e\u6765\u524d\u8fdb\u5341\u79d2\u3002","mejs.live-broadcast":"\u73b0\u573a\u76f4\u64ad","mejs.volume-help-text":"\u4f7f\u7528\u4e0a\/\u4e0b\u7bad\u5934\u952e\u6765\u589e\u9ad8\u6216\u964d\u4f4e\u97f3\u91cf\u3002","mejs.unmute":"\u53d6\u6d88\u9759\u97f3","mejs.mute":"\u9759\u97f3","mejs.volume-slider":"\u97f3\u91cf","mejs.video-player":"\u89c6\u9891\u64ad\u653e\u5668","mejs.audio-player":"\u97f3\u9891\u64ad\u653e\u5668","mejs.captions-subtitles":"\u8bf4\u660e\u6587\u5b57\u6216\u5b57\u5e55","mejs.captions-chapters":"\u7ae0\u8282","mejs.none":"\u65e0","mejs.afrikaans":"\u5357\u975e\u8377\u5170\u8bed","mejs.albanian":"\u963f\u5c14\u5df4\u5c3c\u4e9a\u8bed","mejs.arabic":"\u963f\u62c9\u4f2f\u8bed","mejs.belarusian":"\u767d\u4fc4\u7f57\u65af\u8bed","mejs.bulgarian":"\u4fdd\u52a0\u5229\u4e9a\u8bed","mejs.catalan":"\u52a0\u6cf0\u7f57\u5c3c\u4e9a\u8bed","mejs.chinese":"\u4e2d\u6587","mejs.chinese-simplified":"\u4e2d\u6587\uff08\u7b80\u4f53\uff09","mejs.chinese-traditional":"\u4e2d\u6587(\uff08\u7e41\u4f53\uff09","mejs.croatian":"\u514b\u7f57\u5730\u4e9a\u8bed","mejs.czech":"\u6377\u514b\u8bed","mejs.danish":"\u4e39\u9ea6\u8bed","mejs.dutch":"\u8377\u5170\u8bed","mejs.english":"\u82f1\u8bed","mejs.estonian":"\u7231\u6c99\u5c3c\u4e9a\u8bed","mejs.filipino":"\u83f2\u5f8b\u5bbe\u8bed","mejs.finnish":"\u82ac\u5170\u8bed","mejs.french":"\u6cd5\u8bed","mejs.galician":"\u52a0\u5229\u897f\u4e9a\u8bed","mejs.german":"\u5fb7\u8bed","mejs.greek":"\u5e0c\u814a\u8bed","mejs.haitian-creole":"\u6d77\u5730\u514b\u91cc\u5965\u5c14\u8bed","mejs.hebrew":"\u5e0c\u4f2f\u6765\u8bed","mejs.hindi":"\u5370\u5730\u8bed","mejs.hungarian":"\u5308\u7259\u5229\u8bed","mejs.icelandic":"\u51b0\u5c9b\u8bed","mejs.indonesian":"\u5370\u5ea6\u5c3c\u897f\u4e9a\u8bed","mejs.irish":"\u7231\u5c14\u5170\u8bed","mejs.italian":"\u610f\u5927\u5229\u8bed","mejs.japanese":"\u65e5\u8bed","mejs.korean":"\u97e9\u8bed","mejs.latvian":"\u62c9\u8131\u7ef4\u4e9a\u8bed","mejs.lithuanian":"\u7acb\u9676\u5b9b\u8bed","mejs.macedonian":"\u9a6c\u5176\u987f\u8bed","mejs.malay":"\u9a6c\u6765\u8bed","mejs.maltese":"\u9a6c\u8033\u4ed6\u8bed","mejs.norwegian":"\u632a\u5a01\u8bed","mejs.persian":"\u6ce2\u65af\u8bed","mejs.polish":"\u6ce2\u5170\u8bed","mejs.portuguese":"\u8461\u8404\u7259\u8bed","mejs.romanian":"\u7f57\u9a6c\u5c3c\u4e9a\u8bed","mejs.russian":"\u4fc4\u8bed","mejs.serbian":"\u585e\u5c14\u7ef4\u4e9a\u8bed","mejs.slovak":"\u65af\u6d1b\u4f10\u514b\u8bed","mejs.slovenian":"\u65af\u6d1b\u6587\u5c3c\u4e9a\u8bed","mejs.spanish":"\u897f\u73ed\u7259\u8bed","mejs.swahili":"\u65af\u74e6\u5e0c\u91cc\u8bed","mejs.swedish":"\u745e\u5178\u8bed","mejs.tagalog":"\u4ed6\u52a0\u7984\u8bed","mejs.thai":"\u6cf0\u8bed","mejs.turkish":"\u571f\u8033\u5176\u8bed","mejs.ukrainian":"\u4e4c\u514b\u5170\u8bed","mejs.vietnamese":"\u8d8a\u5357\u8bed","mejs.welsh":"\u5a01\u5c14\u58eb\u8bed","mejs.yiddish":"\u610f\u7b2c\u7eea\u8bed"}};`, "before")
|
||||
AddInlineScript("lodash", `window.lodash = _.noConflict();`, "after")
|
||||
AddInlineScript("moment", `moment.updateLocale( 'zh_CN', {"months":["1\u6708","2\u6708","3\u6708","4\u6708","5\u6708","6\u6708","7\u6708","8\u6708","9\u6708","10\u6708","11\u6708","12\u6708"],"monthsShort":["1\u6708","2\u6708","3\u6708","4\u6708","5\u6708","6\u6708","7\u6708","8\u6708","9\u6708","10\u6708","11\u6708","12\u6708"],"weekdays":["\u661f\u671f\u65e5","\u661f\u671f\u4e00","\u661f\u671f\u4e8c","\u661f\u671f\u4e09","\u661f\u671f\u56db","\u661f\u671f\u4e94","\u661f\u671f\u516d"],"weekdaysShort":["\u5468\u65e5","\u5468\u4e00","\u5468\u4e8c","\u5468\u4e09","\u5468\u56db","\u5468\u4e94","\u5468\u516d"],"week":{"dow":1},"longDateFormat":{"LT":"ag:i","LTS":null,"L":null,"LL":"Y\u5e74n\u6708j\u65e5","LLL":"Y\u5e74n\u6708j\u65e5a g:i","LLLL":null}} );`, "after")
|
||||
AddInlineScript("wp-i18n", `wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ 'ltr' ] } );`, "after")
|
||||
AddInlineScript("text-widgets", `wp.textWidgets.idBases.push( "text" );`, "after")
|
||||
AddInlineScript("custom-html-widgets", `wp.customHtmlWidgets.idBases.push( "custom_html" );`, "after")
|
||||
}
|
||||
|
||||
func defaultAddInLineStyle() {
|
||||
AddInlineStyle("global-styles", GetGlobalStyletSheet())
|
||||
AddInlineStyle("global-styles", `.wp-block-navigation a:where(:not(.wp-element-button)){color: inherit;}`)
|
||||
AddInlineStyle("global-styles", `:where(.wp-block-columns.is-layout-flex){gap: 2em;}`)
|
||||
AddInlineStyle("global-styles", `.wp-block-pullquote{font-size: 1.5em;line-height: 1.6;}`)
|
||||
}
|
||||
|
||||
var re = regexp.MustCompile(`(?is:\([A-Za-z0-9'.:\-/, ]+\))`)
|
||||
var rea = regexp.MustCompile(`array\(array\(.*?\)\)`)
|
||||
|
||||
func InitDefaultScriptSetting() {
|
||||
initThemeJson()
|
||||
defaultLocalize()
|
||||
defaultTranslate()
|
||||
defaultAddData()
|
||||
defaultAddInLineScript()
|
||||
defaultAddInLineStyle()
|
||||
}
|
||||
|
||||
func initThemeJson() {
|
||||
blocksData := __blocksData()
|
||||
path := config.GetConfig().WpDir
|
||||
f, err := os.ReadFile(filepath.Join(path, "wp-includes/theme.json"))
|
||||
if err != nil {
|
||||
logs.Error(err, "can't open theme json", path)
|
||||
return
|
||||
}
|
||||
|
||||
var j map[string]any
|
||||
err = json.Unmarshal(f, &j)
|
||||
if err != nil {
|
||||
logs.Error(err, "can't parse theme json")
|
||||
return
|
||||
}
|
||||
t := ThemeJson{blocksData, j}
|
||||
setThemeJson(j)
|
||||
setSpacingSizes(t)
|
||||
__themeJson.Store(t)
|
||||
}
|
||||
|
||||
func setThemeJson(m map[string]any) {
|
||||
blocks, ok := maps.GetStrAnyVal[map[string]any](m, "settings.blocks")
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var paths = [][]string{{"settings"}}
|
||||
for name := range blocks {
|
||||
paths = append(paths, []string{"settings", "blocks", name})
|
||||
}
|
||||
for _, path := range paths {
|
||||
for _, metadatum := range presetsMetadata {
|
||||
pathx := append(path, metadatum.path...)
|
||||
key := strings.Join(pathx, ".")
|
||||
preset, ok := maps.GetStrAnyVal[[]any](m, key)
|
||||
if !ok || len(preset) < 1 {
|
||||
continue
|
||||
}
|
||||
var presets []map[string]string
|
||||
for _, a := range preset {
|
||||
v, ok := a.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
mm := map[string]string{}
|
||||
for kk, vv := range v {
|
||||
val, ok := vv.(string)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
mm[kk] = val
|
||||
}
|
||||
presets = append(presets, mm)
|
||||
}
|
||||
maps.SetStrAnyVal(m, key, map[string]any{
|
||||
"default": presets,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var __propertyMappings = map[string]string{
|
||||
"apiVersion": "api_version",
|
||||
"title": "title",
|
||||
"category": "category",
|
||||
"parent": "parent",
|
||||
"ancestor": "ancestor",
|
||||
"icon": "icon",
|
||||
"description": "description",
|
||||
"keywords": "keywords",
|
||||
"attributes": "attributes",
|
||||
"providesContext": "provides_context",
|
||||
"usesContext": "uses_context",
|
||||
"supports": "supports",
|
||||
"styles": "styles",
|
||||
"variations": "variations",
|
||||
"example": "example",
|
||||
}
|
||||
|
||||
func __propertyMap(m map[string]any) {
|
||||
for k, mappedKey := range __propertyMappings {
|
||||
vv, ok := m[k]
|
||||
if ok {
|
||||
m[mappedKey] = vv
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func __blocksData() map[string]any {
|
||||
path := config.GetConfig().WpDir
|
||||
//path := "/var/www/html/wordpress"
|
||||
b, err := os.ReadFile(filepath.Join(path, "wp-includes/blocks/blocks-json.php"))
|
||||
if err != nil {
|
||||
logs.Error(err, "can't open block json", path)
|
||||
return nil
|
||||
}
|
||||
bb := re.ReplaceAllStringFunc(string(b), func(s string) string {
|
||||
return str.Replace(s, map[string]string{
|
||||
"(": "[",
|
||||
")": "]",
|
||||
})
|
||||
})
|
||||
bb = strings.ReplaceAll(bb, "\"", `\"`)
|
||||
bb = rea.ReplaceAllStringFunc(bb, func(s string) string {
|
||||
s = strings.ReplaceAll(s, "array(array", "[")
|
||||
ss := []rune(s)
|
||||
ss[len(ss)-1] = ']'
|
||||
s = string(ss)
|
||||
return s
|
||||
})
|
||||
bb = str.Replace(bb, map[string]string{
|
||||
"<?php": "",
|
||||
"return": "",
|
||||
"array": "",
|
||||
"()": "[]",
|
||||
"(": "{",
|
||||
")": "}",
|
||||
"=>": ":",
|
||||
";": "",
|
||||
"'": `"`,
|
||||
})
|
||||
|
||||
var blocks map[string]any
|
||||
err = json.Unmarshal([]byte(bb), &blocks)
|
||||
if err != nil {
|
||||
logs.Error(err, "can't parse block json")
|
||||
return nil
|
||||
}
|
||||
c := map[string]any{
|
||||
"version": int64(2),
|
||||
}
|
||||
for k, v := range blocks {
|
||||
m, ok := v.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
_, ok = m["style"]
|
||||
if !ok {
|
||||
m["style"] = str.Join("wp-block-", k)
|
||||
}
|
||||
_, ok = m["editorStyle"]
|
||||
if !ok {
|
||||
m["editorStyle"] = str.Join("wp-block-", k, "-editor")
|
||||
}
|
||||
__propertyMap(m)
|
||||
name := maps.GetStrAnyValWithDefaults(m, "name", str.Join("core/", k))
|
||||
blocks[name] = v
|
||||
if name != k {
|
||||
delete(blocks, k)
|
||||
}
|
||||
__blockSelectors(m)
|
||||
s, ok := maps.GetStrAnyVal[map[string]any](m, "supports.__experimentalStyle")
|
||||
if ok {
|
||||
__removeComment(s)
|
||||
maps.SetStrAnyVal(c, str.Join("styles.blocks.", name), s)
|
||||
}
|
||||
_, ok = maps.GetStrAnyVal[string](m, "supports.spacing.blockGap.__experimentalDefault")
|
||||
if ok {
|
||||
key := str.Join("styles.blocks.", name, ".spacing.blockGap")
|
||||
_, ok := maps.GetStrAnyVal[string](c, key)
|
||||
if !ok {
|
||||
maps.SetStrAnyVal[map[string]any](c, key, nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
return map[string]any{
|
||||
"blocks_metadata": blocks,
|
||||
"theme_json": c,
|
||||
}
|
||||
}
|
||||
|
||||
func __blockSelectors(m map[string]any) {
|
||||
selector, ok := maps.GetStrAnyVal[string](m, "supports.__experimentalSelector")
|
||||
if !ok {
|
||||
vv, _ := maps.GetStrAnyVal[string](m, "name")
|
||||
selector = str.Join(".wp-block-", str.Replaces(vv,
|
||||
[]string{"core/", ""},
|
||||
[]string{"/", "-"},
|
||||
))
|
||||
}
|
||||
var features = map[string]string{}
|
||||
maps.SetStrAnyVal(m, "supports.selector", selector)
|
||||
color, ok := maps.GetStrAnyVal[string](m, "supports.color.__experimentalDuotone")
|
||||
if ok {
|
||||
maps.SetStrAnyVal(m, "duotone", color)
|
||||
}
|
||||
for k, v := range blockSupportFeatureLevelSelectors {
|
||||
key := str.Join("supports.", k, ".__experimentalSelector")
|
||||
vv, ok := maps.GetStrAnyVal[string](m, key)
|
||||
if ok && vv != "" {
|
||||
features[v] = scopeSelector(selector, vv)
|
||||
}
|
||||
}
|
||||
if len(features) > 0 {
|
||||
m["features"] = features
|
||||
}
|
||||
blockSelector := strings.Split(selector, ",")
|
||||
for name, selor := range __elements {
|
||||
var els []string
|
||||
for _, s := range blockSelector {
|
||||
if s == selor {
|
||||
els = append(els, selor)
|
||||
break
|
||||
}
|
||||
els = append(els, appendToSelector(selor, str.Join(s, " "), "left"))
|
||||
}
|
||||
maps.SetStrAnyVal(m, str.Join("elements.", name), strings.Join(els, ","))
|
||||
}
|
||||
styles, ok := maps.GetStrAnyVal[[]any](m, "styles")
|
||||
if ok {
|
||||
var styleSelectors = map[string]string{}
|
||||
for _, ss := range styles {
|
||||
s, ok := ss.(map[string]any)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
name, ok := maps.GetStrAnyVal[string](s, "name")
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
styleSelectors[name] = appendToSelector(str.Join(".is-style-", name, ".is-style-", name), selector, "")
|
||||
}
|
||||
m["styleVariations"] = styleSelectors
|
||||
}
|
||||
}
|
20
app/theme/wp/scriptloader/defaultscriptload_test.go
Normal file
20
app/theme/wp/scriptloader/defaultscriptload_test.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package scriptloader
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_themeJson(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
}{
|
||||
{
|
||||
name: "t1",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
initThemeJson()
|
||||
})
|
||||
}
|
||||
}
|
7
app/theme/wp/scriptloader/defaultstyles.go
Normal file
7
app/theme/wp/scriptloader/defaultstyles.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package scriptloader
|
||||
|
||||
import "github.com/fthvgb1/wp-go/safety"
|
||||
|
||||
func defaultStyles(m *safety.Map[string, *Style], suffix string) {
|
||||
|
||||
}
|
218
app/theme/wp/scriptloader/head.go
Normal file
218
app/theme/wp/scriptloader/head.go
Normal file
|
@ -0,0 +1,218 @@
|
|||
package scriptloader
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/logs"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp/components/widget"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/number"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type _style struct {
|
||||
handle string
|
||||
src string
|
||||
path string
|
||||
size int64
|
||||
}
|
||||
|
||||
func MaybeInlineStyles(h *wp.Handle) {
|
||||
totalInlineLimit := int64(0)
|
||||
var styles []_style
|
||||
ss := styleQueues.Load()
|
||||
for _, que := range ss.Queue {
|
||||
p, ok := __styles.Load(que)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
f, ok := p.Extra["path"]
|
||||
if !ok || f == nil {
|
||||
continue
|
||||
}
|
||||
ff := f[0]
|
||||
stat, err := os.Stat(ff)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
styles = append(styles, _style{
|
||||
handle: que,
|
||||
src: p.Src,
|
||||
path: ff,
|
||||
size: stat.Size(),
|
||||
})
|
||||
}
|
||||
if len(styles) < 1 {
|
||||
return
|
||||
}
|
||||
slice.Sort(styles, func(i, j _style) bool {
|
||||
return i.size > j.size
|
||||
})
|
||||
totalInlineSize := int64(0)
|
||||
for _, i := range styles {
|
||||
if totalInlineSize+i.size > totalInlineLimit {
|
||||
break
|
||||
}
|
||||
path := filepath.Join(i.path)
|
||||
css := reload.GetAnyValMapBy("script-loader-MaybeInlineStyles", i.handle, path, func(a string) string {
|
||||
css, err := os.ReadFile(i.path)
|
||||
if err != nil {
|
||||
logs.Error(err, "read file ", i.path)
|
||||
return ""
|
||||
}
|
||||
return string(css)
|
||||
})
|
||||
|
||||
s, _ := __styles.Load(i.handle)
|
||||
s.Src = ""
|
||||
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 PrintInlineStyles(handle string) string {
|
||||
o, _ := __styles.Load(handle)
|
||||
out := o.getData("after")
|
||||
if out == "" {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("<style id='%s-inline-css'%s>\n%s\n</style>\n", handle, "", out)
|
||||
}
|
||||
|
||||
func PrintStyle(h *wp.Handle, s ...string) {
|
||||
out := wp.GetComponentsArgs(h, "wp_style_out", str.NewBuilder())
|
||||
out.WriteString(s...)
|
||||
}
|
||||
func PrintHead(h *wp.Handle, s ...string) {
|
||||
out := wp.GetComponentsArgs(h, "wp_head", str.NewBuilder())
|
||||
out.WriteString(s...)
|
||||
}
|
||||
|
||||
func LinkHead(h *wp.Handle) {
|
||||
PrintHead(h, "<link rel=\"https://api.w.org/\" href=\"/wp-json\" />")
|
||||
if s := restGetQueriedResourceRoute(h); s != "" {
|
||||
PrintHead(h, "<link rel=\"alternate\" type=\"application/json\" href=", s, " />")
|
||||
}
|
||||
}
|
||||
|
||||
func restGetQueriedResourceRoute(h *wp.Handle) string {
|
||||
if cate, ok := widget.IsCategory(h); ok {
|
||||
return fmt.Sprintf("/wp/v2/categories/%d", cate.Terms.TermId)
|
||||
}
|
||||
if tag, ok := widget.IsTag(h); ok {
|
||||
return fmt.Sprintf("/wp/v2/tags/%d", tag.Terms.TermId)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func RsdLink(h *wp.Handle) {
|
||||
PrintHead(h, fmt.Sprintf("<link rel=\"EditURI\" type=\"application/rsd+xml\" title=\"RSD\" href=\"%s\" />\n", "xmlrpc.php?rsd"))
|
||||
}
|
||||
|
||||
func WlwmanifestLink(h *wp.Handle) {
|
||||
PrintHead(h, fmt.Sprintf("<link rel=\"wlwmanifest\" type=\"application/wlwmanifest+xml\" href=\"%s\" />\n", "/wp-includes/wlwmanifest.xml"))
|
||||
}
|
||||
|
||||
func LocaleStylesheet(h *wp.Handle) {
|
||||
uri := reload.GetAnyValBys("printHead-localStylesheet", h, func(a *wp.Handle) string {
|
||||
ur := str.Join("wp-content/themes", h.Theme(), str.Join(wpconfig.GetLang(), ".css"))
|
||||
path := filepath.Join(config.GetConfig().WpDir, ur)
|
||||
if helper.FileExist(path) {
|
||||
return str.Join("/", ur)
|
||||
}
|
||||
return ""
|
||||
})
|
||||
if uri != "" {
|
||||
PrintHead(h, fmt.Sprintf("<link rel=\"stylesheet\" href=\"%s\"%s media=\"screen\" />", uri, ""))
|
||||
}
|
||||
}
|
||||
|
||||
func TheGenerator(h *wp.Handle) {
|
||||
PrintHead(h, fmt.Sprintf(`<meta name="generator" content="WordPress %s"/>`, "6.2.2"))
|
||||
}
|
||||
|
||||
func ShortLinkWpHead(h *wp.Handle) {
|
||||
if h.Scene() != constraints.Detail || h.Detail.Post.Id < 1 {
|
||||
return
|
||||
}
|
||||
shortlink := ""
|
||||
post := h.Detail.Post
|
||||
if post.PostType == "page" && wpconfig.GetOption("page_on_front") == number.IntToString(post.Id) &&
|
||||
wpconfig.GetOption("show_on_front") == "page" {
|
||||
shortlink = "/"
|
||||
} else {
|
||||
shortlink = str.Join("/p/", number.IntToString(post.Id))
|
||||
}
|
||||
if shortlink != "" {
|
||||
PrintHead(h, fmt.Sprintf(`<link rel='shortlink' href="%s" />`, shortlink))
|
||||
}
|
||||
}
|
||||
|
||||
func customLogoHeaderStyles(h *wp.Handle) {
|
||||
mod := h.CommonThemeMods()
|
||||
if !mod.ThemeSupport.CustomHeader.HeaderText && mod.ThemeSupport.CustomLogo.HeaderText != "" {
|
||||
class := mod.ThemeSupport.CustomLogo.HeaderText
|
||||
attr := ""
|
||||
if !slice.IsContained(mod.ThemeSupport.HTML5, "style") {
|
||||
attr = ` type="text/css"`
|
||||
}
|
||||
PrintHead(h, fmt.Sprintf(`<style id="custom-logo-css"%s>
|
||||
.%s {
|
||||
position: absolute;
|
||||
clip: rect(1px, 1px, 1px, 1px);
|
||||
}
|
||||
</style>`, attr, class))
|
||||
}
|
||||
}
|
||||
|
||||
func PrintHeadToStr(h *wp.Handle) string {
|
||||
h.DoActionFilter("wp_head", "", h)
|
||||
return wp.GetComponentsArgs(h, "wp_head", str.NewBuilder()).String()
|
||||
}
|
409
app/theme/wp/scriptloader/scriptloader.go
Normal file
409
app/theme/wp/scriptloader/scriptloader.go
Normal file
|
@ -0,0 +1,409 @@
|
|||
package scriptloader
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/theme/wp"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var __styles = reload.MapBy(func(m *safety.Map[string, *Style]) {
|
||||
defaultStyles(m, ".css")
|
||||
})
|
||||
var __scripts = reload.MapBy[string, *Script](func(m *safety.Map[string, *Script]) {
|
||||
suffix := ".min"
|
||||
defaultScripts(m, suffix)
|
||||
|
||||
})
|
||||
|
||||
type Style struct {
|
||||
Dependencies
|
||||
}
|
||||
|
||||
type Script struct {
|
||||
Dependencies
|
||||
}
|
||||
|
||||
func addScript(handle string, src string, deps []string, ver string, args any) {
|
||||
script := NewScript(handle, src, deps, ver, args)
|
||||
__scripts.Store(handle, script)
|
||||
}
|
||||
|
||||
func localize(handle, objectname string, l10n map[string]any) string {
|
||||
if "jquery" == handle {
|
||||
handle = "jquery-core"
|
||||
}
|
||||
after, ok := maps.GetStrAnyVal[string](l10n, "l10n_print_after")
|
||||
if ok {
|
||||
delete(l10n, "l10n_print_after")
|
||||
}
|
||||
v, _ := json.Marshal(l10n)
|
||||
script := fmt.Sprintf("var %s = %s;", objectname, string(v))
|
||||
if after != "" {
|
||||
script = str.Join(script, "\n", after, ";")
|
||||
}
|
||||
return script
|
||||
}
|
||||
|
||||
func AddStaticLocalize(handle, objectname string, l10n map[string]any) {
|
||||
AddScriptData(handle, "data", localize(handle, objectname, l10n))
|
||||
}
|
||||
func AddDynamicLocalize(h *wp.Handle, handle, objectname string, l10n map[string]any) {
|
||||
AddDynamicData(h, handle, "data", localize(handle, objectname, l10n))
|
||||
}
|
||||
|
||||
func (d *Dependencies) getData(key string) string {
|
||||
return strings.Join(d.Extra[key], "\n")
|
||||
}
|
||||
func GetData(h *wp.Handle, handle, key string) string {
|
||||
hh, ok := __scripts.Load(handle)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
d := hh.Extra[key]
|
||||
d = append(d, GetDynamicData(h, handle, key))
|
||||
return strings.Join(d, "\n")
|
||||
}
|
||||
|
||||
func AddScriptData(handle, key, data string) {
|
||||
var s *Script
|
||||
var ok bool
|
||||
s, ok = __scripts.Load(handle)
|
||||
if !ok {
|
||||
s = NewScript(handle, "", nil, "", nil)
|
||||
}
|
||||
if s.Extra == nil {
|
||||
s.Extra = make(map[string][]string)
|
||||
}
|
||||
s.Extra[key] = append(s.Extra[key], data)
|
||||
}
|
||||
|
||||
func AddStyleData(handle, key, data string) {
|
||||
var s *Style
|
||||
var ok bool
|
||||
s, ok = __styles.Load(handle)
|
||||
if !ok {
|
||||
s = NewStyle(handle, "", nil, "", nil)
|
||||
}
|
||||
if s.Extra == nil {
|
||||
s.Extra = make(map[string][]string)
|
||||
}
|
||||
s.Extra[key] = append(s.Extra[key], data)
|
||||
}
|
||||
|
||||
func AddInlineScript(handle, data, position string) {
|
||||
if handle == "" || data == "" {
|
||||
return
|
||||
}
|
||||
if position != "after" {
|
||||
position = "before"
|
||||
}
|
||||
AddScriptData(handle, position, data)
|
||||
}
|
||||
|
||||
func AddInlineStyle(handle, data string) {
|
||||
if handle == "" || data == "" {
|
||||
return
|
||||
}
|
||||
AddStyleData(handle, "after", data)
|
||||
}
|
||||
|
||||
func InlineScripts(handle, position string, display bool) string {
|
||||
v, _ := __scripts.Load(handle)
|
||||
ss := v.getData(position)
|
||||
if ss == "" {
|
||||
return ""
|
||||
}
|
||||
scp := strings.Trim(ss, "\n")
|
||||
if display {
|
||||
return fmt.Sprintf("<script id='%s-js-%s'>\n%s\n</script>\n", handle, position, scp)
|
||||
}
|
||||
return scp
|
||||
}
|
||||
|
||||
func AddScript(handle string, src string, deps []string, ver string, args any) {
|
||||
script := NewScript(handle, src, deps, ver, args)
|
||||
__scripts.Store(handle, script)
|
||||
}
|
||||
|
||||
const (
|
||||
style = iota
|
||||
script
|
||||
)
|
||||
|
||||
var scriptQueues = reload.Vars(scriptQueue{})
|
||||
var styleQueues = reload.Vars(scriptQueue{})
|
||||
|
||||
type scriptQueue struct {
|
||||
Register map[string]struct{}
|
||||
Queue []string
|
||||
Args map[string]string
|
||||
queuedBeforeRegister map[string]string
|
||||
}
|
||||
|
||||
func EnqueueStyle(handle, src string, deps []string, ver, media string) {
|
||||
if media == "" {
|
||||
media = "all"
|
||||
}
|
||||
|
||||
h := strings.Split(handle, "?")
|
||||
if src != "" {
|
||||
AddScript(h[0], src, deps, ver, media)
|
||||
}
|
||||
enqueue(handle, style)
|
||||
}
|
||||
func EnqueueStyles(handle, src string, deps []string, ver, media string) {
|
||||
if src != "" {
|
||||
src = GetThemeFileUri(src)
|
||||
}
|
||||
EnqueueStyle(handle, src, deps, ver, media)
|
||||
}
|
||||
func EnqueueScript(handle, src string, deps []string, ver string, inFooter bool) {
|
||||
h := strings.Split(handle, "?")
|
||||
if src != "" {
|
||||
AddScript(h[0], src, deps, ver, nil)
|
||||
}
|
||||
if inFooter {
|
||||
AddScriptData(h[0], "group", "1")
|
||||
}
|
||||
enqueue(handle, script)
|
||||
}
|
||||
func EnqueueScripts(handle, src string, deps []string, ver string, inFooter bool) {
|
||||
if src != "" {
|
||||
src = GetThemeFileUri(src)
|
||||
}
|
||||
EnqueueScript(handle, src, deps, ver, inFooter)
|
||||
}
|
||||
|
||||
func enqueue(handle string, t int) {
|
||||
h := strings.Split(handle, "?")
|
||||
ss := styleQueues.Load()
|
||||
if t == 1 {
|
||||
ss = scriptQueues.Load()
|
||||
}
|
||||
if slice.IsContained(ss.Queue, h[0]) && maps.IsExists(ss.Register, h[0]) {
|
||||
ss.Queue = append(ss.Queue, h[0])
|
||||
} else if maps.IsExists(ss.Register, h[0]) {
|
||||
ss.queuedBeforeRegister[h[0]] = ""
|
||||
if len(h) > 1 {
|
||||
ss.queuedBeforeRegister[h[0]] = h[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func GetStylesheetUri() string {
|
||||
return GetThemeFileUri("/styles.css")
|
||||
}
|
||||
|
||||
func GetThemeFileUri(file string) string {
|
||||
return filepath.Join("/wp-content/themes", wpconfig.GetOption("template"), file)
|
||||
}
|
||||
|
||||
type Dependencies struct {
|
||||
Handle string `json:"handle,omitempty"`
|
||||
Src string `json:"src,omitempty"`
|
||||
Deps []string `json:"deps,omitempty"`
|
||||
Ver string `json:"ver,omitempty"`
|
||||
Args any `json:"args,omitempty"`
|
||||
Extra map[string][]string `json:"extra,omitempty"`
|
||||
Textdomain string `json:"textdomain,omitempty"`
|
||||
TranslationsPath string `json:"translations_path,omitempty"`
|
||||
}
|
||||
|
||||
func NewScript(handle string, src string, deps []string, ver string, args any) *Script {
|
||||
return &Script{Dependencies{Handle: handle, Src: src, Deps: deps, Ver: ver, Args: args}}
|
||||
}
|
||||
|
||||
func NewStyle(handle string, src string, deps []string, ver string, args any) *Style {
|
||||
return &Style{Dependencies{Handle: handle, Src: src, Deps: deps, Ver: ver, Args: args}}
|
||||
}
|
||||
|
||||
func AddDynamicData(h *wp.Handle, handle, key, data string) {
|
||||
da := helper.GetContextVal(h.C, "__scriptDynamicData__", map[string]map[string][]string{})
|
||||
m, ok := da[handle]
|
||||
if !ok {
|
||||
m = map[string][]string{}
|
||||
}
|
||||
m[key] = append(m[key], data)
|
||||
da[handle] = m
|
||||
}
|
||||
|
||||
func GetDynamicData(h *wp.Handle, handle, key string) string {
|
||||
da := helper.GetContextVal(h.C, "__scriptDynamicData__", map[string]map[string][]string{})
|
||||
if len(da) < 1 {
|
||||
return ""
|
||||
}
|
||||
m, ok := da[handle]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
mm, ok := m[key]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return strings.Join(mm, "\n")
|
||||
}
|
||||
|
||||
func SetTranslation(handle, domain, path string) {
|
||||
hh, ok := __scripts.Load(handle)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if !slice.IsContained(hh.Deps, handle) {
|
||||
hh.Deps = append(hh.Deps, "wp-i18n")
|
||||
}
|
||||
if domain == "" {
|
||||
domain = "default"
|
||||
}
|
||||
hh.Textdomain = domain
|
||||
hh.TranslationsPath = path
|
||||
}
|
||||
|
||||
func (item *__parseLoadItem) allDeps(handles []string, recursion bool, group int) bool {
|
||||
for _, handle := range handles {
|
||||
parts := strings.Split(handle, "?")
|
||||
queued := slice.IsContained(item.todo, parts[0])
|
||||
handle = parts[0]
|
||||
moved := item.setGroup(handle, group)
|
||||
if queued || !moved {
|
||||
continue
|
||||
}
|
||||
newGroup := item.groups[handle]
|
||||
keepGoing := true
|
||||
h, ok := __styles.Load(handle)
|
||||
if !ok {
|
||||
keepGoing = false
|
||||
}
|
||||
if len(h.Deps) > 0 && len(slice.Diff(h.Deps, __styles.Keys())) > 0 {
|
||||
keepGoing = false
|
||||
}
|
||||
if len(h.Deps) > 0 && item.allDeps(h.Deps, true, newGroup) {
|
||||
keepGoing = false
|
||||
}
|
||||
if !keepGoing {
|
||||
if recursion {
|
||||
return false
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if len(parts) > 1 {
|
||||
item.args[handle] = parts[1]
|
||||
}
|
||||
item.todo = append(item.todo, handle)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type __parseLoadItem struct {
|
||||
todo []string
|
||||
done []string
|
||||
groups map[string]int
|
||||
args map[string]string
|
||||
textDirection string
|
||||
concat string
|
||||
doConcat bool
|
||||
}
|
||||
|
||||
func newParseLoadItem() *__parseLoadItem {
|
||||
return &__parseLoadItem{
|
||||
groups: map[string]int{},
|
||||
}
|
||||
}
|
||||
|
||||
func (item *__parseLoadItem) setGroup(handle string, group int) bool {
|
||||
if v, ok := item.groups[handle]; ok && v <= group {
|
||||
return false
|
||||
}
|
||||
item.groups[handle] = group
|
||||
return true
|
||||
}
|
||||
|
||||
func DoStyleItems(h *wp.Handle, handles []string, group int) []string {
|
||||
item := newParseLoadItem()
|
||||
item.allDeps(handles, false, 0)
|
||||
for i, handle := range item.todo {
|
||||
_, ok := __styles.Load(handle)
|
||||
if !slice.IsContained(item.done, handle) && ok {
|
||||
if DoStyleItem(h, item, handle, group) {
|
||||
item.done = append(item.done, handle)
|
||||
}
|
||||
slice.Delete(&item.todo, i)
|
||||
}
|
||||
}
|
||||
return item.done
|
||||
}
|
||||
|
||||
func (s *Style) DoHeadItems() {
|
||||
|
||||
}
|
||||
func (s *Style) DoItems(handle string) {
|
||||
|
||||
}
|
||||
|
||||
func DoStyleItem(h *wp.Handle, item *__parseLoadItem, handle string, group int) bool {
|
||||
obj, _ := __styles.Load(handle)
|
||||
ver := obj.Ver
|
||||
if item.args[handle] != "" {
|
||||
str.Join(ver, "&", item.args[handle])
|
||||
}
|
||||
src := obj.Src
|
||||
var condBefore, condAfter, conditional, _ string
|
||||
if v, ok := obj.Extra["conditional"]; ok && v != nil {
|
||||
conditional = v[0]
|
||||
}
|
||||
if conditional != "" {
|
||||
condBefore = str.Join("<!==[if ", conditional, "]>\n")
|
||||
condAfter = "<![endif]-->\n"
|
||||
}
|
||||
inlineStyle := item.PrintInline(handle)
|
||||
if inlineStyle != "" {
|
||||
_ = fmt.Sprintf("<style id='%s-inline-css'%s>\n%s\n</style>\n", handle, "", inlineStyle)
|
||||
}
|
||||
href := item.CssHref(src, ver)
|
||||
ref := "stylesheet"
|
||||
if v, ok := obj.Extra["alt"]; ok && v != nil {
|
||||
ref = "alternate stylesheet"
|
||||
}
|
||||
title := ""
|
||||
if v, ok := obj.Extra["title"]; ok && v != nil {
|
||||
title = str.Join(" title='", v[len(v)-1], "'")
|
||||
}
|
||||
tag := fmt.Sprintf("<link rel='%s' id='%s-css'%s href='%s'%s media='%s' />\n", ref, handle, title, href, "", item.args)
|
||||
|
||||
if !item.doConcat {
|
||||
PrintStyle(h, condBefore, tag, PrintInlineStyles(handle), condAfter)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (item *__parseLoadItem) CssHref(src, ver string) string {
|
||||
if ver != "" {
|
||||
u, _ := url.Parse(src)
|
||||
v := u.Query()
|
||||
v.Set("ver", ver)
|
||||
u.RawQuery = v.Encode()
|
||||
src = u.String()
|
||||
}
|
||||
return src
|
||||
}
|
||||
|
||||
func (item *__parseLoadItem) PrintInline(handle string) string {
|
||||
sty, _ := __styles.Load(handle)
|
||||
out := sty.getData("after")
|
||||
if out == "" {
|
||||
return ""
|
||||
}
|
||||
s := str.NewBuilder()
|
||||
s.Sprintf("<style id='%s-inline-css'%s>\n%s\n</style>\n", handle)
|
||||
return s.String()
|
||||
}
|
1011
app/theme/wp/scriptloader/wtf.go
Normal file
1011
app/theme/wp/scriptloader/wtf.go
Normal file
File diff suppressed because it is too large
Load Diff
1605
app/theme/wp/scripts.json
Normal file
1605
app/theme/wp/scripts.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -9,7 +9,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
var sizes = []string{"site_icon-270", "site_icon-32", "site_icon-192", "site_icon-180"}
|
||||
var iconSizes = []string{"site_icon-270", "site_icon-32", "site_icon-192", "site_icon-180"}
|
||||
|
||||
func CalSiteIcon(h *Handle) (r string) {
|
||||
id := str.ToInteger[uint64](wpconfig.GetOption("site_icon"), 0)
|
||||
|
@ -21,7 +21,7 @@ func CalSiteIcon(h *Handle) (r string) {
|
|||
return
|
||||
}
|
||||
m := strings.Join(strings.Split(icon.AttachmentMetadata.File, "/")[:2], "/")
|
||||
size := slice.FilterAndMap(sizes, func(t string) (string, bool) {
|
||||
size := slice.FilterAndMap(iconSizes, func(t string) (string, bool) {
|
||||
s, ok := icon.AttachmentMetadata.Sizes[t]
|
||||
if !ok {
|
||||
return "", false
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package wp
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/constraints"
|
||||
|
@ -14,6 +15,7 @@ import (
|
|||
"html/template"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Handle struct {
|
||||
|
@ -41,6 +43,10 @@ type Handle struct {
|
|||
template *template.Template
|
||||
}
|
||||
|
||||
func (h *Handle) Theme() string {
|
||||
return h.theme
|
||||
}
|
||||
|
||||
func (h *Handle) GinH() gin.H {
|
||||
return h.ginH
|
||||
}
|
||||
|
@ -152,7 +158,7 @@ func (h *Handle) Err() error {
|
|||
}
|
||||
|
||||
func (h *Handle) SetErr(err error) {
|
||||
h.err = err
|
||||
h.err = errors.Join(err)
|
||||
}
|
||||
|
||||
func (h *Handle) SetTempl(templ string) {
|
||||
|
@ -281,3 +287,10 @@ func NewHandleFn(fn HandleFn[*Handle], order float64, name string) HandleCall {
|
|||
func NothingToDo(h *Handle) {
|
||||
h.Abort()
|
||||
}
|
||||
|
||||
func (h *Handle) IsHttps() bool {
|
||||
if h.C.Request.TLS != nil {
|
||||
return true
|
||||
}
|
||||
return "https" == strings.ToLower(h.C.Request.Header.Get("X-Forwarded-Proto"))
|
||||
}
|
||||
|
|
|
@ -2,11 +2,15 @@ package wpconfig
|
|||
|
||||
import (
|
||||
"context"
|
||||
"github.com/fthvgb1/wp-go/app/cmd/reload"
|
||||
"github.com/fthvgb1/wp-go/app/phphelper"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/models"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
"github.com/fthvgb1/wp-go/model"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -31,15 +35,43 @@ func InitOptions() error {
|
|||
for _, option := range ops {
|
||||
options.Store(option["k"], option["v"])
|
||||
}
|
||||
themeJson = reload.VarsBy(hasThemeJson)
|
||||
return nil
|
||||
}
|
||||
|
||||
var themeJson *safety.Var[bool]
|
||||
|
||||
func HasThemeJson() bool {
|
||||
if themeJson == nil {
|
||||
return false
|
||||
}
|
||||
return themeJson.Load()
|
||||
}
|
||||
|
||||
func hasThemeJson() bool {
|
||||
styleSheet := GetOption("stylesheet")
|
||||
rootDir := config.GetConfig().WpDir
|
||||
dir := filepath.Join(rootDir, "wp-content/themes", styleSheet, "theme.json")
|
||||
_, err := os.Stat(dir)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
template := GetOption("template")
|
||||
dir = filepath.Join(rootDir, "wp-content/themes", template, "theme.json")
|
||||
_, err = os.Stat(dir)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func GetOption(k string) string {
|
||||
v, ok := options.Load(k)
|
||||
if ok {
|
||||
return v
|
||||
}
|
||||
vv, err := model.GetField[models.Options](ctx, "option_value", model.Conditions(model.Where(model.SqlBuilder{{"option_name", k}})))
|
||||
vv, err := model.GetField[models.Options](ctx, "option_value", model.Conditions(
|
||||
model.Where(
|
||||
model.SqlBuilder{{"option_name", k}}),
|
||||
),
|
||||
)
|
||||
options.Store(k, vv)
|
||||
if err != nil {
|
||||
return ""
|
||||
|
|
32
go.mod
32
go.mod
|
@ -3,7 +3,7 @@ module github.com/fthvgb1/wp-go
|
|||
go 1.20
|
||||
|
||||
require (
|
||||
github.com/dlclark/regexp2 v1.7.0
|
||||
github.com/dlclark/regexp2 v1.10.0
|
||||
github.com/elliotchance/phpserialize v1.3.3
|
||||
github.com/gin-contrib/gzip v0.0.6
|
||||
github.com/gin-contrib/pprof v1.4.0
|
||||
|
@ -11,39 +11,39 @@ require (
|
|||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/go-playground/locales v0.14.1
|
||||
github.com/go-playground/universal-translator v0.18.1
|
||||
github.com/go-playground/validator/v10 v10.14.0
|
||||
github.com/go-sql-driver/mysql v1.6.0
|
||||
github.com/go-playground/validator/v10 v10.15.1
|
||||
github.com/go-sql-driver/mysql v1.7.1
|
||||
github.com/goccy/go-json v0.10.2
|
||||
github.com/jmoiron/sqlx v1.3.5
|
||||
github.com/soxfmr/gomail v0.0.0-20200806033254-80bf84e583f0
|
||||
golang.org/x/crypto v0.9.0
|
||||
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9
|
||||
golang.org/x/crypto v0.12.0
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.9.1 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
|
||||
github.com/bytedance/sonic v1.10.0 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gorilla/context v1.1.1 // indirect
|
||||
github.com/gorilla/securecookie v1.1.1 // indirect
|
||||
github.com/gorilla/sessions v1.2.1 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
|
||||
github.com/leodido/go-urn v1.2.4 // indirect
|
||||
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.11 // indirect
|
||||
golang.org/x/arch v0.3.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
golang.org/x/text v0.9.0 // indirect
|
||||
google.golang.org/protobuf v1.30.0 // indirect
|
||||
golang.org/x/arch v0.4.0 // indirect
|
||||
golang.org/x/net v0.14.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/text v0.12.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
|
||||
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
73
go.sum
73
go.sum
|
@ -1,15 +1,21 @@
|
|||
github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM=
|
||||
github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s=
|
||||
github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U=
|
||||
github.com/bytedance/sonic v1.10.0-rc/go.mod h1:ElCzW+ufi8qKqNW0FY314xriJhyJhuoJ3gFZdAHF7NM=
|
||||
github.com/bytedance/sonic v1.10.0-rc3 h1:uNSnscRapXTwUgTyOF0GVljYD08p9X/Lbr9MweSV3V0=
|
||||
github.com/bytedance/sonic v1.10.0-rc3/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/bytedance/sonic v1.10.0 h1:qtNZduETEIWJVIyDl01BeNxur2rW9OwTQ/yBqFRkKEk=
|
||||
github.com/bytedance/sonic v1.10.0/go.mod h1:iZcSUejdk5aukTND/Eu/ivjQuEL0Cu9/rf50Hi0u/g4=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311/go.mod h1:b583jCggY9gE99b6G5LEC39OIiVsWj+R97kbl5odCEk=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d h1:77cEq6EriyTZ0g/qfRdp61a3Uu/AWrgIq2s0ClJV1g0=
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d/go.mod h1:8EPpVsBuRksnlj1mLy4AWzRNQYxauNi62uWcE3to6eA=
|
||||
github.com/chenzhuoyu/iasm v0.9.0 h1:9fhXjVzq5hUy2gkhhgHl95zG2cEAhw9OSGs8toWWAwo=
|
||||
github.com/chenzhuoyu/iasm v0.9.0/go.mod h1:Xjy2NpN3h7aUqeqM+woSuuvxmIe6+DDsiNLIrkAmYog=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo=
|
||||
github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/dlclark/regexp2 v1.10.0 h1:+/GIL799phkJqYW+3YbOd8LCcbHzT0Pbo8zl70MHsq0=
|
||||
github.com/dlclark/regexp2 v1.10.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
|
||||
github.com/elliotchance/phpserialize v1.3.3 h1:hV4QVmGdCiYgoBbw+ADt6fNgyZ2mYX0OgpnON1adTCM=
|
||||
github.com/elliotchance/phpserialize v1.3.3/go.mod h1:gt7XX9+ETUcLXbtTKEuyrqW3lcLUAeS/AnGZ2e49TZs=
|
||||
github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU=
|
||||
|
@ -34,10 +40,13 @@ github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl
|
|||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||
github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos=
|
||||
github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js=
|
||||
github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-playground/validator/v10 v10.15.0 h1:nDU5XeOKtB3GEa+uB7GNYwhVKsgjAR7VgKoNB6ryXfw=
|
||||
github.com/go-playground/validator/v10 v10.15.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-playground/validator/v10 v10.15.1 h1:BSe8uhN+xQ4r5guV/ywQI4gO59C2raYcGffYWZEjZzM=
|
||||
github.com/go-playground/validator/v10 v10.15.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||
github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
|
@ -56,8 +65,9 @@ github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Cc
|
|||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk=
|
||||
github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
|
||||
|
@ -82,16 +92,14 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
|
|||
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
|
||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||
github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo=
|
||||
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
|
||||
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
|
||||
github.com/pelletier/go-toml/v2 v2.0.9 h1:uH2qQXheeefCCkuBBSLi7jCiSmj3VRh2+Goq2N7Xxu0=
|
||||
github.com/pelletier/go-toml/v2 v2.0.9/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
|
||||
github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
|
||||
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
|
||||
github.com/soxfmr/gomail v0.0.0-20200806033254-80bf84e583f0 h1:eVzIpz9oWTxss+/w5zHkUvCKNCt+1djBoTVlm2lgGQA=
|
||||
github.com/soxfmr/gomail v0.0.0-20200806033254-80bf84e583f0/go.mod h1:FInbtXuM/O1SXBIDwtDMgV8JDa4fHNoZ4QjItNNwA5g=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
|
@ -102,8 +110,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
|
||||
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
|
||||
|
@ -111,35 +119,37 @@ github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95
|
|||
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
|
||||
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k=
|
||||
golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc=
|
||||
golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g=
|
||||
golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0=
|
||||
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9 h1:frX3nT9RkKybPnjyI+yvZh6ZucTZatCCEm9D47sZ2zo=
|
||||
golang.org/x/exp v0.0.0-20230203172020-98cc5a0785f9/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
|
||||
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
|
||||
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de h1:l5Za6utMv/HsBWWqzt4S8X17j+kt1uVETUX5UFhn2rE=
|
||||
golang.org/x/exp v0.0.0-20230807204917-050eac23e9de/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ=
|
||||
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
|
||||
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
|
||||
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
|
||||
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk=
|
||||
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
@ -155,4 +165,5 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
|
|||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -120,3 +121,8 @@ func IsImplements[T, A any](i A) (T, bool) {
|
|||
t, ok := a.(T)
|
||||
return t, ok
|
||||
}
|
||||
|
||||
func FileExist(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package maps
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
"golang.org/x/exp/constraints"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func GetStrAnyVal[T any](m map[string]any, key string, delimiter ...string) (r T, o bool) {
|
||||
separator := "."
|
||||
|
@ -40,14 +44,14 @@ func GetStrAnyValWithDefaults[T any](m map[string]any, key string, defaults T) (
|
|||
}
|
||||
|
||||
// GetStrMapAnyValWithAny 使用"." 分隔层级
|
||||
func GetStrMapAnyValWithAny(key string, v map[string]any) (r any, o bool) {
|
||||
func GetStrMapAnyValWithAny(v map[string]any, key string) (r any, o bool) {
|
||||
k := strings.Split(key, ".")
|
||||
if len(k) > 1 {
|
||||
val, ok := v[k[0]]
|
||||
if ok {
|
||||
vx, ok := val.(map[string]any)
|
||||
if ok {
|
||||
r, o = GetStrMapAnyValWithAny(strings.Join(k[1:], "."), vx)
|
||||
r, o = GetStrMapAnyValWithAny(vx, strings.Join(k[1:], "."))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -111,7 +115,7 @@ func GetAnyAnyValWithDefaults[T any](m map[any]any, defaults T, key ...any) (r T
|
|||
return
|
||||
}
|
||||
|
||||
func RecursiveSetStrVal[T any](m map[string]any, k string, v T, delimiter ...string) {
|
||||
func SetStrAnyVal[T any](m map[string]any, k string, v T, delimiter ...string) {
|
||||
del := "."
|
||||
if len(delimiter) > 0 && delimiter[0] != "" {
|
||||
del = delimiter[0]
|
||||
|
@ -148,7 +152,7 @@ func RecursiveSetStrVal[T any](m map[string]any, k string, v T, delimiter ...str
|
|||
mx[kk[len(kk)-1]] = v
|
||||
}
|
||||
|
||||
func RecursiveSetAnyVal[T any](m map[any]any, v T, k ...any) {
|
||||
func SetAnyAnyVal[T any](m map[any]any, v T, k ...any) {
|
||||
if len(k) < 1 {
|
||||
return
|
||||
} else if len(k) == 1 {
|
||||
|
@ -162,10 +166,10 @@ func RecursiveSetAnyVal[T any](m map[any]any, v T, k ...any) {
|
|||
mm = map[any]any{}
|
||||
preKey := k[0:i]
|
||||
if len(preKey) == 0 {
|
||||
RecursiveSetAnyVal(m, mm, key...)
|
||||
SetAnyAnyVal(m, mm, key...)
|
||||
} else {
|
||||
m, _ := GetAnyAnyMapVal[map[any]any](m, preKey...)
|
||||
RecursiveSetAnyVal(m, mm, k[i])
|
||||
SetAnyAnyVal(m, mm, k[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,3 +177,26 @@ func RecursiveSetAnyVal[T any](m map[any]any, v T, k ...any) {
|
|||
mm, _ := GetAnyAnyMapVal[map[any]any](m, key...)
|
||||
mm[k[len(k)-1]] = v
|
||||
}
|
||||
|
||||
func AscEahByKey[K constraints.Ordered, V any](m map[K]V, fn func(K, V)) {
|
||||
orderedEahByKey(m, slice.ASC, fn)
|
||||
}
|
||||
func DescEahByKey[K constraints.Ordered, V any](m map[K]V, fn func(K, V)) {
|
||||
orderedEahByKey(m, slice.ASC, fn)
|
||||
}
|
||||
|
||||
func orderedEahByKey[K constraints.Ordered, V any](m map[K]V, ordered int, fn func(K, V)) {
|
||||
keys := Keys(m)
|
||||
slice.Sorts(keys, ordered)
|
||||
for _, key := range keys {
|
||||
fn(key, m[key])
|
||||
}
|
||||
}
|
||||
|
||||
func Flip[K, V comparable](m map[K]V) map[V]K {
|
||||
mm := make(map[V]K, len(m))
|
||||
for k, v := range m {
|
||||
mm[v] = k
|
||||
}
|
||||
return mm
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ func TestGetStrMapAnyValWithAny(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
gotR, gotO := GetStrMapAnyValWithAny(tt.args.key, tt.args.v)
|
||||
gotR, gotO := GetStrMapAnyValWithAny(tt.args.v, tt.args.key)
|
||||
if !reflect.DeepEqual(gotR, tt.wantR) {
|
||||
t.Errorf("GetStrMapAnyValWithAny() gotR = %v, want %v", gotR, tt.wantR)
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ func TestRecursiveSetAnyVal(t *testing.T) {
|
|||
target := map[any]any{"m": map[any]any{3: map[any]any{"key": 3.4}}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
RecursiveSetAnyVal(tt.args.m, tt.args.v, tt.args.k...)
|
||||
SetAnyAnyVal(tt.args.m, tt.args.v, tt.args.k...)
|
||||
if !reflect.DeepEqual(tt.args.m, target) {
|
||||
t.Fatalf("not equal target")
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ func TestRecursiveSetStrVal(t *testing.T) {
|
|||
target := map[string]any{"aa": map[string]any{"bb": map[string]any{"cc": 1}}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
RecursiveSetStrVal(tt.args.m, tt.args.k, tt.args.v)
|
||||
SetStrAnyVal(tt.args.m, tt.args.k, tt.args.v)
|
||||
if !reflect.DeepEqual(target, tt.args.m) {
|
||||
t.Fatal()
|
||||
}
|
||||
|
|
|
@ -106,3 +106,8 @@ func Counters[T constraints.Integer]() func() T {
|
|||
return count
|
||||
}
|
||||
}
|
||||
|
||||
func Round(f float64, precision int) float64 {
|
||||
p := math.Pow10(precision)
|
||||
return math.Floor(f*p+0.5) / p
|
||||
}
|
||||
|
|
|
@ -93,14 +93,20 @@ func Replace(s string, replace map[string]string) string {
|
|||
}
|
||||
return s
|
||||
}
|
||||
func Replaces(s string, replace [][]string) string {
|
||||
|
||||
// Replaces replace string by slice as order
|
||||
//
|
||||
// []string sub []string like {old1,old2,old3,....,newString} all old[x] will be replaced by lasted newString
|
||||
func Replaces(s string, replace ...[]string) string {
|
||||
for _, v := range replace {
|
||||
if len(v) < 1 {
|
||||
continue
|
||||
} else if len(v) == 1 {
|
||||
s = strings.ReplaceAll(s, v[0], "")
|
||||
} else {
|
||||
s = strings.ReplaceAll(s, v[0], v[1])
|
||||
for _, s2 := range v[0 : len(v)-1] {
|
||||
s = strings.ReplaceAll(s, s2, v[len(v)-1])
|
||||
}
|
||||
}
|
||||
}
|
||||
return s
|
||||
|
|
|
@ -82,6 +82,9 @@ func Scanner[T any](db *sqlx.DB, v T, s string, params ...any) func(func(T)) err
|
|||
|
||||
func ToMapSlice[V any](db *sqlx.DB, dest *[]map[string]V, sql string, params ...any) (err error) {
|
||||
rows, err := db.Query(sql, params...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
columns, err := rows.Columns()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -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() {
|
||||
m.misses++
|
||||
if m.misses < len(m.dirty) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user