优化
This commit is contained in:
parent
c60c11769a
commit
f722d685ea
2
go.mod
2
go.mod
|
@ -1,6 +1,6 @@
|
|||
module github.com/fthvgb1/wp-go
|
||||
|
||||
go 1.20
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/dlclark/regexp2 v1.7.0
|
||||
|
|
|
@ -2,7 +2,6 @@ package strings
|
|||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/exp/constraints"
|
||||
"io"
|
||||
|
@ -61,16 +60,14 @@ func NewBuilder() *Builder {
|
|||
return &Builder{&strings.Builder{}}
|
||||
}
|
||||
|
||||
func (b *Builder) WriteString(s ...string) (count int, err error) {
|
||||
func (b *Builder) WriteString(s ...string) (count int) {
|
||||
for _, ss := range s {
|
||||
i, er := b.Builder.WriteString(ss)
|
||||
if er != nil {
|
||||
err = errors.Join(er)
|
||||
}
|
||||
i, _ := b.Builder.WriteString(ss)
|
||||
count += i
|
||||
}
|
||||
return
|
||||
}
|
||||
func (b *Builder) Sprintf(format string, a ...any) (int, error) {
|
||||
return b.WriteString(fmt.Sprintf(format, a...))
|
||||
func (b *Builder) Sprintf(format string, a ...any) int {
|
||||
i, _ := fmt.Fprintf(b, format, a...)
|
||||
return i
|
||||
}
|
||||
|
|
|
@ -86,11 +86,8 @@ func TestBuilder_WriteString(t *testing.T) {
|
|||
b := &Builder{
|
||||
Builder: tt.fields.Builder,
|
||||
}
|
||||
gotCount, err := b.WriteString(tt.args.s...)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("WriteString() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
gotCount := b.WriteString(tt.args.s...)
|
||||
|
||||
if gotCount != tt.wantCount {
|
||||
t.Errorf("WriteString() gotCount = %v, want %v", gotCount, tt.wantCount)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package middleware
|
|||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/mail"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||
|
@ -64,17 +65,13 @@ var (
|
|||
)
|
||||
|
||||
func formatStack(s string) (r string) {
|
||||
ss := strings.Builder{}
|
||||
ss := str.NewBuilder()
|
||||
t := strings.Split(s, "\n")
|
||||
for i, line := range t {
|
||||
if i%2 == 0 {
|
||||
ss.WriteString("<dt>")
|
||||
ss.WriteString(line)
|
||||
ss.WriteString("</dt>")
|
||||
ss.WriteString("<dt>", line, "</dt>")
|
||||
} else {
|
||||
ss.WriteString("<dd>")
|
||||
ss.WriteString(strings.Trim(line, "\t"))
|
||||
ss.WriteString("</dd>")
|
||||
ss.WriteString("<dt>", strings.Trim(line, "\t"), "</dt>")
|
||||
}
|
||||
}
|
||||
r = ss.String()
|
||||
|
|
|
@ -2,6 +2,7 @@ package plugins
|
|||
|
||||
import (
|
||||
"github.com/fthvgb1/wp-go/helper/slice"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/url"
|
||||
|
@ -50,7 +51,7 @@ func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, m
|
|||
}
|
||||
|
||||
func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html string) {
|
||||
s := strings.Builder{}
|
||||
s := str.NewBuilder()
|
||||
if d.depth > d.maxDepth {
|
||||
comments = d.findComments(comments)
|
||||
}
|
||||
|
@ -69,9 +70,7 @@ func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html st
|
|||
s.WriteString(d.i.FormatLi(d.Context, comment.Comments, d.depth, d.isTls, eo, parent))
|
||||
if fl {
|
||||
d.depth++
|
||||
s.WriteString(`<ol class="children">`)
|
||||
s.WriteString(d.formatComment(comment.Children, false))
|
||||
s.WriteString(`</ol>`)
|
||||
s.WriteString(`<ol class="children">`, d.formatComment(comment.Children, false), `</ol>`)
|
||||
if isTop {
|
||||
d.depth = 1
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/helper"
|
||||
"github.com/fthvgb1/wp-go/helper/maps"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var postx = map[string]string{
|
||||
|
@ -50,11 +50,9 @@ func (h *Handle) CalCustomBackGround() (r string) {
|
|||
if mods.BackgroundImage == "" && mods.BackgroundColor == mods.ThemeSupport.CustomBackground.DefaultColor {
|
||||
return
|
||||
}
|
||||
s := strings.Builder{}
|
||||
s := str.NewBuilder()
|
||||
if mods.BackgroundImage != "" {
|
||||
s.WriteString(` background-image: url("`)
|
||||
s.WriteString(helper.CutUrlHost(mods.BackgroundImage))
|
||||
s.WriteString(`");`)
|
||||
s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(mods.BackgroundImage))
|
||||
}
|
||||
backgroundPositionX := helper.Defaults(mods.BackgroundPositionX, mods.ThemeSupport.CustomBackground.DefaultPositionX)
|
||||
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
|
||||
|
@ -74,10 +72,7 @@ func (h *Handle) CalCustomBackGround() (r string) {
|
|||
attachment := helper.Defaults(mods.BackgroundAttachment, mods.ThemeSupport.CustomBackground.DefaultAttachment)
|
||||
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
|
||||
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
|
||||
s.WriteString(positon)
|
||||
s.WriteString(siz)
|
||||
s.WriteString(repeats)
|
||||
s.WriteString(attachment)
|
||||
s.WriteString(positon, siz, repeats, attachment)
|
||||
r = fmt.Sprintf(`<style id="custom-background-css">
|
||||
body.custom-background {%s}
|
||||
</style>`, s.String())
|
||||
|
|
Loading…
Reference in New Issue
Block a user