mirror of
https://github.com/miniflux/v2.git
synced 2025-07-22 17:18:37 +00:00
Improve content scraper
This commit is contained in:
parent
827683ab59
commit
c6d9eb3614
7 changed files with 39 additions and 3 deletions
|
@ -5,6 +5,7 @@
|
|||
package rewrite
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
|
@ -38,3 +39,10 @@ func addYoutubeVideo(entryURL, entryContent string) string {
|
|||
}
|
||||
return entryContent
|
||||
}
|
||||
|
||||
func addPDFLink(entryURL, entryContent string) string {
|
||||
if strings.HasSuffix(entryURL, ".pdf") {
|
||||
return fmt.Sprintf(`<a href="%s">PDF</a><br>%s`, entryURL, entryContent)
|
||||
}
|
||||
return entryContent
|
||||
}
|
||||
|
|
|
@ -18,12 +18,16 @@ func Rewriter(entryURL, entryContent, customRewriteRules string) string {
|
|||
}
|
||||
|
||||
rules := strings.Split(rulesList, ",")
|
||||
rules = append(rules, "add_pdf_download_link")
|
||||
|
||||
for _, rule := range rules {
|
||||
switch strings.TrimSpace(rule) {
|
||||
case "add_image_title":
|
||||
entryContent = addImageTitle(entryURL, entryContent)
|
||||
case "add_youtube_video":
|
||||
entryContent = addYoutubeVideo(entryURL, entryContent)
|
||||
case "add_pdf_download_link":
|
||||
entryContent = addPDFLink(entryURL, entryContent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,3 +58,13 @@ func TestRewriteWithXkcdAndNoImage(t *testing.T) {
|
|||
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRewriteWithPDFLink(t *testing.T) {
|
||||
description := "test"
|
||||
output := Rewriter("https://example.org/document.pdf", description, ``)
|
||||
expected := `<a href="https://example.org/document.pdf">PDF</a><br>test`
|
||||
|
||||
if expected != output {
|
||||
t.Errorf(`Not expected output: got "%s" instead of "%s"`, output, expected)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue