point rss items links to comment anchors

This commit is contained in:
Umputun
2018-05-18 14:17:47 -05:00
parent 402f502932
commit da2244d88e
2 changed files with 25 additions and 40 deletions
+4 -1
View File
@@ -15,6 +15,9 @@ import (
const maxRssItems = 20
// ui uses links like <post-url>#remark42__comment-<comment-id>
const uiNav = "#remark42__comment-"
func (s *Rest) rssRoutes() chi.Router {
router := chi.NewRouter()
router.Get("/post", s.rssPostCommentsCtrl)
@@ -105,7 +108,7 @@ func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) {
for i, c := range comments {
f := feeds.Item{
Title: c.User.Name,
Link: &feeds.Link{Href: c.Locator.URL},
Link: &feeds.Link{Href: c.Locator.URL + uiNav + c.ID},
Description: c.Text,
Created: c.Timestamp,
Author: &feeds.Author{Name: c.User.Name},
+21 -39
View File
@@ -2,13 +2,13 @@ package api
import (
"fmt"
"net/http"
"regexp"
"strings"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/umputun/remark/app/store"
)
func TestServer_RssPost(t *testing.T) {
@@ -18,24 +18,15 @@ func TestServer_RssPost(t *testing.T) {
waitOnMinChange()
// add one more comment
r := strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah1", "site": "radio-t"}}`)
client := &http.Client{Timeout: 5 * time.Second}
req, err := http.NewRequest("POST", ts.URL+"/api/v1/comment", r)
assert.Nil(t, err)
withBasicAuth(req, "dev", "password")
resp, err := client.Do(req)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
c1 := store.Comment{
Text: "test 123",
Locator: store.Locator{URL: "https://radio-t.com/blah1", SiteID: "radio-t"},
}
id1 := addComment(t, c1, ts)
pubDate := time.Now().Format(time.RFC1123Z)
res, code := get(t, ts.URL+"/api/v1/rss/post?site=radio-t&url=https://radio-t.com/blah1")
assert.Equal(t, 200, code)
assert.Nil(t, err)
t.Log(res)
expected := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
@@ -46,13 +37,13 @@ func TestServer_RssPost(t *testing.T) {
<pubDate>%s</pubDate>
<item>
<title>developer one</title>
<link>https://radio-t.com/blah1</link>
<link>https://radio-t.com/blah1#remark42__comment-%s</link>
<description>&lt;p&gt;test 123&lt;/p&gt;&#xA;</description>
<author>developer one</author>
<pubDate>%s</pubDate>
</item>
</channel>
</rss>`, pubDate, pubDate)
</rss>`, pubDate, id1, pubDate)
expected, res = cleanRssFormatting(expected, res)
assert.Equal(t, expected, res)
@@ -67,28 +58,19 @@ func TestServer_RssSite(t *testing.T) {
pubDate := time.Now().Format(time.RFC1123Z)
client := &http.Client{Timeout: 5 * time.Second}
r := strings.NewReader(`{"text": "test 123", "locator":{"url": "https://radio-t.com/blah10", "site": "radio-t"}}`)
req, err := http.NewRequest("POST", ts.URL+"/api/v1/comment", r)
assert.Nil(t, err)
withBasicAuth(req, "dev", "password")
resp, err := client.Do(req)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
r = strings.NewReader(`{"text": "xyz test", "locator":{"url": "https://radio-t.com/blah11", "site": "radio-t"}}`)
req, err = http.NewRequest("POST", ts.URL+"/api/v1/comment", r)
assert.Nil(t, err)
withBasicAuth(req, "dev", "password")
resp, err = client.Do(req)
assert.Nil(t, err)
assert.Equal(t, http.StatusCreated, resp.StatusCode)
c1 := store.Comment{
Text: "test 123",
Locator: store.Locator{URL: "https://radio-t.com/blah10", SiteID: "radio-t"},
}
c2 := store.Comment{
Text: "xyz test",
Locator: store.Locator{URL: "https://radio-t.com/blah11", SiteID: "radio-t"},
}
id1 := addComment(t, c1, ts)
id2 := addComment(t, c2, ts)
res, code := get(t, ts.URL+"/api/v1/rss/site?site=radio-t")
assert.Equal(t, 200, code)
assert.Nil(t, err)
t.Log(res)
expected := fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
@@ -99,20 +81,20 @@ func TestServer_RssSite(t *testing.T) {
<pubDate>%s</pubDate>
<item>
<title>developer one</title>
<link>https://radio-t.com/blah11</link>
<link>https://radio-t.com/blah11#remark42__comment-%s</link>
<description>&lt;p&gt;xyz test&lt;/p&gt;&#xA;</description>
<author>developer one</author>
<pubDate>%s</pubDate>
</item>
<item>
<title>developer one</title>
<link>https://radio-t.com/blah10</link>
<link>https://radio-t.com/blah10#remark42__comment-%s</link>
<description>&lt;p&gt;test 123&lt;/p&gt;&#xA;</description>
<author>developer one</author>
<pubDate>%s</pubDate>
</item>
</channel>
</rss>`, pubDate, pubDate, pubDate)
</rss>`, pubDate, id2, pubDate, id1, pubDate)
expected, res = cleanRssFormatting(expected, res)
assert.Equal(t, expected, res)