From: Jean-Philippe Orsini Date: Thu, 30 Jun 2016 07:20:41 +0000 (+0200) Subject: initial release X-Git-Url: https://git.wpitchoune.net/gitweb/?p=asciidoctor_to_rss.git;a=commitdiff_plain;h=44c523495f8133727a4f974ee15c51040eeec051 initial release --- 44c523495f8133727a4f974ee15c51040eeec051 diff --git a/asciidoctorfeed.props b/asciidoctorfeed.props new file mode 100644 index 0000000..1e487af --- /dev/null +++ b/asciidoctorfeed.props @@ -0,0 +1,4 @@ +feed.title=The feed title +feed.description=The description of the feed +feed.link=http://wpitchoune.net/news/feed.xml +feed.baseurl=http://wpitchoune.net/news \ No newline at end of file diff --git a/lib/asciidoctorj-1.5.4.jar b/lib/asciidoctorj-1.5.4.jar new file mode 100644 index 0000000..218a458 Binary files /dev/null and b/lib/asciidoctorj-1.5.4.jar differ diff --git a/lib/jdom2-2.0.6.jar b/lib/jdom2-2.0.6.jar new file mode 100644 index 0000000..2850ca1 Binary files /dev/null and b/lib/jdom2-2.0.6.jar differ diff --git a/lib/jruby-complete-1.7.21.jar b/lib/jruby-complete-1.7.21.jar new file mode 100644 index 0000000..7cde708 Binary files /dev/null and b/lib/jruby-complete-1.7.21.jar differ diff --git a/lib/rome-1.6.0.jar b/lib/rome-1.6.0.jar new file mode 100644 index 0000000..baaf16f Binary files /dev/null and b/lib/rome-1.6.0.jar differ diff --git a/lib/rome-utils-1.6.0.jar b/lib/rome-utils-1.6.0.jar new file mode 100644 index 0000000..f560df6 Binary files /dev/null and b/lib/rome-utils-1.6.0.jar differ diff --git a/lib/slf4j-api-1.7.6.jar b/lib/slf4j-api-1.7.6.jar new file mode 100644 index 0000000..19aaf37 Binary files /dev/null and b/lib/slf4j-api-1.7.6.jar differ diff --git a/lib/slf4j-nop-1.7.6.jar b/lib/slf4j-nop-1.7.6.jar new file mode 100644 index 0000000..52509a2 Binary files /dev/null and b/lib/slf4j-nop-1.7.6.jar differ diff --git a/pdoc.sh b/pdoc.sh new file mode 100755 index 0000000..1758471 --- /dev/null +++ b/pdoc.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +java -classpath target/classes:lib/asciidoctorj-1.5.4.jar:lib/jruby-complete-1.7.21.jar:target/net.wpitchoune.asciidoctor-1.0.jar:lib/rome-1.6.0.jar:lib/slf4j-api-1.7.6.jar:lib/slf4j-nop-1.7.6.jar:lib/jdom2-2.0.6.jar:lib/rome-utils-1.6.0.jar Main $* diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..ba3b108 --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + net.wpitchoune.asciidoctor + net.wpitchoune.net + jar + asciidoctor + 1.0 + + + + org.asciidoctor + asciidoctorj + 1.5.4 + + + + com.rometools + rome + 1.6.0 + + + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..c83bad8 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,92 @@ +import java.io.*; +import java.util.*; + +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.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); + + h = asciidoctor.readDocumentHeader(adoc); + + asciidoctor.convert(new FileReader(adoc), sw, 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()); + + e.setDescription(c); + + entries.add(e); + } + + feed.setEntries(entries); + + feed.setFeedType("rss_2.0"); + SyndFeedOutput output = new SyndFeedOutput(); + output.output(feed, new File(outDir, "feed.xml")); + } +} \ No newline at end of file