all repos — flounder @ 9c90564237faf53d8ee70a963cfed465d372bdd3

A small site builder for the Gemini protocol

Cleanup gemfeeeds
alex wennerberg alex@alexwennerberg.com
Sun, 21 Feb 2021 15:38:55 -0800
commit

9c90564237faf53d8ee70a963cfed465d372bdd3

parent

cc103f75153a3c1a04b48bd6528ef2c22325cdeb

2 files changed, 11 insertions(+), 63 deletions(-)

jump to
M gemfeed.gogemfeed.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 @@ feed.Items = append(feed.Items, &feeds.Item{

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 @@ Date time.Time

DateString string Feed *Gemfeed File string // TODO refactor + Content string } func urlFromPath(fullPath string) url.URL {

@@ -106,6 +106,11 @@ entry.Title = "[" + title + "...]"

} 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 @@ return feed.Entries[i].Date.After(feed.Entries[j].Date)

}) 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 -}
M templates/edit_file.htmltemplates/edit_file.html

@@ -5,15 +5,7 @@ <label for="rename">Rename:</label>

<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 @@ </p>

{{ . }} {{ end }} </div> -</form> +</form> + {{template "footer" .}}