deduplicate code and unify footer and generation time
This commit is contained in:
+25
-17
@@ -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())
|
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 {
|
func (d *FullData) WriteSubs(dataPath string) error {
|
||||||
path := filepath.Join(dataPath, "subscriptions.gmi.new")
|
path := filepath.Join(dataPath, "subscriptions.gmi.new")
|
||||||
|
|
||||||
rawPage := `# subscribed feeds
|
rawPage := "# subscribed feeds\n\n"
|
||||||
|
rawPage += genDay()
|
||||||
|
rawPage += `
|
||||||
|
|
||||||
## Feeds
|
## Feeds
|
||||||
|
|
||||||
Gemini, Atom, RSS, and JSON feeds from all over.
|
Gemini, Atom, RSS, and JSON feeds from all over.
|
||||||
@@ -110,12 +131,7 @@ Watching these pages for any changes that occur.
|
|||||||
}
|
}
|
||||||
d.PagesMu.RUnlock()
|
d.PagesMu.RUnlock()
|
||||||
|
|
||||||
rawPage += `
|
rawPage += agplCompilance()
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
=> https://git.nytpu.com/comitium/about/ aggregated using comitium
|
|
||||||
`
|
|
||||||
|
|
||||||
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
|
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -135,7 +151,7 @@ func (d *FullData) WriteFeed(dataPath string) error {
|
|||||||
pe := d.getPageEntries()
|
pe := d.getPageEntries()
|
||||||
rawPage += fmt.Sprintf("\n=> subscriptions.gmi Currently aggregating %d capsules, gopherholes, and websites.\n\n", len(d.Feeds)+len(d.Pages))
|
rawPage += fmt.Sprintf("\n=> subscriptions.gmi Currently aggregating %d capsules, gopherholes, and websites.\n\n", len(d.Feeds)+len(d.Pages))
|
||||||
d.RUnlock()
|
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 {
|
if len(pe.Entries) > 0 {
|
||||||
curDay := toLocalDay(pe.Entries[0].Published)
|
curDay := toLocalDay(pe.Entries[0].Published)
|
||||||
@@ -156,15 +172,7 @@ func (d *FullData) WriteFeed(dataPath string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rawPage += fmt.Sprintf(`
|
rawPage += agplCompilance()
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
=> https://git.nytpu.com/comitium/about/ aggregated using comitium v%s
|
|
||||||
`,
|
|
||||||
Version,
|
|
||||||
)
|
|
||||||
|
|
||||||
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
|
err := ioutil.WriteFile(path, []byte(rawPage), 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user