优化
This commit is contained in:
parent
abfcc9b1ad
commit
55a9e90ec9
|
@ -63,3 +63,11 @@ func Copy[T any](a []T) []T {
|
||||||
copy(dst, a)
|
copy(dst, a)
|
||||||
return dst
|
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...)
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -78,13 +78,18 @@ func Digest(next Fn[models.Posts], h Handle, post models.Posts) models.Posts {
|
||||||
return next(post)
|
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 {
|
return func(post models.Posts) models.Posts {
|
||||||
if post.PostExcerpt != "" {
|
if post.PostExcerpt != "" {
|
||||||
plugins.PostExcerpt(&post)
|
plugins.PostExcerpt(&post)
|
||||||
} else {
|
} else {
|
||||||
plugins.Digest(ctx, &post, config.GetConfig().DigestWordCount)
|
plugins.Digest(ctx, &post, config.GetConfig().DigestWordCount)
|
||||||
}
|
}
|
||||||
|
if len(calls) > 0 {
|
||||||
|
for _, call := range calls {
|
||||||
|
call(&post)
|
||||||
|
}
|
||||||
|
}
|
||||||
return post
|
return post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package theme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fthvgb1/wp-go/internal/theme/common"
|
"github.com/fthvgb1/wp-go/internal/theme/common"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/theme/twentyfifteen"
|
||||||
)
|
)
|
||||||
|
|
||||||
var themeMap = map[string]func(handle common.Handle){}
|
var themeMap = map[string]func(handle common.Handle){}
|
||||||
|
@ -19,20 +20,5 @@ func Hook(themeName string, handle common.Handle) {
|
||||||
fn(handle)
|
fn(handle)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
/*if _, ok := plugins.IndexSceneMap[scene]; ok {
|
themeMap[twentyfifteen.ThemeName](handle)
|
||||||
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)*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,13 @@ package theme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
"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/theme/twentyseventeen"
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InitThemeAndTemplateFuncMap() {
|
func InitThemeAndTemplateFuncMap() {
|
||||||
|
addThemeHookFunc(twentyfifteen.ThemeName, twentyfifteen.Hook)
|
||||||
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
addThemeHookFunc(twentyseventeen.ThemeName, twentyseventeen.Hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ type handle struct {
|
||||||
templ string
|
templ string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Hook(h2 common.Handle) {
|
func Hook(cHandle common.Handle) {
|
||||||
h := handle{
|
h := handle{
|
||||||
Handle: h2,
|
Handle: cHandle,
|
||||||
templ: "twentyseventeen/posts/index.gohtml",
|
templ: "twentyseventeen/posts/index.gohtml",
|
||||||
}
|
}
|
||||||
h.GinH["HeaderImage"] = h.getHeaderImage(h.C)
|
h.GinH["HeaderImage"] = h.getHeaderImage(h.C)
|
||||||
|
@ -57,7 +57,7 @@ func (h handle) Index() {
|
||||||
|
|
||||||
h.GinH["posts"] = slice.Map(
|
h.GinH["posts"] = slice.Map(
|
||||||
h.GinH["posts"].([]models.Posts),
|
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"]
|
p, ok := h.GinH["pagination"]
|
||||||
if ok {
|
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 {
|
func postThumbnail(next common.Fn[models.Posts], h common.Handle, t models.Posts) models.Posts {
|
||||||
if t.Thumbnail.Path != "" {
|
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"
|
||||||
t.Thumbnail.Sizes = "(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px"
|
if h.Scene == plugins.Detail {
|
||||||
} else {
|
|
||||||
t.Thumbnail.Sizes = "100vw"
|
t.Thumbnail.Sizes = "100vw"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user