Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcc8887

Browse files
committed
txt去除不必要的空格
1 parent 8b806bd commit dcc8887

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

websites/code/studygolang/src/model/document.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ func NewDocument(object interface{}, objectExt interface{}) *Document {
5252
return document
5353
}
5454

55-
var re = regexp.MustCompile("[\r\n\t\v ]+")
55+
var docRe = regexp.MustCompile("[\r \n  \t\v]+")
56+
var docSpaceRe = regexp.MustCompile("[ ]+")
5657

5758
// 文本过滤(预处理)
5859
func filterTxt(txt string) string {
@@ -61,7 +62,8 @@ func filterTxt(txt string) string {
6162
txt = strings.TrimSpace(strings.TrimPrefix(txt, "顶"))
6263
txt = strings.TrimSpace(strings.TrimPrefix(txt, "转"))
6364

64-
return re.ReplaceAllLiteralString(txt, " ")
65+
txt = docRe.ReplaceAllLiteralString(txt, " ")
66+
return docSpaceRe.ReplaceAllLiteralString(txt, " ")
6567
}
6668

6769
type AddCommand struct {

websites/code/studygolang/src/service/article.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ var domainPatch = map[string]string{
2424
"blog.51cto.com": "blog.51cto.com",
2525
}
2626

27+
var articleRe = regexp.MustCompile("[\r \n  \t\v]+")
28+
var articleSpaceRe = regexp.MustCompile("[ ]+")
29+
2730
// 获取url对应的文章并根据规则进行解析
2831
func ParseArticle(articleUrl string, auto bool) (*model.Article, error) {
2932
articleUrl = strings.TrimSpace(articleUrl)
@@ -124,6 +127,8 @@ func ParseArticle(articleUrl string, auto bool) (*model.Article, error) {
124127
}
125128
content = strings.TrimSpace(content)
126129
txt := strings.TrimSpace(contentSelection.Text())
130+
txt = articleRe.ReplaceAllLiteralString(txt, " ")
131+
txt = articleSpaceRe.ReplaceAllLiteralString(txt, " ")
127132

128133
// 自动抓取,内容长度不能少于 300 字
129134
if auto && len(txt) < 300 {

websites/code/studygolang/static/css/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ html, body { background: #F2F2F2; font-family: "Helvetica Neue", Helvetica, Aria
7979
.sidebar .sb-content .cmt-list ul li .word .w-page { padding-top: 2px;font-family: "simsun";font-size: 12px;font-size: 1.2rem;color: #c1c1c1; }
8080
.sidebar .sb-content .cmt-list ul li .word .w-page a { color: #5f5e5e;margin-left: 5px;margin-right: 5px; }
8181
.sidebar .sb-content .cmt-list ul li .word .w-page a:hover { text-decoration: none; color: #F2733C; }
82-
.sidebar .sb-content .cmt-list ul li .word .w-comment { line-height: 18px;max-height: 36px;_height: 36px;color: #db6d4c;font-family: "simsun";font-size: 12px;font-size: 1.2rem;overflow: hidden;padding-top: 2px; }
82+
.sidebar .sb-content .cmt-list ul li .word .w-comment { line-height: 18px;max-height: 54px;_height: 54px;color: #db6d4c;font-family: "simsun";font-size: 12px;font-size: 1.2rem;overflow: hidden;padding-top: 2px; }
8383
.sidebar .sb-content .user-list ul li {width: 92px;text-align: center;margin-bottom: 8px;}
8484
.sidebar .sb-content .user-list ul li .name {text-overflow: clip;}
8585

0 commit comments

Comments
 (0)