mirror of
https://github.com/eiblog/eiblog.git
synced 2026-03-01 00:34:58 +08:00
chore: rm package utils
This commit is contained in:
1
go.mod
1
go.mod
@@ -5,7 +5,6 @@ go 1.15
|
|||||||
require (
|
require (
|
||||||
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
|
||||||
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
|
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae
|
||||||
github.com/eiblog/utils v0.0.0-20181119015747-92c93e218753
|
|
||||||
github.com/gin-contrib/sessions v0.0.3
|
github.com/gin-contrib/sessions v0.0.3
|
||||||
github.com/gin-gonic/gin v1.6.3
|
github.com/gin-gonic/gin v1.6.3
|
||||||
github.com/gofrs/uuid v3.3.0+incompatible
|
github.com/gofrs/uuid v3.3.0+incompatible
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -24,8 +24,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
|||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae h1:V6YC640Gs5jEUYfCimyuXsTW5gzNcIEESG4MGmOJCtA=
|
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae h1:V6YC640Gs5jEUYfCimyuXsTW5gzNcIEESG4MGmOJCtA=
|
||||||
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae/go.mod h1:HzHqTCGEAkSSzBM3shBvQHsHRQYUvjNOIC4mHipZ6tI=
|
github.com/eiblog/blackfriday v0.0.0-20161010144836-c0ec111761ae/go.mod h1:HzHqTCGEAkSSzBM3shBvQHsHRQYUvjNOIC4mHipZ6tI=
|
||||||
github.com/eiblog/utils v0.0.0-20181119015747-92c93e218753 h1:Nygjtnh1nF5zejJF7pZnsoFh77wOPS+jlfhikjkJg60=
|
|
||||||
github.com/eiblog/utils v0.0.0-20181119015747-92c93e218753/go.mod h1:mZHWnipRp41yw/rti2DgpbMiBE5i6ifqg7PKooEwRh4=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
"github.com/eiblog/eiblog/pkg/cache"
|
"github.com/eiblog/eiblog/pkg/cache"
|
||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
|
"github.com/eiblog/eiblog/tools"
|
||||||
|
|
||||||
"github.com/eiblog/utils/tmpl"
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ func init() {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
xmlTmpl, err = template.New("").Funcs(template.FuncMap{
|
xmlTmpl, err = template.New("").Funcs(template.FuncMap{
|
||||||
"dateformat": tmpl.DateFormat,
|
"dateformat": tools.DateFormat,
|
||||||
}).ParseGlob(root)
|
}).ParseGlob(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
"github.com/eiblog/eiblog/tools"
|
"github.com/eiblog/eiblog/tools"
|
||||||
|
|
||||||
"github.com/eiblog/utils/tmpl"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ import (
|
|||||||
var htmlTmpl *template.Template
|
var htmlTmpl *template.Template
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
htmlTmpl = template.New("eiblog").Funcs(tmpl.TplFuncMap)
|
htmlTmpl = template.New("eiblog").Funcs(tools.TplFuncMap)
|
||||||
root := filepath.Join(config.WorkDir, "website")
|
root := filepath.Join(config.WorkDir, "website")
|
||||||
files := tools.ReadDirFiles(root, func(name string) bool {
|
files := tools.ReadDirFiles(root, func(name string) bool {
|
||||||
if name == ".DS_Store" {
|
if name == ".DS_Store" {
|
||||||
|
|||||||
65
tools/tmplfunc.go
Normal file
65
tools/tmplfunc.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
// Package tools provides ...
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
htmpl "html/template"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var TplFuncMap = make(template.FuncMap)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
TplFuncMap["dateformat"] = DateFormat
|
||||||
|
TplFuncMap["str2html"] = Str2html
|
||||||
|
TplFuncMap["join"] = Join
|
||||||
|
TplFuncMap["isnotzero"] = IsNotZero
|
||||||
|
TplFuncMap["getavatar"] = GetAvatar
|
||||||
|
}
|
||||||
|
|
||||||
|
func Str2html(raw string) htmpl.HTML {
|
||||||
|
return htmpl.HTML(raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DateFormat takes a time and a layout string and returns a string with the formatted date. Used by the template parser as "dateformat"
|
||||||
|
func DateFormat(t time.Time, layout string) string {
|
||||||
|
return t.Format(layout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func Join(a []string, sep string) string {
|
||||||
|
return strings.Join(a, sep)
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsNotZero(t time.Time) bool {
|
||||||
|
return !t.IsZero()
|
||||||
|
}
|
||||||
|
|
||||||
|
// cache avatar image
|
||||||
|
// url: https://<static_domain>/static/img/avatar.png
|
||||||
|
var avatar string
|
||||||
|
|
||||||
|
func GetAvatar(domain string) string {
|
||||||
|
if avatar == "" {
|
||||||
|
resp, err := http.Get("https://" + domain + "/static/img/avatar.png")
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
avatar = "data:" + resp.Header.Get("content-type") + ";base64," + base64.StdEncoding.EncodeToString(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return avatar
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user