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 File toHTMLFile(File dir, File adoc) {
29 name = adoc.getName();
31 idx = name.lastIndexOf('.');
34 name = name.substring(0, idx);
36 return new File(dir, name + ".html");
39 public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
40 File inDir, html, outDir;
43 Asciidoctor asciidoctor;
46 ArrayList<SyndEntry> entries;
52 inDir = new File(args[0]);
53 outDir = new File(args[1]);
55 props = new Properties();
56 in = new FileInputStream(args[2]);
60 adocs = inDir.listFiles();
62 asciidoctor = Factory.create();
64 feed = new SyndFeedImpl();
65 feed.setTitle(props.getProperty("feed.title"));
66 feed.setDescription(props.getProperty("feed.description"));
67 feed.setLink(props.getProperty("feed.link"));
69 entries = new ArrayList<SyndEntry>();
71 for (File adoc: adocs) {
72 if (!adoc.getName().endsWith(".adoc"))
74 sw = new StringWriter();
76 html = toHTMLFile(outDir, adoc);
78 h = asciidoctor.readDocumentHeader(adoc);
80 asciidoctor.convert(new FileReader(adoc), sw, new HashMap<String,Object>());
82 e = new SyndEntryImpl();
83 e.setTitle(h.getDocumentTitle().getMain());
84 e.setUri(props.getProperty("feed.baseurl") + "/" + html.getName());
86 c = new SyndContentImpl();
87 c.setType("text/html");
88 c.setValue(sw.toString());
95 feed.setEntries(entries);
97 feed.setFeedType("rss_2.0");
98 SyndFeedOutput output = new SyndFeedOutput();
99 output.output(feed, new File(outDir, "feed.xml"));