This commit is contained in:
xing 2023-02-09 17:12:33 +08:00
parent abfcc9b1ad
commit 55a9e90ec9
6 changed files with 77 additions and 23 deletions

View File

@ -63,3 +63,11 @@ func Copy[T any](a []T) []T {
copy(dst, a)
return dst
}
func Unshift[T any](a *[]T, e ...T) {
*a = append(e, *a...)
}
func Push[T any](a *[]T, e ...T) {
*a = append(*a, e...)
}

View File

@ -165,3 +165,57 @@ func TestCopy(t *testing.T) {
})
}
}
func TestUnshift(t *testing.T) {
type args[T int] struct {
a *[]T
e []T
}
type testCase[T int] struct {
name string
args args[T]
}
a := number.Range(1, 10, 1)
tests := []testCase[int]{
{
name: "t1",
args: args[int]{
a: &a,
e: number.Range(11, 15, 1),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Unshift(tt.args.a, tt.args.e...)
fmt.Println(tt.args.a)
})
}
}
func TestPush(t *testing.T) {
type args[T int] struct {
a *[]T
e []T
}
type testCase[T int] struct {
name string
args args[T]
}
a := number.Range(1, 10, 1)
tests := []testCase[int]{
{
name: "t1",
args: args[int]{
a: &a,
e: number.Range(11, 15, 1),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Push(tt.args.a, tt.args.e...)
fmt.Println(tt.args.a)
})
}
}

View File

@ -78,13 +78,18 @@ func Digest(next Fn[models.Posts], h Handle, post models.Posts) models.Posts {
return next(post)
}
func Digests(ctx context.Context) Fn[models.Posts] {
func DigestsAndOthers(ctx context.Context, calls ...func(*models.Posts)) Fn[models.Posts] {
return func(post models.Posts) models.Posts {
if post.PostExcerpt != "" {
plugins.PostExcerpt(&post)
} else {
plugins.Digest(ctx, &post, config.GetConfig().DigestWordCount)
}
if len(calls) > 0 {
for _, call := range calls {
call(&post)
}
}
return post
}
}

View File

@ -2,6 +2,7 @@ package theme
import (
"github.com/fthvgb1/wp-go/internal/theme/common"
"github.com/fthvgb1/wp-go/internal/theme/twentyfifteen"
)
var themeMap = map[string]func(handle common.Handle){}
@ -19,20 +20,5 @@ func Hook(themeName string, handle common.Handle) {
fn(handle)
return
}
/*if _, ok := plugins.IndexSceneMap[scene]; ok {
p, ok := h["pagination"]
if ok {
pp, ok := p.(pagination.ParsePagination)
if ok {
h["pagination"] = pagination.Paginate(plugins.TwentyFifteenPagination(), pp)
}
}
c.HTML(code, "twentyfifteen/posts/index.gohtml", h)
return
} else if scene == plugins.Detail {
h["comments"] = plugins.FormatComments(c, plugins.CommentRender(), h["comments"].([]models.Comments), h["maxDep"].(int))
c.HTML(code, "twentyfifteen/posts/detail.gohtml", h)
return
}
logs.ErrPrintln(errors.New("what happening"), " how reached here", themeName, code, h, scene, status)*/
themeMap[twentyfifteen.ThemeName](handle)
}

View File

@ -2,11 +2,13 @@ package theme
import (
"github.com/fthvgb1/wp-go/internal/pkg/config"
"github.com/fthvgb1/wp-go/internal/theme/twentyfifteen"
"github.com/fthvgb1/wp-go/internal/theme/twentyseventeen"
"github.com/fthvgb1/wp-go/internal/wpconfig"
)
func InitThemeAndTemplateFuncMap() {
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
}

View File

@ -31,9 +31,9 @@ type handle struct {
templ string
}
func Hook(h2 common.Handle) {
func Hook(cHandle common.Handle) {
h := handle{
Handle: h2,
Handle: cHandle,
templ: "twentyseventeen/posts/index.gohtml",
}
h.GinH["HeaderImage"] = h.getHeaderImage(h.C)
@ -57,7 +57,7 @@ func (h handle) Index() {
h.GinH["posts"] = slice.Map(
h.GinH["posts"].([]models.Posts),
common.PluginFn[models.Posts](plugin, h.Handle, common.Digests(h.C)))
common.PluginFn[models.Posts](plugin, h.Handle, common.DigestsAndOthers(h.C)))
p, ok := h.GinH["pagination"]
if ok {
@ -111,9 +111,8 @@ func (c comment) FormatLi(ctx *gin.Context, m models.Comments, depth int, isTls
func postThumbnail(next common.Fn[models.Posts], h common.Handle, t models.Posts) models.Posts {
if t.Thumbnail.Path != "" {
if slice.IsContained(h.Scene, []int{plugins.Home, plugins.Archive, plugins.Search}) {
t.Thumbnail.Sizes = "(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
} else {
t.Thumbnail.Sizes = "(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
if h.Scene == plugins.Detail {
t.Thumbnail.Sizes = "100vw"
}
}