4 import org.asciidoctor.Asciidoctor;
5 import org.asciidoctor.Asciidoctor.Factory;
6 import org.asciidoctor.Options;
7 import org.asciidoctor.ast.Document;
8 import org.asciidoctor.ast.DocumentHeader;
10 import com.rometools.rome.feed.synd.*;
11 import com.rometools.rome.io.FeedException;
12 import com.rometools.rome.io.SyndFeedOutput;
15 private static File toHTMLFile(File dir, File adoc) {
19 name = adoc.getName();
21 idx = name.lastIndexOf('.');
24 name = name.substring(0, idx);
26 return new File(dir, name + ".html");
29 public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
30 File inDir, html, outDir;
33 Asciidoctor asciidoctor;
37 ArrayList<SyndEntry> entries;
43 inDir = new File(args[0]);
44 outDir = new File(args[1]);
46 props = new Properties();
47 in = new FileInputStream(args[2]);
51 adocs = inDir.listFiles();
53 asciidoctor = Factory.create();
55 feed = new SyndFeedImpl();
56 feed.setTitle(props.getProperty("feed.title"));
57 feed.setDescription(props.getProperty("feed.description"));
58 feed.setLink(props.getProperty("feed.link"));
60 entries = new ArrayList<SyndEntry>();
62 for (File adoc: adocs) {
63 if (!adoc.getName().endsWith(".adoc"))
65 sw = new StringWriter();
67 html = toHTMLFile(outDir, adoc);
69 h = asciidoctor.readDocumentHeader(adoc);
71 asciidoctor.convert(new FileReader(adoc), sw, new HashMap<String,Object>());
73 e = new SyndEntryImpl();
74 e.setTitle(h.getDocumentTitle().getMain());
75 e.setUri(props.getProperty("feed.baseurl") + "/" + html.getName());
77 c = new SyndContentImpl();
78 c.setType("text/html");
79 c.setValue(sw.toString());
86 feed.setEntries(entries);
88 feed.setFeedType("rss_2.0");
89 SyndFeedOutput output = new SyndFeedOutput();
90 output.output(feed, new File(outDir, "feed.xml"));