Browse Source

fix bug

master
Collapseyu 3 months ago
parent
commit
ef5d302c96
  1. 13
      api/pkg/post/post.go
  2. 3
      api/pkg/tag/main.go
  3. 9
      api/post.go
  4. 11
      api/rss.go
  5. 4
      api/sitemap.go
  6. 2
      api/tags.go
  7. 2
      cron/baidupush.go

13
api/pkg/post/post.go

@ -6,6 +6,7 @@ import ( @@ -6,6 +6,7 @@ import (
"strings"
"github.com/OhYee/blotter/api/pkg/markdown"
"github.com/OhYee/blotter/api/pkg/tag"
"github.com/OhYee/blotter/mongo"
"github.com/OhYee/blotter/output"
fp "github.com/OhYee/goutils/functional"
@ -235,9 +236,19 @@ func GetCardPosts( @@ -235,9 +236,19 @@ func GetCardPosts(
withTags []string, withoutTags []string,
sortField string, sortType int,
searchWord string, searchFields []string,
hidden bool,
) (total int64, posts []CardField, err error) {
postsDB := make([]CardField, 0)
if hidden {
var hidden_tags []tag.Type
hidden_tags, err = tag.GetHidden()
if err != nil {
return
}
for _, tag := range hidden_tags {
withoutTags = append(withoutTags, tag.ID)
}
}
total, err = getPosts(2, offset, number, withTags, withoutTags, sortField, sortType, searchWord, searchFields, &postsDB)
posts = make([]CardField, len(postsDB))

3
api/pkg/tag/main.go

@ -192,12 +192,13 @@ func Get(short string) (tag Type, err error) { @@ -192,12 +192,13 @@ func Get(short string) (tag Type, err error) {
// Get tag that should be hidden
func GetHidden() (tags []Type, err error) {
tags = make([]Type, 0)
_, err = mongo.Find("blotter", "tags", bson.M{
"hide": true,
}, nil, &tags)
if err != nil {
err = errors.NewErr(err)
return
}
return tags, nil

9
api/post.go

@ -4,7 +4,6 @@ import ( @@ -4,7 +4,6 @@ import (
"strings"
"github.com/OhYee/blotter/api/pkg/post"
"github.com/OhYee/blotter/api/pkg/tag"
"github.com/OhYee/blotter/register"
)
@ -78,18 +77,12 @@ func Posts(context register.HandleContext) (err error) { @@ -78,18 +77,12 @@ func Posts(context register.HandleContext) (err error) {
res := new(PostsResponse)
context.RequestArgs(args)
withoutTags := strings.Split(args.WithoutTags, ",")
hidden_tags, err := tag.GetHidden()
if err != nil {
return
}
for _, tag := range hidden_tags {
withoutTags = append(withoutTags, tag.ID)
}
res.Total, res.Posts, err = post.GetCardPosts(
args.Offset, args.Number,
strings.Split(args.WithTags, ","), withoutTags,
args.SortField, args.SortType,
args.Search, strings.Split(args.SearchFields, ","),
true,
)
context.ReturnJSON(res)
return

11
api/rss.go

@ -6,7 +6,6 @@ import ( @@ -6,7 +6,6 @@ import (
"time"
"github.com/OhYee/blotter/api/pkg/post"
"github.com/OhYee/blotter/api/pkg/tag"
"github.com/OhYee/blotter/api/pkg/variable"
"github.com/OhYee/blotter/register"
)
@ -47,14 +46,8 @@ func RSSXML(context register.HandleContext) (err error) { @@ -47,14 +46,8 @@ func RSSXML(context register.HandleContext) (err error) {
blogName, _ := variables.GetString("blog_name")
author, _ := variables.GetString("author")
withoutTags := []string{}
hidden_tags, err := tag.GetHidden()
if err != nil {
return
}
for _, tag := range hidden_tags {
withoutTags = append(withoutTags, tag.ID)
}
total, posts, err := post.GetCardPosts(0, 0, []string{}, withoutTags, "", 0, "", []string{})
total, posts, err := post.GetCardPosts(0, 0, []string{}, withoutTags, "", 0, "", []string{}, true)
if err != nil {
return

4
api/sitemap.go

@ -16,7 +16,7 @@ func SitemapTXT(context register.HandleContext) (err error) { @@ -16,7 +16,7 @@ func SitemapTXT(context register.HandleContext) (err error) {
return
}
root, _ := variables.GetString("root")
total, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{})
total, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{}, true)
if err != nil {
return
}
@ -37,7 +37,7 @@ func SitemapXML(context register.HandleContext) (err error) { @@ -37,7 +37,7 @@ func SitemapXML(context register.HandleContext) (err error) {
return
}
root, _ := variables.GetString("root")
total, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{})
total, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{}, true)
if err != nil {
return
}

2
api/tags.go

@ -177,7 +177,7 @@ func Tag(context register.HandleContext) (err error) { @@ -177,7 +177,7 @@ func Tag(context register.HandleContext) (err error) {
if res.Total, res.Posts, err = post.GetCardPosts(
args.Offset, args.Number,
[]string{res.Tag.ID}, []string{},
"", -1, "", []string{},
"", -1, "", []string{}, false,
); err != nil {
return
}

2
cron/baidupush.go

@ -31,7 +31,7 @@ func BaiduPush() { @@ -31,7 +31,7 @@ func BaiduPush() {
// 生成链接文件
buf := bytes.NewBufferString("")
_, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{})
_, posts, err := post.GetCardPosts(0, 0, []string{}, []string{}, "", 0, "", []string{}, true)
if err != nil {
return
}

Loading…
Cancel
Save