Merge pull request #6 from fthvgb1/dev

Dev
This commit is contained in:
2023-01-28 23:35:14 +08:00 committed by GitHub
commit 7e935a8fa6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 15 deletions

View File

@ -1,7 +1,7 @@
## wp-go
a simple front of WordPress build with golang.
一个go写的WordPress的前端功能比较简单只有列表页和详情页,rss2主题只有一个twentyfifteen主题插件的话只有一个简单的列表页的摘要生成和enlighter代码高亮。本身只用于展示文章不支持restful api调用添加评论走的转发请求到php的WordPress。因为大量用了泛型功能所以要求go的版本在1.18以上。
一个go写的WordPress的前端功能比较简单只有列表页和详情页,rss2主题只有twentyfifteen和twentyseventeen两套主题插件的话只有一个简单的列表页的摘要生成和enlighter代码高亮。本身只用于展示文章添加评论走的转发请求到php的WordPress。因为大量用了泛型功能所以要求go的版本在1.18以上。
#### 特色功能

View File

@ -23,6 +23,10 @@ Mail:
Port: 465
Ssl: true
ssl:
cert: ""
key: ""
# 最近文章缓存时间
recentPostCacheTime: 5m
# 分类缓存时间

View File

@ -24,19 +24,19 @@ import (
)
var confPath string
var port string
var address string
var middleWareReloadFn func()
var intReg = regexp.MustCompile(`^\d`)
func init() {
flag.StringVar(&confPath, "c", "config.yaml", "config file")
flag.StringVar(&port, "p", "", "port")
flag.StringVar(&address, "p", "", "listen address(port)")
flag.Parse()
if port == "" && os.Getenv("PORT") == "" {
port = "80"
if address == "" && os.Getenv("PORT") == "" {
address = "80"
}
if intReg.MatchString(port) && !strings.Contains(port, ":") {
port = ":" + port
if intReg.MatchString(address) && !strings.Contains(address, ":") {
address = ":" + address
}
rand.Seed(time.Now().UnixNano())
err := initConf(confPath)
@ -129,8 +129,16 @@ func signalNotify() {
func main() {
go signalNotify()
Gin, reloadFn := route.SetupRouter()
c := config.Conf.Load()
middleWareReloadFn = reloadFn
err := Gin.Run(port)
if c.Ssl.Key != "" && c.Ssl.Cert != "" {
err := Gin.RunTLS(address, c.Ssl.Cert, c.Ssl.Key)
if err != nil {
panic(err)
}
return
}
err := Gin.Run(address)
if err != nil {
panic(err)
}

View File

@ -11,6 +11,7 @@ import (
var Conf safety.Var[Config]
type Config struct {
Ssl Ssl `yaml:"ssl"`
Mysql Mysql `yaml:"mysql"`
Mail Mail `yaml:"mail"`
RecentPostCacheTime time.Duration `yaml:"recentPostCacheTime"`
@ -41,6 +42,11 @@ type Config struct {
PostOrder string `yaml:"postOrder"`
}
type Ssl struct {
Cert string `yaml:"cert"`
Key string `yaml:"key"`
}
type Mail struct {
User string `yaml:"user"`
Alias string `yaml:"alias"`

View File

@ -2,18 +2,16 @@ package plugins
import (
"fmt"
"github.com/fthvgb1/wp-go/helper/number"
str "github.com/fthvgb1/wp-go/helper/strings"
"github.com/fthvgb1/wp-go/internal/wpconfig"
"math/rand"
"net/url"
"strings"
"time"
)
func Gravatar(email string, isTls bool) (u string) {
email = strings.Trim(email, " \t\n\r\000\x0B")
rand.Seed(time.Now().UnixNano())
num := rand.Intn(3)
num := number.Rand(0, 2)
h := ""
if email != "" {
h = str.Md5(strings.ToLower(email))

View File

@ -29,7 +29,7 @@ var twentyFifteen = PageEle{
<span class="meta-nav screen-reader-text"> </span>%d</span>`,
}
func (p PageEle) Current(page int) string {
func (p PageEle) Current(page, totalPage int) string {
return fmt.Sprintf(p.CurrentEle, page)
}

View File

@ -6,7 +6,7 @@ import (
)
type Elements interface {
Current(page int) string
Current(page, totalPage int) string
Prev(url string) string
Next(url string) string
Dots() string
@ -68,7 +68,7 @@ func (p ParsePagination) ToHtml() (html string) {
for page := start; page <= end; page++ {
h := ""
if p.CurrentPage == page {
h = p.Current(page)
h = p.Current(page, p.TotalPage)
} else {
h = p.Middle(page, p.Url(p.Path, p.Query, page))
}