mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-09 08:02:26 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
397d47bc00 |
19
pkg/cache/render/render.go
vendored
19
pkg/cache/render/render.go
vendored
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/eiblog/eiblog/pkg/config"
|
"github.com/eiblog/eiblog/pkg/config"
|
||||||
"github.com/eiblog/eiblog/pkg/model"
|
"github.com/eiblog/eiblog/pkg/model"
|
||||||
|
"github.com/eiblog/eiblog/tools"
|
||||||
|
|
||||||
"github.com/eiblog/blackfriday"
|
"github.com/eiblog/blackfriday"
|
||||||
)
|
)
|
||||||
@@ -41,17 +42,6 @@ var (
|
|||||||
regHeader = regexp.MustCompile("</nav></div>")
|
regHeader = regexp.MustCompile("</nav></div>")
|
||||||
)
|
)
|
||||||
|
|
||||||
// IgnoreHtmlTag 去掉 html tag
|
|
||||||
func IgnoreHtmlTag(src string) string {
|
|
||||||
// 去除所有尖括号内的HTML代码
|
|
||||||
re, _ := regexp.Compile(`<[\S\s]+?>`)
|
|
||||||
src = re.ReplaceAllString(src, "")
|
|
||||||
|
|
||||||
// 去除换行符
|
|
||||||
re, _ = regexp.Compile(`\s+`)
|
|
||||||
return re.ReplaceAllString(src, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
// RenderPage 渲染markdown
|
// RenderPage 渲染markdown
|
||||||
func RenderPage(md []byte) []byte {
|
func RenderPage(md []byte) []byte {
|
||||||
renderer := blackfriday.HtmlRenderer(commonHtmlFlags, "", "")
|
renderer := blackfriday.HtmlRenderer(commonHtmlFlags, "", "")
|
||||||
@@ -66,7 +56,7 @@ func GenerateExcerptMarkdown(article *model.Article) {
|
|||||||
index := strings.Index(article.Content, "\r\n")
|
index := strings.Index(article.Content, "\r\n")
|
||||||
prefix := article.Content[len(blogapp.General.DescPrefix):index]
|
prefix := article.Content[len(blogapp.General.DescPrefix):index]
|
||||||
|
|
||||||
article.Desc = IgnoreHtmlTag(prefix)
|
article.Desc = tools.IgnoreHtmlTag(prefix)
|
||||||
article.Content = article.Content[index:]
|
article.Content = article.Content[index:]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,12 +73,13 @@ func GenerateExcerptMarkdown(article *model.Article) {
|
|||||||
// excerpt
|
// excerpt
|
||||||
index = regIdentifier.FindStringIndex(article.Content)
|
index = regIdentifier.FindStringIndex(article.Content)
|
||||||
if index != nil {
|
if index != nil {
|
||||||
article.Excerpt = IgnoreHtmlTag(article.Content[:index[0]])
|
article.Excerpt = tools.IgnoreHtmlTag(article.Content[:index[0]])
|
||||||
|
return
|
||||||
}
|
}
|
||||||
uc := []rune(article.Content)
|
uc := []rune(article.Content)
|
||||||
length := blogapp.General.Length
|
length := blogapp.General.Length
|
||||||
if len(uc) < length {
|
if len(uc) < length {
|
||||||
length = len(uc)
|
length = len(uc)
|
||||||
}
|
}
|
||||||
article.Excerpt = IgnoreHtmlTag(string(uc[0:length]))
|
article.Excerpt = tools.IgnoreHtmlTag(string(uc[0:length]))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user