From 8f995d23dc73695595d063ffa1775fe7f9b42730 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 13 May 2023 18:50:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=9D=E5=A4=96=E5=BC=95=E5=85=A5=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/theme/wp/template.gohtml | 3 +++ app/theme/wp/wp.go | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/theme/wp/template.gohtml b/app/theme/wp/template.gohtml index 95f915e..9f0cc1b 100644 --- a/app/theme/wp/template.gohtml +++ b/app/theme/wp/template.gohtml @@ -13,6 +13,9 @@ {{if .footerScript}} {{.footerScript|unescaped}} {{end}} + {{if .externFooter}} + {{.externFooter|unescaped}} + {{end}} {{end}} diff --git a/app/theme/wp/wp.go b/app/theme/wp/wp.go index 749adaf..c768bea 100644 --- a/app/theme/wp/wp.go +++ b/app/theme/wp/wp.go @@ -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,29 @@ 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) { + 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) {