diff --git a/server/bbs-go.docker.yaml b/server/bbs-go.docker.yaml index dcb91615..70cb676d 100644 --- a/server/bbs-go.docker.yaml +++ b/server/bbs-go.docker.yaml @@ -1,6 +1,5 @@ Port: 8082 # 端口 BaseUrl: http://127.0.0.1:3000 # 网站域名 -StaticPath: /data/www # 根路径下的静态文件目录,可配置绝对路径 IpDataPath: # IP数据文件,默认读取当前目录下ip2region.xdb文件,最新数据文件请从这里下载:https://github.com/lionsoul2014/ip2region/tree/master/data AllowedOrigins: - "*" diff --git a/server/bbs-go.example.yaml b/server/bbs-go.example.yaml index bf761378..d5e637f0 100644 --- a/server/bbs-go.example.yaml +++ b/server/bbs-go.example.yaml @@ -1,6 +1,5 @@ Port: 8082 # 端口 BaseUrl: https://mlog.club # 网站域名 -StaticPath: /data/www # 根路径下的静态文件目录,可配置绝对路径 IpDataPath: # IP数据文件,默认读取当前目录下ip2region.xdb文件,最新数据文件请从这里下载:https://github.com/lionsoul2014/ip2region/tree/master/data AllowedOrigins: - "*" diff --git a/server/go.mod b/server/go.mod index 6b1a69f5..395ccb3e 100644 --- a/server/go.mod +++ b/server/go.mod @@ -12,7 +12,6 @@ require ( github.com/go-resty/resty/v2 v2.11.0 github.com/goburrow/cache v0.1.4 github.com/golang-jwt/jwt/v4 v4.5.0 - github.com/gorilla/feeds v1.1.2 github.com/ikeikeikeike/go-sitemap-generator/v2 v2.0.2 github.com/iris-contrib/middleware/cors v0.0.0-20240111010557-e34016a4d6ee github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible diff --git a/server/go.sum b/server/go.sum index a115500e..728b01a6 100644 --- a/server/go.sum +++ b/server/go.sum @@ -132,8 +132,6 @@ github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25d github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k= github.com/gorilla/css v1.0.1 h1:ntNaBIghp6JmvWnxbZKANoLyuXTPZ4cAMlo6RyhlbO8= github.com/gorilla/css v1.0.1/go.mod h1:BvnYkspnSzMmwRK+b8/xgNPLiIuNZr6vbZBTPQ2A3b0= -github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw= -github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y= github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= diff --git a/server/internal/pkg/config/config.go b/server/internal/pkg/config/config.go index f3a086ad..d699ffbd 100644 --- a/server/internal/pkg/config/config.go +++ b/server/internal/pkg/config/config.go @@ -12,7 +12,6 @@ type Config struct { Env string // 环境 BaseUrl string // base url Port string // 端口 - StaticPath string // 静态文件目录 IpDataPath string // IP数据文件 // 日志配置 diff --git a/server/internal/scheduler/cron.go b/server/internal/scheduler/cron.go index dbb97017..7353a9f9 100644 --- a/server/internal/scheduler/cron.go +++ b/server/internal/scheduler/cron.go @@ -1,35 +1,24 @@ package scheduler import ( + "bbs-go/internal/pkg/sitemap" "log/slog" "github.com/robfig/cron/v3" - - "bbs-go/internal/services" ) func Start() { c := cron.New() - // Generate RSS - addCronFunc(c, "@every 30m", func() { - services.ArticleService.GenerateRss() - services.TopicService.GenerateRss() + addCronFunc(c, "0 4 ? * *", func() { + sitemap.Generate() }) - // // Generate sitemap - // addCronFunc(c, "0 4 ? * *", func() { - // sitemap.Generate() - // }) - c.Start() } func addCronFunc(c *cron.Cron, sepc string, cmd func()) { - _, err := c.AddFunc(sepc, cmd) - if err != nil { + if _, err := c.AddFunc(sepc, cmd); err != nil { slog.Error("add cron func error", slog.Any("err", err)) - } else { - // slog.Info("add cron func", slog.Any("entryId", entryId)) } } diff --git a/server/internal/services/article_service.go b/server/internal/services/article_service.go index f3443f66..9c94d6b7 100644 --- a/server/internal/services/article_service.go +++ b/server/internal/services/article_service.go @@ -5,19 +5,13 @@ import ( "bbs-go/internal/pkg/bbsurls" "bbs-go/internal/pkg/seo" "errors" - "log/slog" "math" - "path" "strings" - "time" "bbs-go/internal/cache" - "bbs-go/internal/pkg/config" "bbs-go/internal/repositories" - "github.com/gorilla/feeds" "github.com/mlogclub/simple/common/dates" - "github.com/mlogclub/simple/common/files" "github.com/mlogclub/simple/common/jsons" "github.com/mlogclub/simple/common/strs" "github.com/mlogclub/simple/sqls" @@ -27,7 +21,6 @@ import ( "gorm.io/gorm" "bbs-go/internal/models" - "bbs-go/internal/pkg/common" ) var ArticleService = newArticleService() @@ -268,54 +261,6 @@ func (s *articleService) ScanByUser(userId int64, callback func(articles []model } } -// rss -func (s *articleService) GenerateRss() { - articles := repositories.ArticleRepository.Find(sqls.DB(), - sqls.NewCnd().Where("status = ?", constants.StatusOk).Desc("id").Limit(200)) - - var items []*feeds.Item - for _, article := range articles { - articleUrl := bbsurls.ArticleUrl(article.Id) - user := cache.UserCache.Get(article.UserId) - if user == nil { - continue - } - description := common.GetSummary(article.ContentType, article.Content) - item := &feeds.Item{ - Title: article.Title, - Link: &feeds.Link{Href: articleUrl}, - Description: description, - Author: &feeds.Author{Name: user.Avatar, Email: user.Email.String}, - Created: dates.FromTimestamp(article.CreateTime), - } - items = append(items, item) - } - - siteTitle := cache.SysConfigCache.GetValue(constants.SysConfigSiteTitle) - siteDescription := cache.SysConfigCache.GetValue(constants.SysConfigSiteDescription) - feed := &feeds.Feed{ - Title: siteTitle, - Link: &feeds.Link{Href: config.Instance.BaseUrl}, - Description: siteDescription, - Author: &feeds.Author{Name: siteTitle}, - Created: time.Now(), - Items: items, - } - atom, err := feed.ToAtom() - if err != nil { - slog.Error(err.Error(), slog.Any("err", err)) - } else { - _ = files.WriteString(path.Join(config.Instance.StaticPath, "atom.xml"), atom, false) - } - - rss, err := feed.ToRss() - if err != nil { - slog.Error(err.Error(), slog.Any("err", err)) - } else { - _ = files.WriteString(path.Join(config.Instance.StaticPath, "rss.xml"), rss, false) - } -} - // 浏览数+1 func (s *articleService) IncrViewCount(articleId int64) { sqls.DB().Exec("update t_article set view_count = view_count + 1 where id = ?", articleId) diff --git a/server/internal/services/topic_service.go b/server/internal/services/topic_service.go index a69a8fec..048c5227 100644 --- a/server/internal/services/topic_service.go +++ b/server/internal/services/topic_service.go @@ -2,29 +2,21 @@ package services import ( "bbs-go/internal/models/constants" - "bbs-go/internal/pkg/bbsurls" - "bbs-go/internal/pkg/config" "bbs-go/internal/pkg/event" "bbs-go/internal/pkg/search" "errors" - "log/slog" "math" "net/http" - "path" - "time" "github.com/mlogclub/simple/common/dates" - "github.com/mlogclub/simple/common/files" "github.com/mlogclub/simple/common/strs" "github.com/mlogclub/simple/sqls" "github.com/mlogclub/simple/web/params" - "github.com/gorilla/feeds" "gorm.io/gorm" "bbs-go/internal/cache" "bbs-go/internal/models" - "bbs-go/internal/pkg/common" "bbs-go/internal/repositories" ) @@ -350,52 +342,6 @@ func (s *topicService) onComment(tx *gorm.DB, topicId int64, comment *models.Com return nil } -// rss -func (s *topicService) GenerateRss() { - topics := repositories.TopicRepository.Find(sqls.DB(), - sqls.NewCnd().Where("status = ?", constants.StatusOk).Desc("id").Limit(200)) - - var items []*feeds.Item - for _, topic := range topics { - topicUrl := bbsurls.TopicUrl(topic.Id) - user := cache.UserCache.Get(topic.UserId) - if user == nil { - continue - } - item := &feeds.Item{ - Title: topic.Title, - Link: &feeds.Link{Href: topicUrl}, - Description: common.GetMarkdownSummary(topic.Content), - Author: &feeds.Author{Name: user.Avatar, Email: user.Email.String}, - Created: dates.FromTimestamp(topic.CreateTime), - } - items = append(items, item) - } - siteTitle := cache.SysConfigCache.GetValue(constants.SysConfigSiteTitle) - siteDescription := cache.SysConfigCache.GetValue(constants.SysConfigSiteDescription) - feed := &feeds.Feed{ - Title: siteTitle, - Link: &feeds.Link{Href: config.Instance.BaseUrl}, - Description: siteDescription, - Author: &feeds.Author{Name: siteTitle}, - Created: time.Now(), - Items: items, - } - atom, err := feed.ToAtom() - if err != nil { - slog.Error(err.Error(), slog.Any("err", err)) - } else { - _ = files.WriteString(path.Join(config.Instance.StaticPath, "topic_atom.xml"), atom, false) - } - - rss, err := feed.ToRss() - if err != nil { - slog.Error(err.Error(), slog.Any("err", err)) - } else { - _ = files.WriteString(path.Join(config.Instance.StaticPath, "topic_rss.xml"), rss, false) - } -} - func (s *topicService) ScanByUser(userId int64, callback func(topics []models.Topic)) { var cursor int64 = 0 for {