parse html from rss feed
This commit is contained in:
parent
0a6c5ee38a
commit
52da2c5bb1
@ -16,7 +16,7 @@
|
||||
in {
|
||||
xintray = pkgs.buildGoModule {
|
||||
pname = "xintray";
|
||||
version = "v0.1.6";
|
||||
version = "v0.1.7";
|
||||
src = ./.;
|
||||
|
||||
vendorSha256 =
|
||||
|
2
go.mod
2
go.mod
@ -5,6 +5,7 @@ go 1.17
|
||||
require (
|
||||
fyne.io/fyne/v2 v2.3.1
|
||||
golang.org/x/crypto v0.6.0
|
||||
golang.org/x/net v0.6.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -31,7 +32,6 @@ require (
|
||||
github.com/yuin/goldmark v1.5.3 // indirect
|
||||
golang.org/x/image v0.3.0 // indirect
|
||||
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
|
||||
golang.org/x/net v0.6.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
6
main.go
6
main.go
@ -172,7 +172,11 @@ func (x *xinStatus) updateRepoInfo() error {
|
||||
if err = xml.NewDecoder(res.Body).Decode(&resp); err != nil {
|
||||
return err
|
||||
}
|
||||
x.repoCommit = resp.LatestHash()
|
||||
cmit, err := resp.LatestHash()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
x.repoCommit = *cmit
|
||||
}
|
||||
|
||||
return nil
|
||||
|
32
rss.go
32
rss.go
@ -2,9 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"html"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
@ -51,11 +52,30 @@ type Feed struct {
|
||||
} `xml:"entry"`
|
||||
}
|
||||
|
||||
func (f *Feed) LatestHash() commit {
|
||||
return commit{
|
||||
func (f *Feed) LatestHash() (*commit, error) {
|
||||
doc, err := html.Parse(strings.NewReader(f.Entry[0].Content.Text))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmitMsg := ""
|
||||
var h func(*html.Node)
|
||||
h = func(n *html.Node) {
|
||||
if n.Type == html.ElementNode && n.Data == "pre" {
|
||||
cmitMsg = n.FirstChild.Data
|
||||
return
|
||||
}
|
||||
for child := n.FirstChild; child != nil; child = child.NextSibling {
|
||||
h(child)
|
||||
}
|
||||
}
|
||||
h(doc)
|
||||
|
||||
return &commit{
|
||||
hash: strings.Split(f.Entry[0].ID, "/")[1],
|
||||
// TODO: use x/html to pull out the info?
|
||||
message: html.UnescapeString(f.Entry[0].Content.Text),
|
||||
date: f.Entry[0].Updated,
|
||||
}
|
||||
message: cmitMsg,
|
||||
//message: html.UnescapeString(f.Entry[0].Content.Text),
|
||||
date: f.Entry[0].Updated,
|
||||
}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user