add alert template function md_to_html
This commit is contained in:
parent
fc2d2a586e
commit
4cc69c8e53
|
@ -12,6 +12,7 @@ import (
|
|||
"infini.sh/framework/core/global"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
|
@ -190,6 +191,7 @@ func (h *AlertAPI) searchChannel(w http.ResponseWriter, req *http.Request, ps ht
|
|||
strFrom = h.GetParameterOrDefault(req, "from", "0")
|
||||
subType = h.GetParameterOrDefault(req, "sub_type", "")
|
||||
typ = h.GetParameterOrDefault(req, "type", "")
|
||||
sort = h.GetParameterOrDefault(req, "sort", "updated:desc")
|
||||
)
|
||||
mustQ := []interface{}{}
|
||||
if keyword != "" {
|
||||
|
@ -223,6 +225,18 @@ func (h *AlertAPI) searchChannel(w http.ResponseWriter, req *http.Request, ps ht
|
|||
if from < 0 {
|
||||
from = 0
|
||||
}
|
||||
var (
|
||||
sortField string
|
||||
sortDirection string
|
||||
)
|
||||
sortParts := strings.Split(sort, ":")
|
||||
sortField = sortParts[0]
|
||||
if len(sortParts) >= 2 {
|
||||
sortDirection = sortParts[1]
|
||||
}
|
||||
if sortDirection == "" {
|
||||
sortDirection = "asc"
|
||||
}
|
||||
query := util.MapStr{
|
||||
"size": size,
|
||||
"from": from,
|
||||
|
@ -231,6 +245,13 @@ func (h *AlertAPI) searchChannel(w http.ResponseWriter, req *http.Request, ps ht
|
|||
"must": mustQ,
|
||||
},
|
||||
},
|
||||
"sort": []util.MapStr{
|
||||
{
|
||||
sortField: util.MapStr{
|
||||
"order": sortDirection,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
q := orm.Query{
|
||||
|
|
|
@ -17,8 +17,8 @@ import (
|
|||
"infini.sh/framework/core/orm"
|
||||
"infini.sh/framework/core/util"
|
||||
"net/http"
|
||||
"src/github.com/buger/jsonparser"
|
||||
"src/github.com/gopkg.in/gomail.v2"
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/gopkg.in/gomail.v2"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
|
|
@ -33,5 +33,6 @@ var genericMap = map[string]interface{}{
|
|||
"mul": mul,
|
||||
"lookup": lookup,
|
||||
"str_replace": replace,
|
||||
"md_to_html": mdToHTML,
|
||||
//"get_keystore_secret": getKeystoreSecret,
|
||||
}
|
||||
|
|
|
@ -4,7 +4,12 @@
|
|||
|
||||
package funcs
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"github.com/gomarkdown/markdown"
|
||||
"github.com/gomarkdown/markdown/html"
|
||||
"github.com/gomarkdown/markdown/parser"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func substring(start, end int, s string) string {
|
||||
runes := []rune(s)
|
||||
|
@ -17,4 +22,18 @@ func substring(start, end int, s string) string {
|
|||
|
||||
func replace(old, new, src string) string {
|
||||
return strings.Replace(src, old, new, -1)
|
||||
}
|
||||
|
||||
func mdToHTML(mdText string) string {
|
||||
extensions := parser.CommonExtensions | parser.AutoHeadingIDs | parser.NoEmptyLineBeforeBlock
|
||||
p := parser.NewWithExtensions(extensions)
|
||||
doc := p.Parse([]byte(mdText))
|
||||
|
||||
// create HTML renderer with extensions
|
||||
htmlFlags := html.CommonFlags | html.HrefTargetBlank
|
||||
opts := html.RendererOptions{Flags: htmlFlags}
|
||||
renderer := html.NewRenderer(opts)
|
||||
|
||||
buf := markdown.Render(doc, renderer)
|
||||
return string(buf)
|
||||
}
|
Loading…
Reference in New Issue