~sircmpwn/gemreader

1fbb525959916d6afa3091659161f8d7c7826317 — Drew DeVault 3 years ago 30bb8ad
fetch: resolve relative gemini URLs
1 files changed, 9 insertions(+), 4 deletions(-)

M feeds/fetch.go
M feeds/fetch.go => feeds/fetch.go +9 -4
@@ 21,11 21,11 @@ const (
	FEED_GEMINI = "gemini"
)

func fetchGemini(ctx context.Context, url *url.URL) (*rss.Feed, string, error) {
func fetchGemini(ctx context.Context, remoteURL *url.URL) (*rss.Feed, string, error) {
	client := &gemini.Client{}
	tctx, cancel := context.WithTimeout(ctx, 10 * time.Second)
	defer cancel()
	resp, err := client.Get(tctx, url.String())
	resp, err := client.Get(tctx, remoteURL.String())
	if err != nil {
		return nil, "", err
	}


@@ 45,7 45,7 @@ func fetchGemini(ctx context.Context, url *url.URL) (*rss.Feed, string, error) {
	switch mimetype {
	case "text/gemini":
		var feed rss.Feed
		feed.Link = url.String()
		feed.Link = remoteURL.String()
		text, err := gemini.ParseText(resp.Body)
		if err != nil {
			return nil, "", err


@@ 65,10 65,15 @@ func fetchGemini(ctx context.Context, url *url.URL) (*rss.Feed, string, error) {
				if err != nil {
					continue
				}
				link, err := url.Parse(line.URL)
				if err != nil {
					continue
				}
				link = remoteURL.ResolveReference(link)
				item := &rss.Item{}
				item.Title = strings.TrimLeft(line.Name[10:], ": ")
				item.Date = date
				item.Link = line.URL
				item.Link = link.String()
				feed.Items = append(feed.Items, item)
			}
		}