1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-09 11:29:58 +00:00
TiddlyWiki5/tw2/source/tiddlywiki/js/SavingRSS.js
Jeremy Ruston a1c8ac624f Added first pass at support for building TiddlyWiki 2.6.x with TW5
There are still some whitespace and attribute ordering issues, but the
result runs correctly.
2012-05-29 22:02:38 +01:00

58 lines
2.1 KiB
JavaScript
Executable File

//--
//-- RSS Saving
//--
function saveRss(localPath)
{
var rssPath = localPath.substr(0,localPath.lastIndexOf(".")) + ".xml";
if(saveFile(rssPath,convertUnicodeToFileFormat(generateRss())))
displayMessage(config.messages.rssSaved,"file://" + rssPath);
else
alert(config.messages.rssFailed);
}
tiddlerToRssItem = function(tiddler,uri)
{
var s = "<title" + ">" + tiddler.title.htmlEncode() + "</title" + ">\n";
s += "<description>" + wikifyStatic(tiddler.text,null,tiddler).htmlEncode() + "</description>\n";
var i;
for(i=0; i<tiddler.tags.length; i++)
s += "<category>" + tiddler.tags[i] + "</category>\n";
s += "<link>" + uri + "#" + encodeURIComponent(String.encodeTiddlyLink(tiddler.title)) + "</link>\n";
s +="<pubDate>" + tiddler.modified.toGMTString() + "</pubDate>\n";
return s;
};
function generateRss()
{
var s = [];
var d = new Date();
var u = store.getTiddlerText("SiteUrl");
// Assemble the header
s.push("<" + "?xml version=\"1.0\"?" + ">");
s.push("<rss version=\"2.0\">");
s.push("<channel>");
s.push("<title" + ">" + wikifyPlainText(store.getTiddlerText("SiteTitle",""),null,tiddler).htmlEncode() + "</title" + ">");
if(u)
s.push("<link>" + u.htmlEncode() + "</link>");
s.push("<description>" + wikifyPlainText(store.getTiddlerText("SiteSubtitle",""),null,tiddler).htmlEncode() + "</description>");
s.push("<language>" + config.locale + "</language>");
s.push("<copyright>Copyright " + d.getFullYear() + " " + config.options.txtUserName.htmlEncode() + "</copyright>");
s.push("<pubDate>" + d.toGMTString() + "</pubDate>");
s.push("<lastBuildDate>" + d.toGMTString() + "</lastBuildDate>");
s.push("<docs>http://blogs.law.harvard.edu/tech/rss</docs>");
s.push("<generator>TiddlyWiki " + formatVersion() + "</generator>");
// The body
var tiddlers = store.getTiddlers("modified","excludeLists");
var i,n = config.numRssItems > tiddlers.length ? 0 : tiddlers.length-config.numRssItems;
for(i=tiddlers.length-1; i>=n; i--) {
s.push("<item>\n" + tiddlerToRssItem(tiddlers[i],u) + "\n</item>");
}
// And footer
s.push("</channel>");
s.push("</rss>");
// Save it all
return s.join("\n");
}