flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 1f6bec815a3a0138a1c9b5d2a61a673894fe1689
parent 1a685e147c66e68bc6e5bf9e662a52513db6d616
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Thu,  4 Feb 2021 16:35:24 -0800

Remove following page

Extraneous

Diffstat:
Mdb.go | 2+-
Dfeed.go | 140-------------------------------------------------------------------------------
Mmain.go | 1-
Mtemplates/edit_file.html | 3---
Dtemplates/following.gmi | 9---------
Mtemplates/my_site.html | 1-
Mtemplates/nav.html | 1-
7 files changed, 1 insertion(+), 156 deletions(-)

diff --git a/db.go b/db.go @@ -156,7 +156,7 @@ func getIndexFiles(admin bool) ([]*File, error) { // cache this function return filepath.SkipDir } // make this do what it should - if !info.IsDir() && info.Name() != followingFile { + if !info.IsDir() { res := fileFromPath(thepath) result = append(result, &res) } diff --git a/feed.go b/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 -} diff --git a/main.go b/main.go @@ -46,7 +46,6 @@ func main() { if c.AnalyticsDBFile != "" { go dumpLogsWorker() } - go feedsWorker() switch args[0] { case "serve": diff --git a/templates/edit_file.html b/templates/edit_file.html @@ -4,9 +4,6 @@ <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> diff --git a/templates/following.gmi b/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 diff --git a/templates/my_site.html b/templates/my_site.html @@ -12,7 +12,6 @@ For some help building your site, check out the <a href="https://admin.flounder. <br> <h3>Your files:</h3> {{ define "file" }} -{{ if ne .Name "following.gmi" }} <tr> <div> {{ if gt (len .Children) 0 }} diff --git a/templates/nav.html b/templates/nav.html @@ -1,7 +1,6 @@ <nav> <a href="/">home</a> {{ if .AuthUser.LoggedIn }} - <a href="//{{.AuthUser.Username}}.{{.Config.Host}}/following.gmi">following</a> <a href="/my_site">my_site</a> <a href="/me">me</a> {{ if .AuthUser.IsAdmin }}