diff --git a/source/cartastraccia/renderer.d b/source/cartastraccia/renderer.d new file mode 100644 index 0000000..d15b243 --- /dev/null +++ b/source/cartastraccia/renderer.d @@ -0,0 +1,42 @@ +module cartastraccia.renderer; + +import cartastraccia.rss; + +import html; +import vibe.core.file; +import vibe.core.path; + +import std.conv : to; +import std.stdio; +import std.array : appender; + +void createHTMLPage(ref ValidRSS rss, immutable string feedName, immutable string pageName) +{ + auto doc = createDocument(); + doc.root.html = ` `; + + foreach(cname, channel; rss.channels) { + auto container = doc.createElement("div", doc.root.firstChild); + container.attr("class", "channel"); + container.attr("id", feedName); + container.html = "

"~cname~"

"; + + ulong icnt = 0; + foreach(iname, item; channel.items) { + icnt++; + auto container = doc.createElement("div", doc.root.firstChild); + container.attr("class", "channelitem"); + container.html = "

"~icnt.to!string~". "~iname~"

" + ~ "View Source" + ~ "

"~item.pubDate~"

" + ~ item.description; + } + } + + auto output = appender!string; + doc.root.outerHTML(output); + + auto fpath = NativePath(pageName); + if(existsFile(fpath)) removeFile(fpath); + appendToFile(fpath, output.data); +}