2 import java.io.FileInputStream;
3 import java.io.FileNotFoundException;
4 import java.io.FileReader;
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.io.StringWriter;
8 import java.util.ArrayList;
9 import java.util.HashMap;
10 import java.util.Properties;
12 import org.asciidoctor.Asciidoctor;
13 import org.asciidoctor.Asciidoctor.Factory;
14 import org.asciidoctor.ast.DocumentHeader;
16 import com.rometools.rome.feed.synd.SyndContentImpl;
17 import com.rometools.rome.feed.synd.SyndEntry;
18 import com.rometools.rome.feed.synd.SyndEntryImpl;
19 import com.rometools.rome.feed.synd.SyndFeed;
20 import com.rometools.rome.feed.synd.SyndFeedImpl;
21 import com.rometools.rome.io.FeedException;
22 import com.rometools.rome.io.SyndFeedOutput;
25 private static String KEY_HTML_HEADER = "html.header";
27 private static File toHTMLFile(File dir, File adoc) {
31 name = adoc.getName();
33 idx = name.lastIndexOf('.');
36 name = name.substring(0, idx);
38 return new File(dir, name + ".html");
41 private static SyndContentImpl toSyndContentImpl(String description) {
44 ret = new SyndContentImpl();
45 ret.setType("text/html");
46 ret.setValue(description);
51 private static String getHTMLHeader(Properties props) {
55 public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
56 File inDir, html, outDir;
59 Asciidoctor asciidoctor;
62 ArrayList<SyndEntry> entries;
69 inDir = new File(args[0]);
70 outDir = new File(args[1]);
72 props = new Properties();
73 in = new FileInputStream(args[2]);
77 adocs = inDir.listFiles();
79 asciidoctor = Factory.create();
81 feed = new SyndFeedImpl();
82 feed.setTitle(props.getProperty("feed.title"));
83 feed.setDescription(props.getProperty("feed.description"));
84 feed.setLink(props.getProperty("feed.link"));
86 entries = new ArrayList<SyndEntry>();
88 news = new StringBuffer();
89 news.append("<html>\n");
90 news.append("<body>\n");
91 for (File adoc: adocs) {
92 if (!adoc.getName().endsWith(".adoc"))
94 desc = new StringWriter();
96 html = toHTMLFile(outDir, adoc);
98 h = asciidoctor.readDocumentHeader(adoc);
100 asciidoctor.convert(new FileReader(adoc), desc, new HashMap<String,Object>());
102 e = new SyndEntryImpl();
103 e.setTitle(h.getDocumentTitle().getMain());
104 e.setUri(props.getProperty("feed.baseurl") + "/" + html.getName());
106 c = toSyndContentImpl(desc.toString());
112 news.append("\n<div>\n");
114 news.append(h.getDocumentTitle().getMain());
115 news.append("</h2>\n");
116 news.append(desc.toString());
117 news.append("\n</div>\n");
119 news.append("</body>\n");
120 news.append("</html>\n");
122 feed.setEntries(entries);
124 feed.setFeedType("rss_2.0");
125 SyndFeedOutput output = new SyndFeedOutput();
126 output.output(feed, new File(outDir, "feed.xml"));
128 System.out.println(news.toString());