flounder

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

commit 9c90564237faf53d8ee70a963cfed465d372bdd3
parent cc103f75153a3c1a04b48bd6528ef2c22325cdeb
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 21 Feb 2021 15:38:55 -0800

Cleanup gemfeeeds

Diffstat:
Mgemfeed.go | 61++++++++-----------------------------------------------------
Mtemplates/edit_file.html | 13+++----------
2 files changed, 11 insertions(+), 63 deletions(-)

diff --git a/gemfeed.go b/gemfeed.go @@ -4,14 +4,12 @@ package main import ( "bufio" - "fmt" "github.com/gorilla/feeds" - "io" + "io/ioutil" "net/url" "os" "path" "path/filepath" - "regexp" "sort" "strings" "time" @@ -36,6 +34,7 @@ func (gf *Gemfeed) toAtomFeed() string { Title: fe.Title, Link: &feeds.Link{Href: fe.Url.String()}, // Rel=alternate? Created: fe.Date, // Updated not created? + Content: fe.Content, }) } res, _ := feed.ToAtom() @@ -49,6 +48,7 @@ type FeedEntry struct { DateString string Feed *Gemfeed File string // TODO refactor + Content string } func urlFromPath(fullPath string) url.URL { @@ -106,6 +106,11 @@ func generateFeedFromUser(user string) *Gemfeed { } break } + content, err := ioutil.ReadFile(thepath) + if err != nil { + return nil + } + entry.Content = string(content) entry.File = getLocalPath(thepath) u := urlFromPath(thepath) entry.Url = &u @@ -122,53 +127,3 @@ func generateFeedFromUser(user string) *Gemfeed { }) return &feed } - -var GemfeedRegex = regexp.MustCompile(`=>\s*(\S+)\s([0-9]{4}-[0-9]{2}-[0-9]{2})\s?-?\s?(.*)`) - -// Parsed Gemfeed text Returns error if not a gemfeed -// Doesn't sort output -// Doesn't get posts dated in the future -// if limit > -1 -- limit how many we are getting -func ParseGemfeed(text io.Reader, baseUrl url.URL, limit int) (*Gemfeed, error) { - scanner := bufio.NewScanner(text) - gf := Gemfeed{} - for scanner.Scan() { - if limit > -1 && len(gf.Entries) >= limit { - break - } - line := scanner.Text() - if gf.Title == "" && strings.HasPrefix(line, "#") && !strings.HasPrefix(line, "##") { - gf.Title = strings.Trim(line[1:], " \t") - } else if strings.HasPrefix(line, "=>") { - matches := GemfeedRegex.FindStringSubmatch(line) - if len(matches) == 4 { - parsedUrl, err := url.Parse(matches[1]) - if err != nil { - continue - } - date, err := time.Parse("2006-01-02", matches[2]) - if err != nil { - continue - } - title := matches[3] - if parsedUrl.Host == "" { - // Is relative link - parsedUrl.Host = baseUrl.Host - parsedUrl.Path = path.Join(path.Dir(baseUrl.Path), parsedUrl.Path) - } - parsedUrl.Scheme = "" - if time.Now().After(date) { - fe := FeedEntry{title, parsedUrl, date, matches[2], &gf, ""} - if fe.Title == "" { - fe.Title = "(Untitled)" - } - gf.Entries = append(gf.Entries, fe) - } - } - } - } - if len(gf.Entries) == 0 { - return nil, fmt.Errorf("No Gemfeed entries found") - } - return &gf, nil -} diff --git a/templates/edit_file.html b/templates/edit_file.html @@ -5,15 +5,7 @@ <input type="text" value="{{.FileName}}" id="rename" name="rename"> {{ if .IsText }} {{ if .IsGemini }} -<form action="/delete/{{.FileName}}" method="POST" class="inline"> - <input - class="button delete" - type="submit" - onclick="return confirm('Are you sure you want to delete this file?');" - value="delete" - /> - </form> - <p> + <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> </p> {{ end }} @@ -36,5 +28,6 @@ {{ . }} {{ end }} </div> -</form> +</form> + {{template "footer" .}}