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

Skip to content

Commit ad866e7

Browse files
committed
支持正在表达式获取作者信息
1 parent 0855e81 commit ad866e7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/logic/article.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ func (self ArticleLogic) ParseArticle(ctx context.Context, articleUrl string, au
114114

115115
author = strings.TrimSpace(author)
116116
authorTxt = strings.TrimSpace(authorSelection.Text())
117+
} else if strings.HasPrefix(rule.Author, "/") {
118+
// 正则表达式
119+
re, err := regexp.Compile(rule.Author[1:])
120+
if err != nil {
121+
logger.Errorln("author regexp error:", err)
122+
return nil, err
123+
}
124+
body, _ := doc.Find("body").Html()
125+
authorResult := re.FindStringSubmatch(body)
126+
if len(authorResult) < 2 {
127+
logger.Errorln("no author found:", rule.Domain)
128+
return nil, errors.New("no author found!")
129+
}
130+
131+
author = authorResult[1]
132+
authorTxt = author
117133
} else {
118134
// 某些个人博客,页面中没有作者的信息,因此,规则中 author 即为 作者
119135
author = rule.Author

src/logic/uploader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (this *UploaderLogic) TransferUrl(ctx context.Context, origUrl string, pref
188188
}
189189

190190
if !strings.HasPrefix(origUrl, "http") {
191-
origUrl = "https:"+origUrl
191+
origUrl = "https:" + origUrl
192192
}
193193

194194
resp, err := http.Get(origUrl)

0 commit comments

Comments
 (0)