forked from jason/cpolis
Store article content outside of DB and convert and serve on request from respective file
This commit is contained in:
@@ -9,47 +9,6 @@ import (
|
||||
"git.streifling.com/jason/rss"
|
||||
)
|
||||
|
||||
func GetChannel(db *DB, title, link, description string) (*rss.Channel, error) {
|
||||
channel := &rss.Channel{
|
||||
Title: title,
|
||||
Link: link,
|
||||
Description: description,
|
||||
Items: make([]*rss.Item, 0),
|
||||
}
|
||||
|
||||
articles, err := db.GetCertainArticles(true, false)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching published articles: %v", err)
|
||||
}
|
||||
|
||||
for _, article := range articles {
|
||||
tags, err := db.GetArticleTags(article.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error fetching tags for article %v: %v", article.Title, err)
|
||||
}
|
||||
tagNames := make([]string, 0)
|
||||
for _, tag := range tags {
|
||||
tagNames = append(tagNames, tag.Name)
|
||||
}
|
||||
|
||||
user, err := db.GetUser(article.AuthorID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error finding user %v: %v", article.AuthorID, err)
|
||||
}
|
||||
|
||||
channel.Items = append(channel.Items, &rss.Item{
|
||||
Title: article.Title,
|
||||
Author: fmt.Sprint(user.FirstName, " ", user.LastName),
|
||||
PubDate: article.Created.Format(time.RFC1123Z),
|
||||
Description: article.Description,
|
||||
Content: &rss.Content{Value: article.Content},
|
||||
Categories: tagNames,
|
||||
})
|
||||
}
|
||||
|
||||
return channel, nil
|
||||
}
|
||||
|
||||
func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
channel := &rss.Channel{
|
||||
Title: c.Title,
|
||||
@@ -93,15 +52,19 @@ func GenerateRSS(c *Config, db *DB) (*string, error) {
|
||||
Author: fmt.Sprint(user.FirstName, " ", user.LastName),
|
||||
Categories: tagNames,
|
||||
Description: articleDescription,
|
||||
Guid: string(article.ID),
|
||||
Link: article.Link,
|
||||
PubDate: article.Created.Format(time.RFC1123Z),
|
||||
Title: articleTitle,
|
||||
}
|
||||
fmt.Println(article.Link, ": ", len(article.Link))
|
||||
|
||||
if article.Link == "" {
|
||||
item.Link = fmt.Sprint("http://", c.Domain, "/article/serve/", article.ID, ".html")
|
||||
} else {
|
||||
item.Link = article.Link
|
||||
if article.Title == "Autogenerated cpolis Issue Article" {
|
||||
item.Enclosure = &rss.Enclosure{
|
||||
Url: article.EncURL,
|
||||
Lenght: article.EncLength,
|
||||
Type: article.EncType,
|
||||
}
|
||||
}
|
||||
|
||||
channel.Items = append(channel.Items, item)
|
||||
|
||||
Reference in New Issue
Block a user