all repos — flounder @ 742fae8d63c7bb08b844980d8eae7b90bc438488

A small site builder for the Gemini protocol

display HTML in RSS feed
Bi-Rabittoh andronacomarco@gmail.com
Tue, 04 May 2021 17:12:41 +0200
commit

742fae8d63c7bb08b844980d8eae7b90bc438488

parent

f37b2e8dc4ee0c6517969b7d5df9b16cf318cbd6

1 files changed, 30 insertions(+), 23 deletions(-)

jump to
M gemfeed.gogemfeed.go

@@ -4,6 +4,7 @@ package main

import ( "bufio" + "bytes" "github.com/gorilla/feeds" "io/ioutil" "net/url"

@@ -13,6 +14,8 @@ "path/filepath"

"sort" "strings" "time" + + "git.sr.ht/~adnano/go-gemini" ) type Gemfeed struct {

@@ -81,36 +84,40 @@ }

entry.Date = date entry.DateString = base[:10] entry.Feed = &feed - f, err := os.Open(thepath) + content, err := ioutil.ReadFile(thepath) if err != nil { return nil } - defer f.Close() - scanner := bufio.NewScanner(f) - for scanner.Scan() { - // skip blank lines - if scanner.Text() == "" { - continue + parse, _ := gemini.ParseText(bytes.NewReader(content)) + htmlDoc := textToHTML(nil, parse) + if htmlDoc.Title != "" { + // look for a title in headings + entry.Title = htmlDoc.Title + } else { + // look for a title in lines + f, err := os.Open(thepath) + if err != nil { + return nil } - line := scanner.Text() - if strings.HasPrefix(line, "#") { - entry.Title = strings.Trim(line, "# \t") - } else { - var title string - if len(line) > 50 { - title = line[:50] - } else { - title = line + defer f.Close() + scanner := bufio.NewScanner(f) + for scanner.Scan() { + // skip blank lines + if scanner.Text() == "" { + continue } - entry.Title = "[" + title + "...]" + line := scanner.Text() + var title string + if len(line) > 50 { + title = line[:50] + } else { + title = line + } + entry.Title = "[" + title + "...]" + break } - break } - content, err := ioutil.ReadFile(thepath) - if err != nil { - return nil - } - entry.Content = "<pre>" + string(content) + "</pre>" + entry.Content = htmlDoc.Content entry.File = getLocalPath(thepath) u := urlFromPath(thepath) entry.Url = &u