Reworked fixers and NNTP output: now later does dehtmlifying, not fixers. They work with HTML data.
This commit is contained in:
@@ -6,3 +6,4 @@ _build
|
|||||||
dist
|
dist
|
||||||
.task
|
.task
|
||||||
TASKS_NOTES.md
|
TASKS_NOTES.md
|
||||||
|
config.test.json
|
||||||
|
|||||||
+9
-3
@@ -12,9 +12,15 @@ var fixers = map[string]fixerFunc{
|
|||||||
// Fix fixes title and body depending on site parsed.
|
// Fix fixes title and body depending on site parsed.
|
||||||
func Fix(domain string, feedItem *gofeed.Item) (string, string) {
|
func Fix(domain string, feedItem *gofeed.Item) (string, string) {
|
||||||
fixer, found := fixers[domain]
|
fixer, found := fixers[domain]
|
||||||
if !found {
|
if found {
|
||||||
return feedItem.Title, feedItem.Description
|
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
|
package fixers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
|
||||||
|
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
"github.com/prodigeris/html2text"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func githubFixer(item *gofeed.Item) (string, string) {
|
func githubFixer(item *gofeed.Item) (string, string) {
|
||||||
plainTextBody, err := html2text.FromString(item.Content, html2text.Options{
|
return item.Title, item.Content
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-12
@@ -1,26 +1,15 @@
|
|||||||
package fixers
|
package fixers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log/slog"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/mmcdole/gofeed"
|
"github.com/mmcdole/gofeed"
|
||||||
"github.com/prodigeris/html2text"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func opennetFixer(item *gofeed.Item) (string, string) {
|
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{}
|
newBody := &strings.Builder{}
|
||||||
|
|
||||||
for line := range strings.Lines(oldBody) {
|
for line := range strings.Lines(item.Description) {
|
||||||
if strings.HasPrefix(line, "Источник") {
|
if strings.HasPrefix(line, "Источник") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -9,6 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/prodigeris/html2text"
|
||||||
"go.dev.pztrn.name/rsser/configuration"
|
"go.dev.pztrn.name/rsser/configuration"
|
||||||
"go.dev.pztrn.name/rsser/outputs"
|
"go.dev.pztrn.name/rsser/outputs"
|
||||||
)
|
)
|
||||||
@@ -110,7 +111,15 @@ func (c *nntp) Do(dest, feedName, url, title, body string) error {
|
|||||||
"Content-Transfer-Encoding": "7bit",
|
"Content-Transfer-Encoding": "7bit",
|
||||||
}
|
}
|
||||||
|
|
||||||
body = "URL: " + url + "\n\n" + body
|
// NNTP/Usenet do not want HTML things.
|
||||||
|
plainTextBody, err := html2text.FromString(body, html2text.Options{
|
||||||
|
PrettyTables: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to de-HTMLify body: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
body = "URL: " + url + "\n\n" + plainTextBody
|
||||||
|
|
||||||
if err := c.postArticle(headers, body); err != nil {
|
if err := c.postArticle(headers, body); err != nil {
|
||||||
return fmt.Errorf("Do: %w", err)
|
return fmt.Errorf("Do: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user