Skip to content

Commit

Permalink
feat: add a way to have toc & link only digest with toc filter. fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
slurdge committed Nov 13, 2022
1 parent 068acd4 commit 037a7c4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/goeland/fetch/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func fetchFeed(source *goeland.Source, feedLocation string, isFile bool) error {
source.Entries = append(source.Entries, entry)
}
source.Title = feed.Title
source.URL = feed.Link
return nil
}

Expand Down
4 changes: 3 additions & 1 deletion internal/goeland/fetch/imgur.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package fetch

import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"time"
Expand Down Expand Up @@ -81,6 +82,7 @@ func fetchImgurTag(source *goeland.Source, tag string, sort string) error {
entry.URL = item.Link
source.Entries = append(source.Entries, entry)
}
source.Title = "Imgur pictures for tag #" + tag
source.Title = fmt.Sprintf("Imgur pictures for tag #%s", tag)
source.URL = fmt.Sprintf("https://imgur.com/t/%s", tag)
return nil
}
26 changes: 26 additions & 0 deletions internal/goeland/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var filters = map[string]filter{
"untrack": {"Removes feedburner pixel tracking", filterUntrack},
"reddit": {"Better formatting for reddit rss", filterReddit},
"sanitize": {"Sanitize the content of entries (to be used in case of --unsafe-no-sanitize-filter flag)", filterSanitize},
"toc": {"Create a table of content entry for all the entries", filterToc},
}

func GetFiltersHelp() string {
Expand Down Expand Up @@ -244,6 +245,31 @@ func filterEmbedImage(source *goeland.Source, params *filterParams) {
}
}

func filterToc(source *goeland.Source, params *filterParams) {
toc := goeland.Entry{}
args := params.args
if len(args) > 0 && strings.ToLower(args[0]) == "nameastitle" {
toc.Title = fmt.Sprintf(`<a href="%s">%s</a>`, source.URL, source.Title)
} else {
toc.Title = fmt.Sprintf("Table of Content for %s", source.Title)
}
content := "<ul>"
for _, entry := range source.Entries {
if entry.IncludeLink {
content += fmt.Sprintf(`<li><a href="%s">%s</a></li>`, entry.URL, entry.Title)
} else {
content += fmt.Sprintf("<li>%s</li>", entry.Title)
}
}
content += "</ul>"
h := sha256.New()
h.Write([]byte(content))
toc.UID = fmt.Sprintf("%x", h.Sum(nil))
toc.Date = time.Now()
toc.Content = content
source.Entries = append([]goeland.Entry{toc}, source.Entries...)
}

// FilterSource filters a source according to the config
func FilterSource(source *goeland.Source, config config.Provider) {
log.Infof("Retrieved %v feeds for source %v", len(source.Entries), source.Name)
Expand Down
5 changes: 5 additions & 0 deletions internal/goeland/i18n/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@ func init() {
message.SetString(language.BritishEnglish, "Digest for %s", "Digest for %s")
message.SetString(language.AmericanEnglish, "Digest for %s", "Digest for %s")
message.SetString(language.French, "Digest for %s", "Abrégé de %s")

message.SetString(language.BritishEnglish, "Imgur pictures for tag #%s", "Imgur pictures for tag #%s")
message.SetString(language.AmericanEnglish, "Imgur pictures for tag #%s", "Imgur pictures for tag #%s")
message.SetString(language.French, "Imgur pictures for tag #%s", "Images Imgur pour le tag#%s")

}
1 change: 1 addition & 0 deletions internal/goeland/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ type Entry struct {
type Source struct {
Name string
Title string
URL string
Entries []Entry
}

0 comments on commit 037a7c4

Please # to comment.