1 module vibelog.rss; 2 3 import vibe.core.stream; 4 import vibe.inet.message : toRFC822DateTimeString; 5 6 import std.datetime; 7 8 9 final class RssFeed { 10 RssChannel[] channels; 11 12 void render(OutputStream dst) 13 { 14 dst.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); 15 dst.write("<rss version=\"2.0\">\n"); 16 foreach( ch; channels ) 17 ch.render(dst); 18 dst.write("</rss>\n"); 19 dst.flush(); 20 } 21 } 22 23 final class RssChannel { 24 string title; 25 string link; 26 string description; 27 string language = "en-us"; 28 string copyright; 29 SysTime pubDate; 30 31 string imageTitle; 32 string imageUrl; 33 string imageLink; 34 35 RssEntry[] entries; 36 37 void render(OutputStream dst) 38 { 39 dst.write("\t<channel>\n"); 40 dst.write("\t\t<title>"); dst.write(title); dst.write("</title>\n"); 41 dst.write("\t\t<link>"); dst.write(link); dst.write("</link>\n"); 42 dst.write("\t\t<description>"); dst.write(description); dst.write("</description>\n"); 43 dst.write("\t\t<language>"); dst.write(language); dst.write("</language>\n"); 44 dst.write("\t\t<copyright>"); dst.write(copyright); dst.write("</copyright>\n"); 45 dst.write("\t\t<pubDate>"); dst.write(toRFC822DateTimeString(pubDate)); dst.write("</pubDate>\n"); 46 if( imageUrl.length ){ 47 dst.write("\t\t<image>\n"); 48 dst.write("\t\t\t<url>"); dst.write(imageUrl); dst.write("</url>\n"); 49 dst.write("\t\t\t<title>"); dst.write(imageTitle); dst.write("</title>\n"); 50 dst.write("\t\t\t<link>"); dst.write(imageLink); dst.write("</link>\n"); 51 dst.write("\t\t</image>\n"); 52 } 53 foreach( e; entries ) 54 e.render(dst); 55 dst.write("\t</channel>\n"); 56 } 57 } 58 59 final class RssEntry { 60 string title; 61 string description; 62 string link; 63 string language = "en-us"; 64 string author; 65 string guid; 66 SysTime pubDate; 67 68 void render(OutputStream dst) 69 { 70 dst.write("\t\t<item>\n"); 71 dst.write("\t\t\t<title>"); dst.write(title); dst.write("</title>\n"); 72 dst.write("\t\t\t<description>"); dst.write(description); dst.write("</description>\n"); 73 dst.write("\t\t\t<link>"); dst.write(link); dst.write("</link>\n"); 74 dst.write("\t\t\t<author>"); dst.write(author); dst.write("</author>\n"); 75 dst.write("\t\t\t<guid>"); dst.write(guid); dst.write("</guid>\n"); 76 dst.write("\t\t\t<pubDate>"); dst.write(toRFC822DateTimeString(pubDate)); dst.write("</pubDate>\n"); 77 dst.write("\t\t</item>\n"); 78 } 79 }