Skip to content

Commit

Permalink
Highlight new articles in a virtual feed
Browse files Browse the repository at this point in the history
Make a virtual feed (called `new`) which has symlinks to the most
recently downloaded articles during an `update` or a `refetch`.
  • Loading branch information
mattpep committed Nov 28, 2022
1 parent 85d5e13 commit 31fc925
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 8 additions & 1 deletion feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type Feed struct {

var wg sync.WaitGroup
var isAllUpdate bool

const newArticleDirectory = "new"
const maxFileNameLength = 255

func truncateString(s string, n int) string {
Expand Down Expand Up @@ -61,7 +63,7 @@ func UpdateFeed(name string, deleteFiles bool) {

articlePath := Config.FeedDirectory + "/" + name + "/" + truncateString(strings.ReplaceAll(item.Title, "/", ""), maxFileNameLength)
if _, err := os.Stat(articlePath); err == nil {
log.Info("Article " + articlePath + " already exists - skipping download")
log.Debug("Article " + articlePath + " already exists - skipping download")
skipCount++
continue
}
Expand All @@ -77,6 +79,11 @@ func UpdateFeed(name string, deleteFiles bool) {
continue
}
downloadCount++
NewLinkPath := Config.FeedDirectory + "/" + newArticleDirectory + "/" + truncateString(strings.ReplaceAll(item.Title, "/", ""), maxFileNameLength)
err = os.Symlink(articlePath, NewLinkPath)
if err != nil {
log.Error("Could not create symlink for newly downloaded article " + articlePath)
}
}
log.Info(strconv.Itoa(downloadCount) + " articles fetched from feed '" + name + "' (" + strconv.Itoa(skipCount) + " already seen, " + strconv.Itoa(len(feed.Items)) + " total in feed)")
if isAllUpdate {
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func main() {
Aliases: []string{"r"},
Usage: "delete and refetch given feed(s) or all feeds if no argument is given",
Action: func(cCtx *cli.Context) error {
InitialiseNewArticleDirectory()
if cCtx.Args().Len() == 0 {
UpdateAllFeeds(true)
}
Expand All @@ -81,6 +82,7 @@ func main() {
Aliases: []string{"u"},
Usage: "update given feed(s) or all feeds if no argument is given",
Action: func(cCtx *cli.Context) error {
InitialiseNewArticleDirectory()
if cCtx.Args().Len() == 0 {
UpdateAllFeeds(false)
}
Expand Down

0 comments on commit 31fc925

Please sign in to comment.