Only provide link in item instead of the entire article via content
This commit is contained in:
parent
10d8fceb77
commit
be467521d9
@ -50,11 +50,11 @@ func GetChannel(db *DB, title, link, description string) (*rss.Channel, error) {
|
|||||||
return channel, nil
|
return channel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenerateRSS(db *DB, title, link, desc string) (*string, error) {
|
func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||||
channel := &rss.Channel{
|
channel := &rss.Channel{
|
||||||
Title: title,
|
Title: c.Title,
|
||||||
Link: link,
|
Link: c.Link,
|
||||||
Description: desc,
|
Description: c.Description,
|
||||||
Items: make([]*rss.Item, 0),
|
Items: make([]*rss.Item, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,18 +89,13 @@ func GenerateRSS(db *DB, title, link, desc string) (*string, error) {
|
|||||||
return nil, fmt.Errorf("error converting description to plain text for RSS feed: %v", err)
|
return nil, fmt.Errorf("error converting description to plain text for RSS feed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
articleContent, err := ConvertToHTML(article.Content)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("error converting content to HTML for RSS feed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
channel.Items = append(channel.Items, &rss.Item{
|
channel.Items = append(channel.Items, &rss.Item{
|
||||||
Title: articleTitle,
|
Author: fmt.Sprint(user.FirstName, user.LastName),
|
||||||
Author: user.FirstName + " " + user.LastName,
|
|
||||||
PubDate: article.Created.Format(time.RFC1123Z),
|
|
||||||
Description: articleDescription,
|
|
||||||
Content: &rss.Content{Value: articleContent},
|
|
||||||
Categories: tagNames,
|
Categories: tagNames,
|
||||||
|
Description: articleDescription,
|
||||||
|
Link: fmt.Sprintf("http://%s/article/serve/%d", c.Domain, article.ID),
|
||||||
|
PubDate: article.Created.Format(time.RFC1123Z),
|
||||||
|
Title: articleTitle,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
cmd/calls/articles.go
Normal file
33
cmd/calls/articles.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package calls
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
b "streifling.com/jason/cpolis/cmd/backend"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if tokenIsVerified(w, r, c) {
|
||||||
|
idString := r.PathValue("id")
|
||||||
|
id, err := strconv.ParseInt(idString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
article, err := db.GetArticle(id)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Fprint(w, article.Content)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -363,7 +363,7 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed, err := b.GenerateRSS(db, c.Title, c.Link, c.Description)
|
feed, err := b.GenerateRSS(c, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
@ -582,7 +582,7 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
feed, err := b.GenerateRSS(db, c.Title, c.Link, c.Description)
|
feed, err := b.GenerateRSS(c, db)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -49,6 +49,7 @@ func main() {
|
|||||||
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
http.FileServer(http.Dir(config.WebDir+"/static/"))))
|
||||||
mux.HandleFunc("/", f.HomePage(config, db, store))
|
mux.HandleFunc("/", f.HomePage(config, db, store))
|
||||||
|
|
||||||
|
mux.HandleFunc("GET /article/serve/{id}", c.ServeArticle(config, db))
|
||||||
mux.HandleFunc("GET /create-tag", f.CreateTag(config, store))
|
mux.HandleFunc("GET /create-tag", f.CreateTag(config, store))
|
||||||
mux.HandleFunc("GET /create-user", f.CreateUser(config, store))
|
mux.HandleFunc("GET /create-user", f.CreateUser(config, store))
|
||||||
mux.HandleFunc("GET /delete-article/{id}", f.DeleteArticle(config, db, store))
|
mux.HandleFunc("GET /delete-article/{id}", f.DeleteArticle(config, db, store))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user