This commit is contained in:
blank X 2021-08-11 20:22:30 +07:00
parent 301edec262
commit 6926e9f3e4
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 25 additions and 24 deletions

28
main.go
View File

@ -1,18 +1,18 @@
package main package main
import ( import (
"os"
"fmt"
"log"
"sort"
"time"
"errors"
"context" "context"
"strings"
"net/url"
"crypto/x509" "crypto/x509"
"encoding/xml" "encoding/xml"
"errors"
"fmt"
"log"
"net/url"
"os"
"path/filepath" "path/filepath"
"sort"
"strings"
"time"
"git.sr.ht/~adnano/go-gemini" "git.sr.ht/~adnano/go-gemini"
"git.sr.ht/~adnano/go-gemini/tofu" "git.sr.ht/~adnano/go-gemini/tofu"
@ -98,7 +98,7 @@ func do(client gemini.Client, ctx context.Context, req *gemini.Request, via []*g
} }
if resp.Status.Class() == gemini.StatusPermanentFailure { if resp.Status.Class() == gemini.StatusPermanentFailure {
perrors[req.URL.String()] = PError{ perrors[req.URL.String()] = PError{
Code: resp.Status, Code: resp.Status,
Message: resp.Meta, Message: resp.Meta,
} }
err = savePErrors() err = savePErrors()
@ -170,7 +170,7 @@ func main() {
Link: FeedLink{ Link: FeedLink{
Href: req.URL.String(), Href: req.URL.String(),
}, },
Id: req.URL.String(), Id: req.URL.String(),
Entries: nil, Entries: nil,
} }
if aw.Title == "" { if aw.Title == "" {
@ -181,10 +181,10 @@ func main() {
if len(aw.Items) == 0 { if len(aw.Items) == 0 {
feed.Updated = time.Now().Format(time.RFC3339) feed.Updated = time.Now().Format(time.RFC3339)
} else { } else {
feed.Updated = aw.Items[len(aw.Items) - 1].Date.Format(time.RFC3339) feed.Updated = aw.Items[len(aw.Items)-1].Date.Format(time.RFC3339)
} }
for i := len(aw.Items); i != 0; i-- { for i := len(aw.Items); i != 0; i-- {
item := aw.Items[i - 1] item := aw.Items[i-1]
link, err := req.URL.Parse(item.Link) link, err := req.URL.Parse(item.Link)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -193,9 +193,9 @@ func main() {
Title: item.Title, Title: item.Title,
Link: EntryLink{ Link: EntryLink{
Href: link.String(), Href: link.String(),
Rel: "alternate", Rel: "alternate",
}, },
Id: link.String(), Id: link.String(),
Updated: item.Date.Format(time.RFC3339), Updated: item.Date.Format(time.RFC3339),
}) })
} }

View File

@ -1,9 +1,9 @@
package main package main
import ( import (
"time"
"strings"
"encoding/xml" "encoding/xml"
"strings"
"time"
"git.sr.ht/~adnano/go-gemini" "git.sr.ht/~adnano/go-gemini"
) )
@ -41,6 +41,7 @@ type FeedItem struct {
} }
type ByTime []FeedItem type ByTime []FeedItem
func (a ByTime) Len() int { func (a ByTime) Len() int {
return len(a) return len(a)
} }
@ -63,9 +64,9 @@ func (a *AtomWriter) Handle(line gemini.Line) {
t, err := time.Parse("2006-01-02", string(runes[:10])) t, err := time.Parse("2006-01-02", string(runes[:10]))
if err == nil { if err == nil {
a.Items = append(a.Items, FeedItem{ a.Items = append(a.Items, FeedItem{
Date: t, Date: t,
Title: strings.TrimSpace(strings.TrimLeft(strings.TrimSpace(string(runes[10:])), ":-")), Title: strings.TrimSpace(strings.TrimLeft(strings.TrimSpace(string(runes[10:])), ":-")),
Link: string(line.URL), Link: string(line.URL),
}) })
} }
case gemini.LineHeading1: case gemini.LineHeading1:

View File

@ -1,12 +1,12 @@
package main package main
import ( import (
"os"
"bufio" "bufio"
"net/url"
"os"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"net/url"
"path/filepath"
"git.sr.ht/~adnano/go-gemini" "git.sr.ht/~adnano/go-gemini"
) )
@ -44,7 +44,7 @@ func populatePErrors() error {
continue continue
} }
perrors[url.String()] = PError{ perrors[url.String()] = PError{
Code: gemini.Status(code), Code: gemini.Status(code),
Message: unescaper.Replace(values[2]), Message: unescaper.Replace(values[2]),
} }
} }

View File

@ -1,11 +1,11 @@
package main package main
import ( import (
"os"
"bufio" "bufio"
"strings"
"net/url" "net/url"
"os"
"path/filepath" "path/filepath"
"strings"
) )
var predirs map[string]*url.URL var predirs map[string]*url.URL