From a313210f7178e846a081c6f4bb6f1ccb5ce01618 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 14 Mar 2023 13:50:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- helper/func.go | 4 +- helper/func_test.go | 18 ++++ .../theme/twentyfifteen/custombackground.go | 2 +- .../theme/twentyfifteen/layout/sidebar.gohtml | 14 --- .../theme/wp/components/widget/category.go | 89 +++++++++++++++++++ .../theme/wp/components/widgetareadata.go | 1 + 7 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 internal/theme/wp/components/widget/category.go diff --git a/README.md b/README.md index de05bab..956ca99 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## wp-go -一个go写的WordPress的前端,功能比较简单,只有列表页和详情页,rss2,主题只有twentyfifteen和twentyseventeen两套主题,插件的话只有一个简单的列表页的摘要生成和enlighter代码高亮。本身只用于展示文章及评论。因为大量用了泛型功能,所以要求go的版本在1.19及以上,越新越好。。。 +一个go写的WordPress的前端,功能比较简单,只有列表页和详情页,rss2,主题只有twentyfifteen和twentyseventeen两套主题,插件的话只有一个简单的列表页的摘要生成和enlighter代码高亮。本身只用于展示文章及评论。要求go的版本在1.20以上,越新越好。。。 #### 特色功能 diff --git a/helper/func.go b/helper/func.go index be8370d..043d86a 100644 --- a/helper/func.go +++ b/helper/func.go @@ -70,7 +70,7 @@ func IsZeros(v any) bool { switch v.(type) { case int64, int, int8, int16, int32, uint64, uint, uint8, uint16, uint32: i := fmt.Sprintf("%d", v) - return str.ToInt[int](i) == 0 + return str.ToInt[int64](i) == 0 case float32, float64: f := fmt.Sprintf("%v", v) ff, _ := strconv.ParseFloat(f, 64) @@ -81,7 +81,7 @@ func IsZeros(v any) bool { s := v.(string) return s == "" } - return false + return reflect.DeepEqual(v, reflect.Zero(reflect.TypeOf(v)).Interface()) } func ToBool[T comparable](t T) bool { diff --git a/helper/func_test.go b/helper/func_test.go index b718244..dc336b3 100644 --- a/helper/func_test.go +++ b/helper/func_test.go @@ -217,3 +217,21 @@ func TestToBool(t *testing.T) { }) } } + +func TestIsZeros(t *testing.T) { + tt := struct { + name string + args struct { + v struct{ a string } + } + want bool + }{ + name: "t1", + args: struct{ v struct{ a string } }{v: struct{ a string }{a: ""}}, + } + t.Run(tt.name, func(t *testing.T) { + if got := IsZeros(tt.args.v); got != tt.want { + t.Errorf("IsZeros() = %v, want %v", got, tt.want) + } + }) +} diff --git a/internal/theme/twentyfifteen/custombackground.go b/internal/theme/twentyfifteen/custombackground.go index 463c987..86e1471 100644 --- a/internal/theme/twentyfifteen/custombackground.go +++ b/internal/theme/twentyfifteen/custombackground.go @@ -32,7 +32,7 @@ var repeat = map[string]string{ func CalCustomBackGround(h *wp.Handle) (r string) { themeMods := h.CommonThemeMods() - if themeMods.BackgroundImage == "" && themeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor { + if themeMods.BackgroundImage == "" && (themeMods.BackgroundColor == "" || themeMods.BackgroundColor == themesupport.CustomBackground.DefaultColor) { return } s := str.NewBuilder() diff --git a/internal/theme/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml index 02bad3c..7250873 100644 --- a/internal/theme/twentyfifteen/layout/sidebar.gohtml +++ b/internal/theme/twentyfifteen/layout/sidebar.gohtml @@ -1,20 +1,6 @@ {{define "layout/sidebar" }}