X-Git-Url: https://git.wpitchoune.net/gitweb/?p=asciidoctor_to_rss.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2FMain.java;h=ea54abebc0660ff07dab50c56e9149de434f88cf;hp=c83bad8a2ee00e4c7ee8a6f60f22f146fe73d7a9;hb=db33734e0d1fe77bd36acb452dff58de764b8537;hpb=44c523495f8133727a4f974ee15c51040eeec051 diff --git a/src/main/java/Main.java b/src/main/java/Main.java index c83bad8..ea54abe 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,17 +1,29 @@ -import java.io.*; -import java.util.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Properties; import org.asciidoctor.Asciidoctor; import org.asciidoctor.Asciidoctor.Factory; -import org.asciidoctor.Options; -import org.asciidoctor.ast.Document; import org.asciidoctor.ast.DocumentHeader; -import com.rometools.rome.feed.synd.*; +import com.rometools.rome.feed.synd.SyndContentImpl; +import com.rometools.rome.feed.synd.SyndEntry; +import com.rometools.rome.feed.synd.SyndEntryImpl; +import com.rometools.rome.feed.synd.SyndFeed; +import com.rometools.rome.feed.synd.SyndFeedImpl; import com.rometools.rome.io.FeedException; import com.rometools.rome.io.SyndFeedOutput; public class Main { + private static String KEY_HTML_HEADER = "html.header"; + private static File toHTMLFile(File dir, File adoc) { int idx; String name; @@ -26,12 +38,25 @@ public class Main { return new File(dir, name + ".html"); } + private static SyndContentImpl toSyndContentImpl(String description) { + SyndContentImpl ret; + + ret = new SyndContentImpl(); + ret.setType("text/html"); + ret.setValue(description); + + return ret; + } + + private static String getHTMLHeader(Properties props) { + return null; + } + public static void main(String[] args) throws FileNotFoundException, IOException, FeedException { File inDir, html, outDir; File[] adocs; - StringWriter sw; + StringWriter desc; Asciidoctor asciidoctor; - Options opts; SyndFeed feed; Properties props; ArrayList entries; @@ -39,6 +64,7 @@ public class Main { InputStream in; DocumentHeader h; SyndContentImpl c; + StringBuffer news; inDir = new File(args[0]); outDir = new File(args[1]); @@ -59,34 +85,46 @@ public class Main { entries = new ArrayList(); + news = new StringBuffer(); + news.append("\n"); + news.append("\n"); for (File adoc: adocs) { if (!adoc.getName().endsWith(".adoc")) continue; - sw = new StringWriter(); + desc = new StringWriter(); html = toHTMLFile(outDir, adoc); h = asciidoctor.readDocumentHeader(adoc); - asciidoctor.convert(new FileReader(adoc), sw, new HashMap()); + asciidoctor.convert(new FileReader(adoc), desc, new HashMap()); e = new SyndEntryImpl(); e.setTitle(h.getDocumentTitle().getMain()); e.setUri(props.getProperty("feed.baseurl") + "/" + html.getName()); - c = new SyndContentImpl(); - c.setType("text/html"); - c.setValue(sw.toString()); + c = toSyndContentImpl(desc.toString()); e.setDescription(c); entries.add(e); + + news.append("\n
\n"); + news.append("

"); + news.append(h.getDocumentTitle().getMain()); + news.append("

\n"); + news.append(desc.toString()); + news.append("\n
\n"); } + news.append("\n"); + news.append("\n"); feed.setEntries(entries); feed.setFeedType("rss_2.0"); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, new File(outDir, "feed.xml")); + + System.out.println(news.toString()); } } \ No newline at end of file