Compare commits

...

3 Commits

Author SHA1 Message Date
a6ee333232 完善 2023-05-13 18:52:19 +08:00
1353541c94 配置 2023-05-13 18:51:49 +08:00
8f995d23dc 额外引入脚本 2023-05-13 18:50:10 +08:00
3 changed files with 34 additions and 1 deletions

View File

@ -13,6 +13,9 @@
{{if .footerScript}}
{{.footerScript|unescaped}}
{{end}}
{{if .externFooter}}
{{.externFooter|unescaped}}
{{end}}
{{end}}

View File

@ -2,6 +2,7 @@ package wp
import (
"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/plugins/wphandle/apply"
@ -12,6 +13,7 @@ import (
"github.com/gin-gonic/gin"
"html/template"
"net/http"
"os"
)
type Handle struct {
@ -239,6 +241,32 @@ func (h *Handle) CommonComponents() {
h.PushCacheGroupHeadScript(constraints.AllScene, "siteIconAndCustomCss", 0, CalSiteIcon, CalCustomCss)
h.PushRender(constraints.AllStats, NewHandleFn(CalComponents, 10, "wp.CalComponents"))
h.PushRender(constraints.AllStats, NewHandleFn(PreRenderTemplate, 0, "wp.PreRenderTemplate"))
AdditionScript(h)
}
func AdditionScript(h *Handle) {
s := config.GetConfig().ExternScript
if len(s) < 1 {
return
}
fn := func(f, name string) {
if f == "" {
return
}
ss, err := os.ReadFile(f)
if err != nil {
logs.Error(err, str.Join("解析", name, "失败"), f)
} else {
h.PushComponents(constraints.AllScene, constraints.HeadScript, NewComponent(name, string(ss), false, 0, nil))
}
}
switch len(s) {
case 1:
fn(s[0], "externHead")
case 2:
fn(s[0], "externHead")
fn(s[1], "externFooter")
}
}
func PreRenderTemplate(h *Handle) {

View File

@ -98,3 +98,5 @@ plugins: ["enlightjs"]
pluginPath: "./plugins"
# 列表页面post使用的插件
listPagePlugins: ["digest"]
# 额外引入的脚本 第一个为head 第二个为footer
externScript: ["",""]