1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-06-27 16:36:00 +00:00

Added new rewrite rules add_hn_links_using_hack and add_hn_links_using_opener to open HN comments with iOS apps

This commit is contained in:
Adriano Di Luzio 2023-09-23 22:54:48 +02:00 committed by GitHub
parent ace2699e79
commit 54cb8fa028
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 0 deletions

View file

@ -12,6 +12,7 @@ import (
"strings"
"miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/logger"
"github.com/PuerkitoBio/goquery"
"github.com/yuin/goldmark"
@ -321,6 +322,55 @@ func decodeBase64Content(entryContent string) string {
}
}
func addHackerNewsLinksUsing(entryContent, app string) string {
doc, err := goquery.NewDocumentFromReader(strings.NewReader(entryContent))
if err != nil {
return entryContent
}
hn_prefix := "https://news.ycombinator.com/"
matches := doc.Find(`a[href^="` + hn_prefix + `"]`)
if matches.Length() > 0 {
matches.Each(func(i int, a *goquery.Selection) {
hrefAttr, _ := a.Attr("href")
hn_uri, err := url.Parse(hrefAttr)
if err != nil {
return
}
if app == "opener" {
params := url.Values{}
params.Add("url", hn_uri.String())
url := url.URL{
Scheme: "opener",
Host: "x-callback-url",
Path: "show-options",
RawQuery: params.Encode(),
}
open_with_opener := `<a href="` + url.String() + `">Open with Opener</a>`
a.Parent().AppendHtml(" " + open_with_opener)
} else if app == "hack" {
url := strings.Replace(hn_uri.String(), hn_prefix, "hack://", 1)
open_with_hack := `<a href="` + url + `">Open with HACK</a>`
a.Parent().AppendHtml(" " + open_with_hack)
} else {
logger.Error("[openHackerNewsLinksWith] unknown app provided: %q", app)
return
}
})
output, _ := doc.Find("body").First().Html()
return output
}
return entryContent
}
func parseMarkdown(entryContent string) string {
var sb strings.Builder
md := goldmark.New(