diff --git a/README.md b/README.md index 7c3b3f2..5773891 100644 --- a/README.md +++ b/README.md @@ -23,10 +23,20 @@ |-----|--------------------------------------------| | 列表页 | 首页/搜索/归档/分类/标签/作者 分页列表 | | 详情页 | 显示内容、评论并可以添加评论(转发的php处理,需要配置php版的添加评论的url) | -| 侧边栏 | 目前固定 近期文章、近期评论、规档、分类、条目/评论feed | +| 侧边栏 | 目前支持旧版小工具的 近期文章、近期评论、规档、分类、其它操作 显示及设置 | #### 后台设置支持程度 +- 仪表盘 + - 外观 + - 小工具 + - 搜索 + - 规档 + - 近期文章 + - 近期评论 + - 分类 + - 其它操作 + - 设置- - 常规 - 站点标题 @@ -55,7 +65,7 @@ | 列表页文章数据插件 | 整个程序表现的插件 | |----------------------|--------------------------------------| | passwordProject 密码保护 | enlighter 代码高亮(需要在后台安装enlighterjs插件) | -| digest 自动生成指定长度的摘要 | | +| digest 自动生成指定长度的摘要 | hiddenLogin 隐藏登录入口 | #### 其它 diff --git a/internal/pkg/constraints/widgets/constraints.go b/internal/pkg/constraints/widgets/constraints.go index 37794b3..93f67e7 100644 --- a/internal/pkg/constraints/widgets/constraints.go +++ b/internal/pkg/constraints/widgets/constraints.go @@ -1,9 +1,10 @@ package widgets const ( - SearchFormArgs = "SearchFormArgs" - RecentPostsArgs = "RecentPostsArgs" - RecentCommentsArgs = "RecentCommentsArgs" - ArchiveArgs = "ArchiveArgs" - Categories = "Categories" + Search = "search" + RecentPosts = "recent-posts" + RecentComments = "recent-comments" + Archive = "archives" + Categories = "categories" + Meta = "meta" ) diff --git a/internal/plugins/wphandle/handle.go b/internal/plugins/wphandle/handle.go index c19afee..4ff447d 100644 --- a/internal/plugins/wphandle/handle.go +++ b/internal/plugins/wphandle/handle.go @@ -3,11 +3,13 @@ package wphandle import ( "github.com/fthvgb1/wp-go/helper/maps" "github.com/fthvgb1/wp-go/internal/plugins/wphandle/enlightjs" + "github.com/fthvgb1/wp-go/internal/plugins/wphandle/hiddenlogin" "github.com/fthvgb1/wp-go/internal/theme/wp" ) var plugins = wp.HandlePlugins{ - "enlightjs": enlightjs.EnlighterJS, + "enlightjs": enlightjs.EnlighterJS, + "hiddenLogin": hiddenlogin.HiddenLogin, } func Plugins() wp.HandlePlugins { diff --git a/internal/plugins/wphandle/hiddenlogin/hiddenlogin.go b/internal/plugins/wphandle/hiddenlogin/hiddenlogin.go new file mode 100644 index 0000000..858dbd8 --- /dev/null +++ b/internal/plugins/wphandle/hiddenlogin/hiddenlogin.go @@ -0,0 +1,17 @@ +package hiddenlogin + +import ( + str "github.com/fthvgb1/wp-go/helper/strings" + "github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets" + "github.com/fthvgb1/wp-go/internal/theme/wp" +) + +func HiddenLogin(h *wp.Handle) { + h.PushComponentFilterFn(widgets.Meta, func(h *wp.Handle, s string) string { + return str.Replace(s, map[string]string{ + `
  • 登录
  • `: "", + `
  • 登录
  • `: "", + `
  • 登录
  • `: "", + }) + }) +} diff --git a/internal/theme/twentyfifteen/layout/sidebar.gohtml b/internal/theme/twentyfifteen/layout/sidebar.gohtml index 7250873..5e71ecb 100644 --- a/internal/theme/twentyfifteen/layout/sidebar.gohtml +++ b/internal/theme/twentyfifteen/layout/sidebar.gohtml @@ -1,14 +1,5 @@ {{define "layout/sidebar" }} {{end}} \ No newline at end of file diff --git a/internal/theme/twentyfifteen/twentyfifteen.go b/internal/theme/twentyfifteen/twentyfifteen.go index 58b922a..95dd7bc 100644 --- a/internal/theme/twentyfifteen/twentyfifteen.go +++ b/internal/theme/twentyfifteen/twentyfifteen.go @@ -43,7 +43,7 @@ func Hook(h *wp.Handle) { func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) { components.WidgetArea(h) h.GetPassword() - h.PushComponentFilterFn(widgets.SearchFormArgs, func(h *wp.Handle, s string) string { + h.PushComponentFilterFn(widgets.Search, func(h *wp.Handle, s string) string { return strings.ReplaceAll(s, `class="search-submit"`, `class="search-submit screen-reader-text"`) }) wphandle.RegisterPlugins(h, config.GetConfig().Plugins...) diff --git a/internal/theme/twentyseventeen/layout/sidebar.gohtml b/internal/theme/twentyseventeen/layout/sidebar.gohtml index 37b69ba..fe1c43a 100644 --- a/internal/theme/twentyseventeen/layout/sidebar.gohtml +++ b/internal/theme/twentyseventeen/layout/sidebar.gohtml @@ -1,25 +1,3 @@ {{define "layout/sidebar" }} {{template "common/sidebarWidget" .}} -
    -

    分类

    - -
    -
    -

    其他操作

    - -
    {{end}} \ No newline at end of file diff --git a/internal/theme/twentyseventeen/twentyseventeen.go b/internal/theme/twentyseventeen/twentyseventeen.go index d350eb6..27dc739 100644 --- a/internal/theme/twentyseventeen/twentyseventeen.go +++ b/internal/theme/twentyseventeen/twentyseventeen.go @@ -10,6 +10,7 @@ import ( "github.com/fthvgb1/wp-go/internal/cmd/reload" "github.com/fthvgb1/wp-go/internal/pkg/config" "github.com/fthvgb1/wp-go/internal/pkg/constraints" + "github.com/fthvgb1/wp-go/internal/pkg/constraints/widgets" "github.com/fthvgb1/wp-go/internal/pkg/logs" "github.com/fthvgb1/wp-go/internal/pkg/models" "github.com/fthvgb1/wp-go/internal/plugins" @@ -61,9 +62,29 @@ func ready(next wp.HandleFn[*wp.Handle], h *wp.Handle) { pushScripts(h) h.SetData("HeaderImage", getHeaderImage(h)) h.SetData("scene", h.Scene()) + for _, s := range []string{widgets.Meta, widgets.Categories, widgets.Archive, widgets.Search, widgets.RecentComments, widgets.RecentPosts} { + ss := strings.ReplaceAll(s, "-", "_") + if s == widgets.RecentPosts { + ss = "recent_entries" + } + wp.SetComponentsArgsForMap(h, s, "{$before_widget}", fmt.Sprintf(`
    `, s, ss)) + wp.SetComponentsArgsForMap(h, s, "{$after_widget}", "
    ") + } + wp.SetComponentsArgsForMap(h, widgets.Search, "{$form}", searchForm) next(h) } +var searchForm = `` + func dispatch(next wp.HandleFn[*wp.Handle], h *wp.Handle) { switch h.Scene() { case constraints.Detail: diff --git a/internal/theme/wp/bodyclass.go b/internal/theme/wp/bodyclass.go index 82a2c33..8f1b724 100644 --- a/internal/theme/wp/bodyclass.go +++ b/internal/theme/wp/bodyclass.go @@ -36,6 +36,9 @@ func (h *Handle) BodyClass(class ...string) string { case constraints.Category, constraints.Tag: class = append(class, "archive", "category") cat := h.Index.Param.Category + if cat == "" { + break + } _, cate := slice.SearchFirst(cache.CategoriesTags(h.C, h.scene), func(my models.TermsMy) bool { return my.Name == cat }) diff --git a/internal/theme/wp/components/widget/archive.go b/internal/theme/wp/components/widget/archive.go index 14f5624..7303e43 100644 --- a/internal/theme/wp/components/widget/archive.go +++ b/internal/theme/wp/components/widget/archive.go @@ -49,17 +49,20 @@ var archiveTemplate = `{$before_widget} ` func Archive(h *wp.Handle) string { - args := wp.GetComponentsArgs(h, widgets.ArchiveArgs, archiveArgs.Load()) + args := wp.GetComponentsArgs(h, widgets.Archive, archiveArgs.Load()) args = maps.FilterZeroMerge(archiveArgs.Load(), args) conf := wpconfig.GetPHPArrayVal("widget_archives", archivesConfig.Load(), int64(2)) args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) + if id, ok := args["{$id}"]; ok && id != "" { + args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"]) + } s := archiveTemplate if int64(1) == conf["dropdown"].(int64) { s = strings.ReplaceAll(s, "{$html}", archiveDropDown(h, conf, args, cache.Archives(h.C))) } else { s = strings.ReplaceAll(s, "{$html}", archiveUl(h, conf, args, cache.Archives(h.C))) } - return h.ComponentFilterFnHook(widgets.ArchiveArgs, str.Replace(s, args)) + return h.ComponentFilterFnHook(widgets.Archive, str.Replace(s, args)) } var dropdownScript = ` diff --git a/internal/theme/wp/components/widget/category.go b/internal/theme/wp/components/widget/category.go index 28e4a2f..f66d124 100644 --- a/internal/theme/wp/components/widget/category.go +++ b/internal/theme/wp/components/widget/category.go @@ -36,7 +36,7 @@ var categoryConfig = func() safety.Var[map[any]any] { "{$class}": "postform", "{$show_option_none}": "选择分类", "{$name}": "cat", - "{$id}": "cat", + "{$selectId}": "cat", "{$required}": "", "{$nav}": "", "{$navCloser}": "", @@ -64,6 +64,9 @@ func Category(h *wp.Handle) string { args["{$title}"] = str.Join(args["{$before_title}"], conf["title"].(string), args["{$after_title}"]) t := categoryTemplate dropdown := conf["dropdown"].(int64) + if id, ok := args["{$id}"]; ok && id != "" { + args["{$before_widget}"] = strings.ReplaceAll(args["{$before_widget}"], "2", args["{$id}"]) + } categories := cache.CategoriesTags(h.C, constraints.Category) if dropdown == 1 { t = strings.ReplaceAll(t, "{$html}", categoryDropdown(h, args, conf, categories)) @@ -71,7 +74,7 @@ func Category(h *wp.Handle) string { } else { t = strings.ReplaceAll(t, "{$html}", categoryUL(h, args, conf, categories)) } - return str.Replace(t, args) + return h.ComponentFilterFnHook(widgets.Categories, str.Replace(t, args)) } func categoryUL(h *wp.Handle, args map[string]string, conf map[any]any, categories []models.TermsMy) string { @@ -173,10 +176,10 @@ func categoryDropdown(h *wp.Handle, args map[string]string, conf map[any]any, ca s.WriteString(`
    `) s.Sprintf(` -`, args["{$id}"], args["{$title}"]) +`, args["{$selectId}"], args["{$title}"]) if len(categories) > 0 { s.Sprintf(`