Skip to content

Commit

Permalink
Merge pull request #129 from panigrc/feature/add-includesourcetitle-f…
Browse files Browse the repository at this point in the history
…ilter

Feature: Add includesourcetitle filter
  • Loading branch information
slurdge authored Mar 26, 2023
2 parents b4316fc + 902b28f commit 2906052
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ The available filters are as follows:
in your config file.

* includelink: Include the link of entries in the digest form
* includesourcetitle: Include source titles of entries in the digest form
* retrieve: Retrieves the full content from a goquery. E.g. you can use `retrieve(div.content)` to get the full excerpts of Next INpact's [LeBrief](https://www.nextinpact.com/lebrief/)
* language: Keep only the specified languages (best effort detection), use like this: `language(en,de)`
* untrack: Removes feedburner pixel tracking
Expand Down
7 changes: 5 additions & 2 deletions internal/goeland/fetch/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func fetchFeed(source *goeland.Source, feedLocation string, isFile bool, allowIn
return fmt.Errorf("cannot open or parse url: %s (%v)", feedLocation, err)
}
}

source.Title = feed.Title
source.URL = feed.Link

for _, item := range feed.Items {

entry := goeland.Entry{}
Expand Down Expand Up @@ -119,10 +123,9 @@ func fetchFeed(source *goeland.Source, feedLocation string, isFile bool, allowIn
hash.Write([]byte(entry.URL))
entry.UID = hex.EncodeToString(hash.Sum([]byte{}))
}
entry.Source = source
source.Entries = append(source.Entries, entry)
}
source.Title = feed.Title
source.URL = feed.Link
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions internal/goeland/filters/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var filters = map[string]filter{
to="Another string"
in your config file.`, filterReplace},
"includelink": {"Include the link of entries in the digest form", filterIncludeLink},
"includesourcetitle": {"Include source titles of the entries in the digest form. Useful for merge sources", filterIncludeSourceTitle},
"language": {"Keep only the specified languages (best effort detection), use like this: language(en,de)", filterLanguage},
"unseen": {"Keep only unseen entry", filterUnSeen},
"lebrief": {"Deprecated. Use retrieve(div.content) instead. Retrieves the full excerpts for Next INpact's Lebrief", filterLeBrief},
Expand Down Expand Up @@ -154,8 +155,13 @@ func filterDigestGeneric(source *goeland.Source, level int, useFirstEntryTitle b
if useFirstEntryTitle && len(source.Entries) > 0 {
digest.Title = source.Entries[0].Title
}
var previousSource *goeland.Source
content := ""
for _, entry := range source.Entries {
if entry.IncludeSourceTitle && previousSource != entry.Source {
content += fmt.Sprintf(`<h%d><a href="%s">%s</a></h%d>`, level - 1, entry.Source.URL, entry.Source.Title, level - 1)
previousSource = entry.Source
}
if entry.IncludeLink {
content += fmt.Sprintf(`<h%d><a href="%s">%s</a></h%d>`, level, entry.URL, entry.Title, level)
} else {
Expand Down Expand Up @@ -224,6 +230,12 @@ func filterIncludeLink(source *goeland.Source, params *filterParams) {
}
}

func filterIncludeSourceTitle(source *goeland.Source, params *filterParams) {
for i := range source.Entries {
source.Entries[i].IncludeSourceTitle = true
}
}

func filterEmbedImage(source *goeland.Source, params *filterParams) {
args := params.args
positions := []string{"top", "bottom", "left", "right"}
Expand Down
16 changes: 9 additions & 7 deletions internal/goeland/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import (

// Entry This represent an entry produced by a source
type Entry struct {
UID string
Title string
Content string
URL string
Date time.Time
IncludeLink bool
ImageURL string
UID string
Title string
Content string
URL string
Date time.Time
IncludeLink bool
IncludeSourceTitle bool
ImageURL string
Source *Source
}

// Source ...
Expand Down

0 comments on commit 2906052

Please sign in to comment.