X-Git-Url: http://git.wpitchoune.net/gitweb/?p=www.git;a=blobdiff_plain;f=asciidoctor%2Fsrc%2Fmain%2Fjava%2FMain.java;fp=asciidoctor%2Fsrc%2Fmain%2Fjava%2FMain.java;h=228935dd9c2c49c048bb48441c618c4935ef4e23;hp=0000000000000000000000000000000000000000;hb=7f8bd4e38e4e433e249f772cc1088ff05055937c;hpb=405c5b55c568b2f826f8e307fc0b76176a7f200e diff --git a/asciidoctor/src/main/java/Main.java b/asciidoctor/src/main/java/Main.java new file mode 100644 index 0000000..228935d --- /dev/null +++ b/asciidoctor/src/main/java/Main.java @@ -0,0 +1,97 @@ +import java.io.*; +import java.util.*; + +import org.asciidoctor.Asciidoctor; +import org.asciidoctor.Asciidoctor.Factory; +import org.asciidoctor.Options; +import org.asciidoctor.ast.DocumentHeader; + +import com.rometools.rome.feed.synd.*; +import com.rometools.rome.io.FeedException; +import com.rometools.rome.io.SyndFeedOutput; + +public class Main { + private static File toHTMLFile(File dir, File adoc) { + int idx; + String name; + + name = adoc.getName(); + + idx = name.lastIndexOf('.'); + + if (idx >= 0) + name = name.substring(0, idx); + + return new File(dir, name + ".html"); + } + + public static void main(String[] args) throws FileNotFoundException, IOException, FeedException { + File inDir, html, outDir; + File[] adocs; + StringWriter sw; + Asciidoctor asciidoctor; + Options opts; + SyndFeed feed; + Properties props; + ArrayList entries; + SyndEntryImpl e; + InputStream in; + DocumentHeader h; + SyndContentImpl c; + + inDir = new File(args[0]); + outDir = new File(args[1]); + + props = new Properties(); + in = new FileInputStream(args[2]); + props.load(in); + in.close(); + + adocs = inDir.listFiles(); + + asciidoctor = Factory.create(); + + feed = new SyndFeedImpl(); + feed.setTitle(props.getProperty("feed.title")); + feed.setDescription(props.getProperty("feed.description")); + feed.setLink(props.getProperty("feed.link")); + + entries = new ArrayList(); + + for (File adoc: adocs) { + if (!adoc.getName().endsWith(".adoc")) + continue; + + sw = new StringWriter(); + + html = toHTMLFile(outDir, adoc); + System.out.println(adoc + " => " + html); + + opts = new Options(); + opts.setToFile(html.getAbsolutePath()); + + asciidoctor.renderFile(adoc, opts); + + h = asciidoctor.readDocumentHeader(adoc); + + asciidoctor.convert(new FileReader(adoc), sw, Collections.emptyMap()); + + e = new SyndEntryImpl(); + e.setTitle(h.getDocumentTitle().getMain()); + + c = new SyndContentImpl(); + c.setType("text/html"); + c.setValue(sw.toString()); + + e.setDescription(c); + + entries.add(e); + } + + feed.setEntries(entries); + + feed.setFeedType("rss_2.0"); + SyndFeedOutput output = new SyndFeedOutput(); + System.out.println("" + output.outputString(feed)); + } +} \ No newline at end of file