4 import org.asciidoctor.Asciidoctor;
5 import org.asciidoctor.Asciidoctor.Factory;
6 import org.asciidoctor.Options;
7 import org.asciidoctor.ast.DocumentHeader;
9 import com.rometools.rome.feed.synd.*;
10 import com.rometools.rome.io.FeedException;
11 import com.rometools.rome.io.SyndFeedOutput;
14 private static File toHTMLFile(File dir, File adoc) {
18 name = adoc.getName();
20 idx = name.lastIndexOf('.');
23 name = name.substring(0, idx);
25 return new File(dir, name + ".html");
28 public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
29 File inDir, html, outDir;
32 Asciidoctor asciidoctor;
36 ArrayList<SyndEntry> entries;
42 inDir = new File(args[0]);
43 outDir = new File(args[1]);
45 props = new Properties();
46 in = new FileInputStream(args[2]);
50 adocs = inDir.listFiles();
52 asciidoctor = Factory.create();
54 feed = new SyndFeedImpl();
55 feed.setTitle(props.getProperty("feed.title"));
56 feed.setDescription(props.getProperty("feed.description"));
57 feed.setLink(props.getProperty("feed.link"));
59 entries = new ArrayList<SyndEntry>();
61 for (File adoc: adocs) {
62 if (!adoc.getName().endsWith(".adoc"))
65 sw = new StringWriter();
67 html = toHTMLFile(outDir, adoc);
68 System.out.println(adoc + " => " + html);
71 opts.setToFile(html.getAbsolutePath());
73 asciidoctor.renderFile(adoc, opts);
75 h = asciidoctor.readDocumentHeader(adoc);
77 asciidoctor.convert(new FileReader(adoc), sw, Collections.emptyMap());
79 e = new SyndEntryImpl();
80 e.setTitle(h.getDocumentTitle().getMain());
82 c = new SyndContentImpl();
83 c.setType("text/html");
84 c.setValue(sw.toString());
91 feed.setEntries(entries);
93 feed.setFeedType("rss_2.0");
94 SyndFeedOutput output = new SyndFeedOutput();
95 System.out.println("" + output.outputString(feed));