Compare commits
No commits in common. "1d805343334c3e5f05238bf96e80be39b3624fc8" and "c60c11769a16fc005d935e06c71016f5cc1e2f52" have entirely different histories.
1d80534333
...
c60c11769a
2
go.mod
2
go.mod
@ -1,6 +1,6 @@
|
|||||||
module github.com/fthvgb1/wp-go
|
module github.com/fthvgb1/wp-go
|
||||||
|
|
||||||
go 1.19
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dlclark/regexp2 v1.7.0
|
github.com/dlclark/regexp2 v1.7.0
|
||||||
|
@ -2,6 +2,7 @@ package strings
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"golang.org/x/exp/constraints"
|
"golang.org/x/exp/constraints"
|
||||||
"io"
|
"io"
|
||||||
@ -60,14 +61,16 @@ func NewBuilder() *Builder {
|
|||||||
return &Builder{&strings.Builder{}}
|
return &Builder{&strings.Builder{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Builder) WriteString(s ...string) (count int) {
|
func (b *Builder) WriteString(s ...string) (count int, err error) {
|
||||||
for _, ss := range s {
|
for _, ss := range s {
|
||||||
i, _ := b.Builder.WriteString(ss)
|
i, er := b.Builder.WriteString(ss)
|
||||||
|
if er != nil {
|
||||||
|
err = errors.Join(er)
|
||||||
|
}
|
||||||
count += i
|
count += i
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (b *Builder) Sprintf(format string, a ...any) int {
|
func (b *Builder) Sprintf(format string, a ...any) (int, error) {
|
||||||
i, _ := fmt.Fprintf(b, format, a...)
|
return b.WriteString(fmt.Sprintf(format, a...))
|
||||||
return i
|
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,11 @@ func TestBuilder_WriteString(t *testing.T) {
|
|||||||
b := &Builder{
|
b := &Builder{
|
||||||
Builder: tt.fields.Builder,
|
Builder: tt.fields.Builder,
|
||||||
}
|
}
|
||||||
gotCount := b.WriteString(tt.args.s...)
|
gotCount, err := b.WriteString(tt.args.s...)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("WriteString() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
if gotCount != tt.wantCount {
|
if gotCount != tt.wantCount {
|
||||||
t.Errorf("WriteString() gotCount = %v, want %v", gotCount, tt.wantCount)
|
t.Errorf("WriteString() gotCount = %v, want %v", gotCount, tt.wantCount)
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
"github.com/fthvgb1/wp-go/internal/plugins"
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
||||||
"github.com/fthvgb1/wp-go/internal/theme"
|
"github.com/fthvgb1/wp-go/internal/theme"
|
||||||
|
"github.com/fthvgb1/wp-go/internal/theme/common"
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github.com/fthvgb1/wp-go/model"
|
"github.com/fthvgb1/wp-go/model"
|
||||||
"log"
|
"log"
|
||||||
@ -106,7 +107,7 @@ func reload() {
|
|||||||
logs.ErrPrintln(err, "获取网站设置WpOption失败")
|
logs.ErrPrintln(err, "获取网站设置WpOption失败")
|
||||||
err = wpconfig.InitTerms()
|
err = wpconfig.InitTerms()
|
||||||
wpconfig.FlushModes()
|
wpconfig.FlushModes()
|
||||||
theme.Reload()
|
common.Reload()
|
||||||
logs.ErrPrintln(err, "获取WpTerms表失败")
|
logs.ErrPrintln(err, "获取WpTerms表失败")
|
||||||
if middleWareReloadFn != nil {
|
if middleWareReloadFn != nil {
|
||||||
middleWareReloadFn()
|
middleWareReloadFn()
|
||||||
|
@ -3,7 +3,6 @@ package middleware
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/mail"
|
"github.com/fthvgb1/wp-go/internal/mail"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
"github.com/fthvgb1/wp-go/internal/pkg/config"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
@ -65,13 +64,17 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func formatStack(s string) (r string) {
|
func formatStack(s string) (r string) {
|
||||||
ss := str.NewBuilder()
|
ss := strings.Builder{}
|
||||||
t := strings.Split(s, "\n")
|
t := strings.Split(s, "\n")
|
||||||
for i, line := range t {
|
for i, line := range t {
|
||||||
if i%2 == 0 {
|
if i%2 == 0 {
|
||||||
ss.WriteString("<dt>", line, "</dt>")
|
ss.WriteString("<dt>")
|
||||||
|
ss.WriteString(line)
|
||||||
|
ss.WriteString("</dt>")
|
||||||
} else {
|
} else {
|
||||||
ss.WriteString("<dt>", strings.Trim(line, "\t"), "</dt>")
|
ss.WriteString("<dd>")
|
||||||
|
ss.WriteString(strings.Trim(line, "\t"))
|
||||||
|
ss.WriteString("</dd>")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r = ss.String()
|
r = ss.String()
|
||||||
|
@ -2,7 +2,6 @@ package plugins
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
"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/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -51,7 +50,7 @@ func FormatComments(c *gin.Context, i CommentHtml, comments []models.Comments, m
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html string) {
|
func (d CommentHandler) formatComment(comments []*Comments, isTop bool) (html string) {
|
||||||
s := str.NewBuilder()
|
s := strings.Builder{}
|
||||||
if d.depth > d.maxDepth {
|
if d.depth > d.maxDepth {
|
||||||
comments = d.findComments(comments)
|
comments = d.findComments(comments)
|
||||||
}
|
}
|
||||||
@ -70,7 +69,9 @@ 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))
|
s.WriteString(d.i.FormatLi(d.Context, comment.Comments, d.depth, d.isTls, eo, parent))
|
||||||
if fl {
|
if fl {
|
||||||
d.depth++
|
d.depth++
|
||||||
s.WriteString(`<ol class="children">`, d.formatComment(comment.Children, false), `</ol>`)
|
s.WriteString(`<ol class="children">`)
|
||||||
|
s.WriteString(d.formatComment(comment.Children, false))
|
||||||
|
s.WriteString(`</ol>`)
|
||||||
if isTop {
|
if isTop {
|
||||||
d.depth = 1
|
d.depth = 1
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fthvgb1/wp-go/helper"
|
"github.com/fthvgb1/wp-go/helper"
|
||||||
"github.com/fthvgb1/wp-go/helper/maps"
|
"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/internal/wpconfig"
|
||||||
"github.com/fthvgb1/wp-go/safety"
|
"github.com/fthvgb1/wp-go/safety"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var postx = map[string]string{
|
var postx = map[string]string{
|
||||||
@ -50,9 +50,11 @@ func (h *Handle) CalCustomBackGround() (r string) {
|
|||||||
if mods.BackgroundImage == "" && mods.BackgroundColor == mods.ThemeSupport.CustomBackground.DefaultColor {
|
if mods.BackgroundImage == "" && mods.BackgroundColor == mods.ThemeSupport.CustomBackground.DefaultColor {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s := str.NewBuilder()
|
s := strings.Builder{}
|
||||||
if mods.BackgroundImage != "" {
|
if mods.BackgroundImage != "" {
|
||||||
s.Sprintf(` background-image: url("%s");`, helper.CutUrlHost(mods.BackgroundImage))
|
s.WriteString(` background-image: url("`)
|
||||||
|
s.WriteString(helper.CutUrlHost(mods.BackgroundImage))
|
||||||
|
s.WriteString(`");`)
|
||||||
}
|
}
|
||||||
backgroundPositionX := helper.Defaults(mods.BackgroundPositionX, mods.ThemeSupport.CustomBackground.DefaultPositionX)
|
backgroundPositionX := helper.Defaults(mods.BackgroundPositionX, mods.ThemeSupport.CustomBackground.DefaultPositionX)
|
||||||
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
|
backgroundPositionX = maps.WithDefaultVal(postx, backgroundPositionX, "left")
|
||||||
@ -72,7 +74,10 @@ func (h *Handle) CalCustomBackGround() (r string) {
|
|||||||
attachment := helper.Defaults(mods.BackgroundAttachment, mods.ThemeSupport.CustomBackground.DefaultAttachment)
|
attachment := helper.Defaults(mods.BackgroundAttachment, mods.ThemeSupport.CustomBackground.DefaultAttachment)
|
||||||
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
|
attachment = helper.Or(attachment == "fixed", "fixed", "scroll")
|
||||||
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
|
attachment = fmt.Sprintf(" background-attachment: %s;", attachment)
|
||||||
s.WriteString(positon, siz, repeats, attachment)
|
s.WriteString(positon)
|
||||||
|
s.WriteString(siz)
|
||||||
|
s.WriteString(repeats)
|
||||||
|
s.WriteString(attachment)
|
||||||
r = fmt.Sprintf(`<style id="custom-background-css">
|
r = fmt.Sprintf(`<style id="custom-background-css">
|
||||||
body.custom-background {%s}
|
body.custom-background {%s}
|
||||||
</style>`, s.String())
|
</style>`, s.String())
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
package common
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/fthvgb1/wp-go/helper/slice"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/wpconfig"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (h *Handle) DisplayHeaderText() bool {
|
|
||||||
mods, err := wpconfig.GetThemeMods(h.Theme)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return mods.ThemeSupport.CustomHeader.HeaderText && "blank" != mods.HeaderTextcolor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handle) GetCustomHeader() (r models.PostThumbnail, isRand bool) {
|
|
||||||
hs, err := cache.GetHeaderImages(h.C, h.Theme)
|
|
||||||
if err != nil {
|
|
||||||
logs.ErrPrintln(err, "获取页眉背景图失败")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(hs) < 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(hs) > 1 {
|
|
||||||
isRand = true
|
|
||||||
}
|
|
||||||
r, _ = slice.RandPop(&hs)
|
|
||||||
return
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
package common
|
package common
|
||||||
|
|
||||||
func Reload() {
|
func Reload() {
|
||||||
backgroud.Store("default")
|
backgroud.Flush()
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,6 @@ func InitTheme() {
|
|||||||
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
common.AddThemeSupport(twentyfifteen.ThemeName, twentyfifteen.ThemeSupport())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reload() {
|
|
||||||
twentyfifteen.Reload()
|
|
||||||
common.Reload()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetTemplateName() string {
|
func GetTemplateName() string {
|
||||||
tmlp := config.GetConfig().Theme
|
tmlp := config.GetConfig().Theme
|
||||||
if tmlp == "" {
|
if tmlp == "" {
|
||||||
|
@ -1,124 +0,0 @@
|
|||||||
package twentyfifteen
|
|
||||||
|
|
||||||
import (
|
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
|
||||||
"github.com/fthvgb1/wp-go/safety"
|
|
||||||
)
|
|
||||||
|
|
||||||
var style = `<style type="text/css" id="twentyfifteen-header-css">`
|
|
||||||
var defaultTextStyle = `.site-header {
|
|
||||||
padding-top: 14px;
|
|
||||||
padding-bottom: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.site-branding {
|
|
||||||
min-height: 42px;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 46.25em) {
|
|
||||||
.site-header {
|
|
||||||
padding-top: 21px;
|
|
||||||
padding-bottom: 21px;
|
|
||||||
}
|
|
||||||
.site-branding {
|
|
||||||
min-height: 56px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media screen and (min-width: 55em) {
|
|
||||||
.site-header {
|
|
||||||
padding-top: 25px;
|
|
||||||
padding-bottom: 25px;
|
|
||||||
}
|
|
||||||
.site-branding {
|
|
||||||
min-height: 62px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@media screen and (min-width: 59.6875em) {
|
|
||||||
.site-header {
|
|
||||||
padding-top: 0;
|
|
||||||
padding-bottom: 0;
|
|
||||||
}
|
|
||||||
.site-branding {
|
|
||||||
min-height: 0;
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
var imgStyle = `.site-header {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* No shorthand so the Customizer can override individual properties.
|
|
||||||
* @see https://core.trac.wordpress.org/ticket/31460
|
|
||||||
*/
|
|
||||||
background-image: url("%s");
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: 50% 50%;
|
|
||||||
-webkit-background-size: cover;
|
|
||||||
-moz-background-size: cover;
|
|
||||||
-o-background-size: cover;
|
|
||||||
background-size: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media screen and (min-width: 59.6875em) {
|
|
||||||
body:before {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* No shorthand so the Customizer can override individual properties.
|
|
||||||
* @see https://core.trac.wordpress.org/ticket/31460
|
|
||||||
*/
|
|
||||||
background-image: url("%s");
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
background-position: 100% 50%;
|
|
||||||
-webkit-background-size: cover;
|
|
||||||
-moz-background-size: cover;
|
|
||||||
-o-background-size: cover;
|
|
||||||
background-size: cover;
|
|
||||||
border-right: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.site-header {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
}`
|
|
||||||
|
|
||||||
var header = safety.NewVar("default")
|
|
||||||
|
|
||||||
func Reload() {
|
|
||||||
header.Store("default")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *handle) CalCustomHeader() (r string, rand bool) {
|
|
||||||
img, rand := h.IndexHandle.GetCustomHeader()
|
|
||||||
if img.Path == "" && h.IndexHandle.DisplayHeaderText() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
ss := str.NewBuilder()
|
|
||||||
ss.WriteString(style)
|
|
||||||
if img.Path == "" && !h.IndexHandle.DisplayHeaderText() {
|
|
||||||
ss.WriteString(defaultTextStyle)
|
|
||||||
}
|
|
||||||
if img.Path != "" {
|
|
||||||
ss.Sprintf(imgStyle, img.Path, img.Path)
|
|
||||||
}
|
|
||||||
if !h.IndexHandle.DisplayHeaderText() {
|
|
||||||
ss.WriteString(`.site-title,
|
|
||||||
.site-description {
|
|
||||||
clip: rect(1px, 1px, 1px, 1px);
|
|
||||||
position: absolute;
|
|
||||||
}`)
|
|
||||||
}
|
|
||||||
ss.WriteString("</style>")
|
|
||||||
r = ss.String()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *handle) CustomHeader() {
|
|
||||||
headers := header.Load()
|
|
||||||
if headers == "default" {
|
|
||||||
headerss, rand := h.CalCustomHeader()
|
|
||||||
headers = headerss
|
|
||||||
if !rand {
|
|
||||||
header.Store(headers)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
h.IndexHandle.GinH["customHeader"] = headers
|
|
||||||
return
|
|
||||||
}
|
|
@ -61,7 +61,4 @@
|
|||||||
{{if .customBackground}}
|
{{if .customBackground}}
|
||||||
{{.customBackground|unescaped}}
|
{{.customBackground|unescaped}}
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .customHeader}}
|
|
||||||
{{.customHeader|unescaped}}
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
@ -12,13 +12,12 @@ import (
|
|||||||
|
|
||||||
const ThemeName = "twentyfifteen"
|
const ThemeName = "twentyfifteen"
|
||||||
|
|
||||||
type handle struct {
|
type indexHandle struct {
|
||||||
*common.IndexHandle
|
*common.IndexHandle
|
||||||
*common.DetailHandle
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHandle(iHandle *common.IndexHandle, dHandle *common.DetailHandle) *handle {
|
func newIndexHandle(iHandle *common.IndexHandle) *indexHandle {
|
||||||
return &handle{iHandle, dHandle}
|
return &indexHandle{iHandle}
|
||||||
}
|
}
|
||||||
|
|
||||||
type detailHandle struct {
|
type detailHandle struct {
|
||||||
@ -32,22 +31,19 @@ func newDetailHandle(dHandle *common.DetailHandle) *detailHandle {
|
|||||||
func Hook(h *common.Handle) {
|
func Hook(h *common.Handle) {
|
||||||
h.WidgetAreaData()
|
h.WidgetAreaData()
|
||||||
h.GetPassword()
|
h.GetPassword()
|
||||||
handle := newHandle(common.NewIndexHandle(h), common.NewDetailHandle(h))
|
|
||||||
if h.Scene == constraints.Detail {
|
if h.Scene == constraints.Detail {
|
||||||
handle.Detail()
|
newDetailHandle(common.NewDetailHandle(h)).Detail()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handle.Index()
|
newIndexHandle(common.NewIndexHandle(h)).Index()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handle) Index() {
|
func (i *indexHandle) Index() {
|
||||||
h.CustomHeader()
|
i.Indexs()
|
||||||
h.Indexs()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *handle) Detail() {
|
func (d *detailHandle) Detail() {
|
||||||
h.CustomHeader()
|
d.Details()
|
||||||
h.Details()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
func getHeaderImage(c *gin.Context) (r models.PostThumbnail) {
|
||||||
|
@ -114,7 +114,6 @@ func GetThemeMods(theme string) (r ThemeMods, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
r.setThemeColorScheme(theme)
|
r.setThemeColorScheme(theme)
|
||||||
r.setThemeSupport(theme)
|
|
||||||
themeModes.Store(theme, r)
|
themeModes.Store(theme, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user