forked from jason/cpolis
Get rid of RSS completely
This commit is contained in:
@ -22,13 +22,13 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
|
||||
articles, err := db.GetCertainArticles("published", true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting published articles for RSS feed: %v", err)
|
||||
return nil, fmt.Errorf("error getting published articles for Atom feed: %v", err)
|
||||
}
|
||||
|
||||
for _, article := range articles {
|
||||
articleTitle, err := ConvertToPlain(article.Title)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting title to plain text for RSS feed: %v", err)
|
||||
return nil, fmt.Errorf("error converting title to plain text for Atom feed: %v", err)
|
||||
}
|
||||
entry := atom.NewEntry(articleTitle)
|
||||
entry.ID = atom.NewID(fmt.Sprint("urn:entry:", article.ID))
|
||||
@ -41,13 +41,13 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
|
||||
user, err := db.GetUser(c, article.AuthorID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting user user info for RSS feed: %v", err)
|
||||
return nil, fmt.Errorf("error getting user user info for Atom feed: %v", err)
|
||||
}
|
||||
entry.AddAuthor(atom.NewPerson(user.FirstName + " " + user.LastName))
|
||||
|
||||
articleSummary, err := ConvertToPlain(article.Summary)
|
||||
if err != nil {
|
||||
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 Atom feed: %v", err)
|
||||
}
|
||||
if article.AutoGenerated {
|
||||
articleSummary = "auto generated"
|
||||
@ -56,7 +56,7 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
|
||||
tags, err := db.GetArticleTags(article.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting tags for articles for RSS feed: %v", err)
|
||||
return nil, fmt.Errorf("error getting tags for articles for Atom feed: %v", err)
|
||||
}
|
||||
for _, tag := range tags {
|
||||
entry.AddCategory(atom.NewCategory(tag.Name))
|
||||
@ -79,7 +79,7 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
|
||||
atom, err := feed.ToXML("UTF-8")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting RSS feed to XML: %v", err)
|
||||
return nil, fmt.Errorf("error converting Atom feed to XML: %v", err)
|
||||
}
|
||||
|
||||
return &atom, nil
|
||||
|
@ -1,103 +0,0 @@
|
||||
package backend
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"git.streifling.com/jason/rss"
|
||||
)
|
||||
|
||||
func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
channel := &rss.Channel{
|
||||
Title: c.Title,
|
||||
Link: c.Link,
|
||||
Description: c.Description,
|
||||
Items: make([]*rss.Item, 0),
|
||||
}
|
||||
|
||||
articles, err := db.GetCertainArticles("published", true)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting published articles for RSS feed: %v", err)
|
||||
}
|
||||
|
||||
for _, article := range articles {
|
||||
tags, err := db.GetArticleTags(article.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting tags for articles for RSS feed: %v", err)
|
||||
}
|
||||
tagNames := make([]string, 0)
|
||||
for _, tag := range tags {
|
||||
tagNames = append(tagNames, tag.Name)
|
||||
}
|
||||
|
||||
if article.IsInIssue || article.AutoGenerated {
|
||||
tagNames = append(tagNames, fmt.Sprint("Orient Express ", article.IssueID))
|
||||
}
|
||||
if article.AutoGenerated {
|
||||
tagNames = append(tagNames, "autogenerated")
|
||||
}
|
||||
|
||||
user, err := db.GetUser(c, article.AuthorID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error getting user user info for RSS feed: %v", err)
|
||||
}
|
||||
|
||||
articleTitle, err := ConvertToPlain(article.Title)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting title to plain text for RSS feed: %v", err)
|
||||
}
|
||||
|
||||
articleDescription, err := ConvertToPlain(article.Summary)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting description to plain text for RSS feed: %v", err)
|
||||
}
|
||||
|
||||
item := &rss.Item{
|
||||
Author: user.FirstName + " " + user.LastName,
|
||||
Categories: tagNames,
|
||||
Description: articleDescription,
|
||||
Guid: string(article.ID),
|
||||
Link: article.ContentLink,
|
||||
PubDate: article.Created.Format(time.RFC1123Z),
|
||||
Title: articleTitle,
|
||||
}
|
||||
|
||||
// if article.AutoGenerated {
|
||||
// item.Enclosure = &rss.Enclosure{
|
||||
// Url: article.EncURL,
|
||||
// Lenght: article.EncLength,
|
||||
// Type: article.EncType,
|
||||
// }
|
||||
// }
|
||||
//
|
||||
channel.Items = append(channel.Items, item)
|
||||
}
|
||||
|
||||
feed := rss.NewFeed()
|
||||
feed.Channels = append(feed.Channels, channel)
|
||||
rss, err := feed.ToXML("UTF-8")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error converting RSS feed to XML: %v", err)
|
||||
}
|
||||
|
||||
return &rss, nil
|
||||
}
|
||||
|
||||
func SaveRSS(filename string, feed *string) error {
|
||||
file, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating file for RSS feed: %v", err)
|
||||
}
|
||||
defer file.Close()
|
||||
if err = file.Chmod(0644); err != nil {
|
||||
return fmt.Errorf("error setting permissions for RSS file: %v", err)
|
||||
}
|
||||
|
||||
if _, err = io.WriteString(file, *feed); err != nil {
|
||||
return fmt.Errorf("error writing to RSS file: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user