From ada0dcfa6c7e2070d809b396de72a8bccea5279c Mon Sep 17 00:00:00 2001 From: truthhun <1272881215@qq.com> Date: Wed, 18 Oct 2023 16:43:59 +0800 Subject: [PATCH] =?UTF-8?q?SEO=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/util.go | 2 +- service/serve.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/model/util.go b/model/util.go index da7d0ef..77cc46c 100644 --- a/model/util.go +++ b/model/util.go @@ -141,11 +141,11 @@ func (m *DBModel) InitSEO() { defaultTitle = "管理后台 - " } - m.logger.Debug("initSEO", zap.String("file", path), zap.String("title", defaultTitle)) bs, _ := os.ReadFile(path) if doc, errDoc := goquery.NewDocumentFromReader(bytes.NewReader(bs)); errDoc != nil { m.logger.Error("initSEO", zap.Error(errDoc), zap.String("file", path)) } else { + m.logger.Debug("initSEO", zap.String("file", path), zap.String("title", defaultTitle+cfg.Sitename)) doc.Find("title").SetText(defaultTitle + cfg.Sitename) doc.Find("meta[name='keywords']").SetAttr("content", cfg.Keywords) doc.Find("meta[name='description']").SetAttr("content", cfg.Description) diff --git a/service/serve.go b/service/serve.go index c0532e1..4679d04 100644 --- a/service/serve.go +++ b/service/serve.go @@ -58,6 +58,9 @@ func Run(cfg *conf.Config, logger *zap.Logger) { return } + // 每次启动时,都对dist中的title进行一次处理,以替换掉关键字 moredoc + go dbModel.InitSEO() + if cfg.Level != "debug" { gin.SetMode(gin.ReleaseMode) }