接入后台近期评论设置

This commit is contained in:
xing 2023-03-07 17:13:12 +08:00
parent 096514a677
commit 1f7e51858b
5 changed files with 36 additions and 35 deletions

View File

@ -3,16 +3,14 @@ package cache
import (
"context"
"github.com/fthvgb1/wp-go/cache"
"github.com/fthvgb1/wp-go/helper/number"
"github.com/fthvgb1/wp-go/internal/pkg/logs"
"github.com/fthvgb1/wp-go/internal/pkg/models"
"time"
)
func RecentComments(ctx context.Context, n int) (r []models.Comments) {
nn := n
if nn <= 5 {
nn = 10
}
nn := number.Max(n, 10)
r, err := recentCommentsCaches.GetCache(ctx, time.Second, ctx, nn)
if len(r) > n {
r = r[0:n]

View File

@ -1,6 +1,9 @@
{{define "layout/sidebar" }}
<div id="widget-area" class="widget-area" role="complementary">
<aside id="search-2" class="widget widget_search">
{{if .searchConf}}
<h2 class="widget-title">{{.searchConf}}</h2>
{{end}}
<form role="search" method="get" class="search-form" action="/">
<label>
<span class="screen-reader-text">搜索:</span>
@ -10,18 +13,7 @@
</form>
</aside>
{{template "common/recent-posts" .}}
<aside id="recent-comments-2" class="widget widget_recent_comments">
<h2 class="widget-title">近期评论</h2>
<nav aria-label="近期评论">
<ul id="recentcomments">
{{ range $i,$v := .recentComments}}
<li class="recentcomments">
<span class="comment-author-link">{{$v.CommentAuthor}}</span>发表在《<a class="wp-block-latest-comments__comment-link" href="/p/{{$v.CommentPostId}}#comment-{{$v.CommentId}}">{{$v.PostTitle}}</a>》
</li>
{{end}}
</ul>
</nav>
</aside>
{{template "common/recent-comments" .}}
{{template "common/archives" .}}
<aside id="categories-2" class="widget widget_categories">
<h2 class="widget-title">分类</h2>

View File

@ -14,17 +14,7 @@
</form>
</section>
{{template "common/recent-posts" .}}
<section id="recent-comments-2" class="widget widget_recent_comments"><h2 class="widget-title">近期评论</h2>
<nav aria-label="近期评论">
<ul id="recentcomments">
{{ range $i,$v := .recentComments}}
<li class="recentcomments">
<span class="comment-author-link">{{$v.CommentAuthor}}</span>发表在《<a class="wp-block-latest-comments__comment-link" href="/p/{{$v.CommentPostId}}#comment-{{$v.CommentId}}">{{$v.PostTitle}}</a>》
</li>
{{end}}
</ul>
</nav>
</section>
{{template "common/recent-comments" .}}
{{template "common/archives" .}}
<section id="categories-2" class="widget widget_categories">
<h2 class="widget-title">分类</h2>

View File

@ -0,0 +1,14 @@
{{define "common/recent-comments"}}
<aside id="recent-comments-2" class="widget widget_recent_comments">
<h2 class="widget-title">{{.recentCommentsConfig.title}}</h2>
<nav aria-label="近期评论">
<ul id="recentcomments">
{{ range $i,$v := .recentComments}}
<li class="recentcomments">
<span class="comment-author-link">{{$v.CommentAuthor}}</span>发表在《<a class="wp-block-latest-comments__comment-link" href="/p/{{$v.CommentPostId}}#comment-{{$v.CommentId}}">{{$v.PostTitle}}</a>》
</li>
{{end}}
</ul>
</nav>
</aside>
{{end}}

View File

@ -2,7 +2,6 @@ package wp
import (
"github.com/fthvgb1/wp-go/helper/slice"
"github.com/fthvgb1/wp-go/internal/cmd/reload"
"github.com/fthvgb1/wp-go/internal/pkg/cache"
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
"github.com/fthvgb1/wp-go/internal/wpconfig"
@ -11,8 +10,9 @@ import (
func (h *Handle) WidgetAreaData() {
h.Archives()
h.RecentPosts()
h.RecentComments()
h.ginH["searchConf"] = wpconfig.GetPHPArrayVal("widget_search", "", int64(2), "title")
h.ginH["categories"] = cache.CategoriesTags(h.C, constraints.Category)
h.ginH["recentComments"] = cache.RecentComments(h.C, 5)
}
var recentConf = map[any]any{
@ -22,13 +22,22 @@ var recentConf = map[any]any{
}
func (h *Handle) RecentPosts() {
set := reload.GetAnyValBy("recentPostsConfig", func() map[any]any {
return wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recentConf, int64(2))
})
set := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-posts", recentConf, int64(2))
h.ginH["recentPostsConfig"] = set
h.ginH["recentPosts"] = slice.Map(cache.RecentPosts(h.C, int(set["number"].(int64))), ProjectTitle)
}
var recentCommentConf = map[any]any{
"number": int64(5),
"title": "近期文章",
}
func (h *Handle) RecentComments() {
set := wpconfig.GetPHPArrayVal[map[any]any]("widget_recent-comments", recentCommentConf, int64(2))
h.ginH["recentCommentsConfig"] = set
h.ginH["recentComments"] = cache.RecentComments(h.C, int(set["number"].(int64)))
}
var archivesConfig = map[any]any{
"count": 0,
"dropdown": 0,
@ -36,8 +45,6 @@ var archivesConfig = map[any]any{
}
func (h *Handle) Archives() {
h.ginH["archivesConfig"] = reload.GetAnyValBy("archivesConfig", func() map[any]any {
return wpconfig.GetPHPArrayVal[map[any]any]("widget_archives", archivesConfig, int64(2))
})
h.ginH["archivesConfig"] = wpconfig.GetPHPArrayVal[map[any]any]("widget_archives", archivesConfig, int64(2))
h.ginH["archives"] = cache.Archives(h.C)
}