summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-05-19 08:00:21 -0600
committernytpu <alex@nytpu.com>2021-05-19 08:02:28 -0600
commitf9d88722606e5c2570fe4237a64b5a1b22bf1789 (patch)
tree49db52ecb6a468f3340256166299f0978990b608
parentac86835f6dcaaf4c42e0c1f2e4ff5eae24b9ff14 (diff)
add core.HistoryDays for variable history kept
-rw-r--r--comitium.go2
-rw-r--r--core/core.go8
-rw-r--r--core/structs.go2
-rw-r--r--fetch/gemini.go2
4 files changed, 10 insertions, 4 deletions
diff --git a/comitium.go b/comitium.go
index 8355870..8228510 100644
--- a/comitium.go
+++ b/comitium.go
@@ -68,7 +68,7 @@ func main() {
// make sure it exists so we can start working with files in it
os.MkdirAll(dataPath, os.ModePerm)
- err := core.Init(dataPath, localizer)
+ err := core.Init(dataPath, localizer, 0)
if err != nil {
fmt.Fprintf(os.Stderr, core.TranslateStringLocalizer(
localizer, "%s\n",
diff --git a/core/core.go b/core/core.go
index 21487f6..ab1430f 100644
--- a/core/core.go
+++ b/core/core.go
@@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"sync"
+ "time"
"golang.nytpu.com/comitium/localizations"
)
@@ -40,11 +41,14 @@ var (
// Timeout for requests
var Timeout int
+// Number of days of history to keep
+var HistoryDays time.Time
+
var Localizer *localizations.Localizer
// have to do this instead of the automatically called init() because
// initialization stuff requires parsing of command line args first
-func Init(dataPath string, localizer *localizations.Localizer) error {
+func Init(dataPath string, localizer *localizations.Localizer, days int) error {
Localizer = localizer
// initialize comitium.json & data maps
@@ -98,6 +102,8 @@ func Init(dataPath string, localizer *localizations.Localizer) error {
}
Footer = fmt.Sprintf("\n\n%s", footer)
+ HistoryDays = time.Now().AddDate(0, 0, -days)
+
Timeout = 10
return nil
diff --git a/core/structs.go b/core/structs.go
index 1244567..f9b738b 100644
--- a/core/structs.go
+++ b/core/structs.go
@@ -83,7 +83,7 @@ func GofeedConvert(f *gofeed.Feed, title string) (*Feed, error) {
item.Link = v.Link
// don't insert if older than 1 year
- if item.Published.After(time.Now().AddDate(-1, 0, 0)) {
+ if item.Published.After(HistoryDays) {
new.Items = append(new.Items, item)
}
}
diff --git a/fetch/gemini.go b/fetch/gemini.go
index dcb6229..2608468 100644
--- a/fetch/gemini.go
+++ b/fetch/gemini.go
@@ -98,7 +98,7 @@ func geminiFeed(data *core.FullData, remote string, title string) error {
item.Link = link.String()
// don't insert if older than 1 year
- if item.Published.After(time.Now().AddDate(-1, 0, 0)) {
+ if item.Published.After(core.HistoryDays) {
feed.Items = append(feed.Items, item)
}
}