Skip to content

Commit

Permalink
移除RSS
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbbbbbbbbbbba committed Jun 2, 2024
1 parent 46e44e8 commit 088cdf6
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 130 deletions.
1 change: 0 additions & 1 deletion server/bbs-go.docker.yaml
Original file line number Diff line number Diff line change
@@ -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:
- "*"
Expand Down
1 change: 0 additions & 1 deletion server/bbs-go.example.yaml
Original file line number Diff line number Diff line change
@@ -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:
- "*"
Expand Down
1 change: 0 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 0 additions & 1 deletion server/internal/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type Config struct {
Env string // 环境
BaseUrl string // base url
Port string // 端口
StaticPath string // 静态文件目录
IpDataPath string // IP数据文件

// 日志配置
Expand Down
19 changes: 4 additions & 15 deletions server/internal/scheduler/cron.go
Original file line number Diff line number Diff line change
@@ -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))
}
}
55 changes: 0 additions & 55 deletions server/internal/services/article_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,7 +21,6 @@ import (
"gorm.io/gorm"

"bbs-go/internal/models"
"bbs-go/internal/pkg/common"
)

var ArticleService = newArticleService()
Expand Down Expand Up @@ -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)
Expand Down
54 changes: 0 additions & 54 deletions server/internal/services/topic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 088cdf6

Please sign in to comment.