Reworked fixers and NNTP output: now later does dehtmlifying, not fixers. They work with HTML data.
This commit is contained in:
+9
-3
@@ -12,9 +12,15 @@ var fixers = map[string]fixerFunc{
|
||||
// Fix fixes title and body depending on site parsed.
|
||||
func Fix(domain string, feedItem *gofeed.Item) (string, string) {
|
||||
fixer, found := fixers[domain]
|
||||
if !found {
|
||||
return feedItem.Title, feedItem.Description
|
||||
if found {
|
||||
return fixer(feedItem)
|
||||
}
|
||||
|
||||
return fixer(feedItem)
|
||||
// We should check WHAT IS LONGER - description or content.
|
||||
bodyData := feedItem.Description
|
||||
if len(feedItem.Content) > len(feedItem.Description) {
|
||||
bodyData = feedItem.Content
|
||||
}
|
||||
|
||||
return feedItem.Title, bodyData
|
||||
}
|
||||
|
||||
+1
-13
@@ -1,21 +1,9 @@
|
||||
package fixers
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
|
||||
"github.com/mmcdole/gofeed"
|
||||
"github.com/prodigeris/html2text"
|
||||
)
|
||||
|
||||
func githubFixer(item *gofeed.Item) (string, string) {
|
||||
plainTextBody, err := html2text.FromString(item.Content, html2text.Options{
|
||||
PrettyTables: true,
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("Failed to de-HTMLify github body!", "error", err.Error())
|
||||
|
||||
return item.Title, item.Content
|
||||
}
|
||||
|
||||
return item.Title, plainTextBody
|
||||
return item.Title, item.Content
|
||||
}
|
||||
|
||||
+1
-12
@@ -1,26 +1,15 @@
|
||||
package fixers
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/mmcdole/gofeed"
|
||||
"github.com/prodigeris/html2text"
|
||||
)
|
||||
|
||||
func opennetFixer(item *gofeed.Item) (string, string) {
|
||||
oldBody, err := html2text.FromString(item.Description, html2text.Options{
|
||||
PrettyTables: true,
|
||||
})
|
||||
if err != nil {
|
||||
slog.Error("Failed to de-HTMLify opennet body!", "error", err.Error())
|
||||
|
||||
return item.Title, item.Description
|
||||
}
|
||||
|
||||
newBody := &strings.Builder{}
|
||||
|
||||
for line := range strings.Lines(oldBody) {
|
||||
for line := range strings.Lines(item.Description) {
|
||||
if strings.HasPrefix(line, "Источник") {
|
||||
continue
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user