all repos — flounder @ 1f6bec815a3a0138a1c9b5d2a61a673894fe1689

A small site builder for the Gemini protocol

Remove following page

Extraneous
alex wennerberg alex@alexwennerberg.com
Thu, 04 Feb 2021 16:35:24 -0800
commit

1f6bec815a3a0138a1c9b5d2a61a673894fe1689

parent

1a685e147c66e68bc6e5bf9e662a52513db6d616

7 files changed, 1 insertions(+), 156 deletions(-)

jump to
M db.godb.go

@@ -156,7 +156,7 @@ if !admin && info.IsDir() && info.Name() == HiddenFolder {

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) }
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 main.gomain.go

@@ -46,7 +46,6 @@ // Background workers

if c.AnalyticsDBFile != "" { go dumpLogsWorker() } - go feedsWorker() switch args[0] { case "serve":
M templates/edit_file.htmltemplates/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.htmltemplates/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 }}
M templates/nav.htmltemplates/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 }}