rss in ejs
This commit is contained in:
@@ -69,31 +69,13 @@ app.get(config.rss_url, (req,res) => {
|
||||
})
|
||||
}
|
||||
else {
|
||||
let rss_content = `<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>${config.site_name}</title>
|
||||
<link>${config.site_url}</link>
|
||||
<description>${config.site_description}</description>
|
||||
`
|
||||
for (let i = posts.length-1; i >= 0; i--) {
|
||||
rss_content += `
|
||||
<item>
|
||||
<title>${posts[i]["title"]}</title>
|
||||
<link>${config.site_url}/post/${i}</link>
|
||||
<description><![CDATA[${converter.makeHtml(posts[i]["content"])}]]></description>
|
||||
<guid isPermaLink="true">${config.site_url}/post/${i}</guid>
|
||||
<pubDate>${func.unix_time_to_rss_date(posts[i]['pubdate'])}</pubDate>`
|
||||
for (let j = 0; j < posts[i]['tags'].length; j++) {
|
||||
rss_content += `<category><![CDATA[${posts[i]['tags'][j]}]]></category>`
|
||||
};
|
||||
rss_content += "</item>"
|
||||
}
|
||||
rss_content += `
|
||||
</channel>
|
||||
</rss>`
|
||||
res.setHeader('content-type', 'application/rss+xml');
|
||||
res.send(rss_content)
|
||||
res.render("syndication/rss", {
|
||||
config,
|
||||
posts,
|
||||
converter,
|
||||
func,
|
||||
})
|
||||
};
|
||||
});
|
||||
|
||||
|
20
views/syndication/rss.ejs
Normal file
20
views/syndication/rss.ejs
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="<%= config.charset %>" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title><%= config.site_name %></title>
|
||||
<link><%= config.site_url %></title>
|
||||
<description><%= config.site_description %></description>
|
||||
<% for (let postID = posts.length-1; postID >= 0; postID--) { %>
|
||||
<item>
|
||||
<title><%= posts[postID]["title"] %></title>
|
||||
<link><%= config.site_url %>/post/<%= postID %></link>
|
||||
<description><![CDATA[<%= converter.makeHtml(posts[postID]["content"]) %>]]></description>
|
||||
<guid isPermaLink="true"><%= config.site_url %>/post/<%= postID %></guid>
|
||||
<pubDate><%= func.unix_time_to_rss_date(posts[postID]['pubdate']) %></pubDate>
|
||||
<% for (let tag_index = 0; tag_index < posts[postID]['tags'].length; tag_index++) { %>
|
||||
<category><![CDATA[<%= posts[postID]['tags'][tag_index] %>]]></category>
|
||||
<% } %>
|
||||
</item>
|
||||
<% } %>
|
||||
</channel>
|
||||
</rss>
|
Reference in New Issue
Block a user