diff --git a/rss/rss.go b/rss/rss.go index fbff567..7375e24 100644 --- a/rss/rss.go +++ b/rss/rss.go @@ -4,12 +4,29 @@ import ( "fmt" "io" "net/http" - "regexp" "strings" "time" "golang.org/x/net/html" ) +const feedfmt = ` + + + %s + %s + %s + %s + + + ` + +const itemfmt = ` + Content Title + %s + %s + %s + + `; func fetchPage(url string) (string, error) { resp, err := http.Get(url) @@ -77,29 +94,13 @@ func parseArticle(content string) (string, *time.Time, error) { } } - article := strings.TrimSuffix(strings.TrimPrefix(builder.String(), "
"), "
") - - return article, pagetime, nil + return builder.String(), pagetime, nil } func GenerateRss(siteUrl, siteTitle, siteDesc string, pageUrls ...string) (string, error) { - // get page - // parse article - // parse date - // create item element - // collect item elements into feed var items strings.Builder var err error - itemfmt := ` - Content Title - %s - %s - %s - %s - -` - for _, u := range pageUrls { page, err := fetchPage(u) if err != nil { @@ -116,15 +117,5 @@ func GenerateRss(siteUrl, siteTitle, siteDesc string, pageUrls ...string) (strin } } - feed := ` - - - %s - %s - %s - %s - - - ` - return fmt.Sprintf(feed, siteTitle, siteUrl, siteDesc, items.String()), err + return fmt.Sprintf(feedfmt, siteTitle, siteUrl, siteDesc, items.String()), err } diff --git a/rss/rss_test.go b/rss/rss_test.go index 407b7fa..367406f 100644 --- a/rss/rss_test.go +++ b/rss/rss_test.go @@ -19,19 +19,13 @@ func TestArticleParse(t *testing.T) { "article stripped out of basic HTML", "
hello world
", nil, - "hello world", + "
hello world
", }, { "article and time stripped out of basic HTML", "
hello world
", &testDate, - "hello world", - }, - { - "article with attributes", - "
hello world
", - &testDate, - "hello world", + "
hello world
", }, }