summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authornytpu <alex@nytpu.com>2021-05-03 10:26:52 -0600
committernytpu <alex@nytpu.com>2021-05-03 10:26:52 -0600
commit6b7f50a2d9fedc4286d451f2756964cf366111f1 (patch)
tree791b0dd1c15b8c31c96ef8e0c95da7988151e285 /core
parent28fd3d7b240971627e2196b228297397904f4e87 (diff)
deduplicate code and unify footer and generation time
Diffstat (limited to 'core')
-rw-r--r--core/entries.go42
1 files changed, 25 insertions, 17 deletions
diff --git a/core/entries.go b/core/entries.go
index f1bb092..74fb241 100644
--- a/core/entries.go
+++ b/core/entries.go
@@ -72,10 +72,31 @@ func toLocalDay(t time.Time) time.Time {
return time.Date(t.Year(), t.Month(), t.Day(), 0, 0, 0, 0, t.Location())
}
+// genDay returns a string with the current date and time
+func genDay() string {
+ return fmt.Sprintf("Generated on %s\n", time.Now().Format("2006-01-02 at 15:04 MST"))
+}
+
+// agplCompliance returns a string containing a footer linking to the source code
+func agplCompilance() string {
+ return fmt.Sprintf(`
+
+---
+
+=> https://git.nytpu.com/comitium/about/ aggregated using comitium v%s
+`,
+ Version,
+ )
+
+}
+
func (d *FullData) WriteSubs(dataPath string) error {
path := filepath.Join(dataPath, "subscriptions.gmi.new")
- rawPage := `# subscribed feeds
+ rawPage := "# subscribed feeds\n\n"
+ rawPage += genDay()
+ rawPage += `
+
## Feeds
Gemini, Atom, RSS, and JSON feeds from all over.
@@ -110,12 +131,7 @@ Watching these pages for any changes that occur.
}
d.PagesMu.RUnlock()
- rawPage += `
-
----
-
-=> https://git.nytpu.com/comitium/about/ aggregated using comitium
-`
+ rawPage += agplCompilance()
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
if err != nil {
@@ -135,7 +151,7 @@ func (d *FullData) WriteFeed(dataPath string) error {
pe := d.getPageEntries()
rawPage += fmt.Sprintf("\n=> subscriptions.gmi Currently aggregating %d capsules, gopherholes, and websites.\n\n", len(d.Feeds)+len(d.Pages))
d.RUnlock()
- rawPage += fmt.Sprintf("Generated on %s\n", time.Now().Format("2006-01-02 at 15:04 MST"))
+ rawPage += genDay()
if len(pe.Entries) > 0 {
curDay := toLocalDay(pe.Entries[0].Published)
@@ -156,15 +172,7 @@ func (d *FullData) WriteFeed(dataPath string) error {
}
}
- rawPage += fmt.Sprintf(`
-
----
-
-=> https://git.nytpu.com/comitium/about/ aggregated using comitium v%s
-`,
- Version,
- )
-
+ rawPage += agplCompilance()
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
if err != nil {
return err