2023-01-21 13:13:33 +00:00
package dao
2023-01-12 12:42:16 +00:00
import (
"context"
"fmt"
2023-01-21 13:13:33 +00:00
"github.com/fthvgb1/wp-go/internal/pkg/models"
2023-01-18 15:02:59 +00:00
"github.com/fthvgb1/wp-go/internal/wpconfig"
"github.com/fthvgb1/wp-go/model"
2023-01-12 12:42:16 +00:00
)
var TotalRaw int64
type PostIds struct {
Ids [ ] uint64
Length int
}
type PostContext struct {
2023-01-21 13:13:33 +00:00
Prev models . Posts
Next models . Posts
2023-01-12 12:42:16 +00:00
}
2023-01-21 13:13:33 +00:00
func PasswordProjectTitle ( post * models . Posts ) {
2023-01-12 12:42:16 +00:00
if post . PostPassword != "" {
post . PostTitle = fmt . Sprintf ( "密码保护:%s" , post . PostTitle )
}
}
2023-01-21 14:56:41 +00:00
func CategoriesAndTags ( a ... any ) ( terms [ ] models . TermsMy , err error ) {
2023-01-12 12:42:16 +00:00
ctx := a [ 0 ] . ( context . Context )
2023-01-21 14:56:41 +00:00
var in = [ ] any { "category" , "post_tag" }
2023-01-21 13:13:33 +00:00
terms , err = model . Find [ models . TermsMy ] ( ctx , model . SqlBuilder {
2023-01-12 12:42:16 +00:00
{ "tt.count" , ">" , "0" , "int" } ,
{ "tt.taxonomy" , "in" , "" } ,
} , "t.term_id" , "" , model . SqlBuilder {
{ "t.name" , "asc" } ,
} , model . SqlBuilder {
{ "t" , "inner join" , "wp_term_taxonomy tt" , "t.term_id = tt.term_id" } ,
} , nil , 0 , in )
for i := 0 ; i < len ( terms ) ; i ++ {
if v , ok := wpconfig . Terms . Load ( terms [ i ] . Terms . TermId ) ; ok {
terms [ i ] . Terms = v
}
if v , ok := wpconfig . TermTaxonomies . Load ( terms [ i ] . Terms . TermId ) ; ok {
terms [ i ] . TermTaxonomy = v
}
}
return
}
2023-01-21 13:13:33 +00:00
func Archives ( ctx context . Context ) ( [ ] models . PostArchive , error ) {
return model . Find [ models . PostArchive ] ( ctx , model . SqlBuilder {
2023-01-12 12:42:16 +00:00
{ "post_type" , "post" } , { "post_status" , "publish" } ,
} , "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts" , "year,month" , model . SqlBuilder { { "year" , "desc" } , { "month" , "desc" } } , nil , nil , 0 )
}