Remove following page Extraneous
alex wennerberg alex@alexwennerberg.com
Thu, 04 Feb 2021 16:35:24 -0800
7 files changed,
1 insertions(+),
156 deletions(-)
D
feed.go
@@ -1,140 +0,0 @@
-package main - -import ( - "bufio" - "fmt" - "git.sr.ht/~adnano/go-gemini" - "github.com/mmcdole/gofeed" - "log" - "net/http" - "net/url" - "os" - "path" - "sort" - "time" -) - -const followingPath = "following.txt" -const followingFile = "following.gmi" - -// TODO also get gemini, gemfeed - -func feedsWorker() { - log.Println("Starting feeds worker") - for { - time.Sleep(time.Hour * 1) - users, err := getActiveUserNames() - if err != nil { - // Handle error somehow - fmt.Println(err) - continue - } - for _, user := range users { - writeAllFeeds(user) - } - } -} - -func writeAllFeeds(user string) error { - // Open file - file, err := os.Open(path.Join(getUserDirectory(user), followingPath)) - log.Println("Writing feeds for user " + user) - defer file.Close() - - feedData := []*gofeed.Feed{} - if err == nil { - scanner := bufio.NewScanner(file) - count := 1 - for scanner.Scan() { - if count > 100 { // max number of lines - break - } - count = count + 1 - feedURL := scanner.Text() - parsed, err := url.Parse(feedURL) - var feed *gofeed.Feed - fp := gofeed.NewParser() - if err != nil { - log.Println("Invalid url " + feedURL) - } - if parsed.Scheme == "gemini" { - client := gemini.Client{ - Timeout: 10 * time.Second, - } - res, err := client.Get(feedURL) - defer res.Body.Close() - if err != nil { - log.Println(err) - continue - } - if err != nil { - log.Println(err) - continue - } - feed, err = fp.Parse(res.Body) - if err != nil { - log.Println(err) - continue - } - } else { - // TODO if scheme is gemini and filetype is gemini... gemtext - // TODO rate limit etc - fp.Client = &http.Client{ - Timeout: 10 * time.Second, - } - feed, err = fp.ParseURL(feedURL) - if err != nil { - log.Println("Error getting feed " + feedURL) - continue - } - } - log.Println("Got feed data from " + feedURL) - feedData = append(feedData, feed) - } - if err := scanner.Err(); err != nil { - return err - } - } - // Aggregate and sort by date - type feedPlusItem struct { - Feed *gofeed.Feed - FeedItem *gofeed.Item - Date string - } - data := struct { - User string - FeedItems []feedPlusItem - }{} - data.User = user - for _, feed := range feedData { - for _, item := range feed.Items { - if item.UpdatedParsed == nil { - item.UpdatedParsed = item.PublishedParsed - } - if item.UpdatedParsed != nil { - date := item.UpdatedParsed.Format("2006-01-02") - data.FeedItems = append(data.FeedItems, feedPlusItem{feed, item, date}) - } - } - } - sort.Slice(data.FeedItems, func(i, j int) bool { - return data.FeedItems[i].FeedItem.UpdatedParsed.After(*data.FeedItems[j].FeedItem.UpdatedParsed) - }) - maxItems := 100 - if len(data.FeedItems) > maxItems { - data.FeedItems = data.FeedItems[:maxItems] - } - - outputf, err := os.OpenFile(path.Join(getUserDirectory(user), followingFile), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755) - defer outputf.Close() - if err != nil { - return err - } - err = gt.ExecuteTemplate(outputf, "following.gmi", data) - if err != nil { - return err - } - // convert to gemini template - // write template to file - return nil -}
M
templates/edit_file.html
→
templates/edit_file.html
@@ -4,9 +4,6 @@ <form id="edit-form" action="/edit/{{.FileName}}" method="POST">
<label for="rename">Rename:</label> <input type="text" value="{{.FileName}}" id="rename" name="rename"> {{ if .IsText }} - {{ if eq .FileName "following.txt" }} - <p><em>Add URLs here of feeds you would like to follow. They will be available at <a href="//{{.AuthUser.Username}}.{{.Host}}/following.gmi">following.gmi</a>. For more information, see <a href="https://admin.flounder.online/following-pages.gmi">Following Feeds</a></em></p> - {{ end}} {{ if .IsGemini }} <p> <em>For help with the Gemini markup format, see the <a href="https://admin.flounder.online/gemini_text_guide.gmi">Gemtext Guide</a></em>
D
templates/following.gmi
@@ -1,9 +0,0 @@
-# {{.User}}'s Following -A collection of feeds that {{.User}} is following -=> following.txt - -{{ range .FeedItems }} -=> {{.FeedItem.Link}} {{.Date}} {{.Feed.Title}} -- {{.FeedItem.Title}}{{ end }} - -For more information about setting up this page, see: -=> //admin.flounder.online/following-feeds.gmi
M
templates/my_site.html
→
templates/my_site.html
@@ -12,7 +12,6 @@ <br>
<br> <h3>Your files:</h3> {{ define "file" }} -{{ if ne .Name "following.gmi" }} <tr> <div> {{ if gt (len .Children) 0 }}