initial release
authorJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 30 Jun 2016 07:20:41 +0000 (09:20 +0200)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Thu, 30 Jun 2016 07:20:41 +0000 (09:20 +0200)
asciidoctorfeed.props [new file with mode: 0644]
lib/asciidoctorj-1.5.4.jar [new file with mode: 0644]
lib/jdom2-2.0.6.jar [new file with mode: 0644]
lib/jruby-complete-1.7.21.jar [new file with mode: 0644]
lib/rome-1.6.0.jar [new file with mode: 0644]
lib/rome-utils-1.6.0.jar [new file with mode: 0644]
lib/slf4j-api-1.7.6.jar [new file with mode: 0644]
lib/slf4j-nop-1.7.6.jar [new file with mode: 0644]
pdoc.sh [new file with mode: 0755]
pom.xml [new file with mode: 0644]
src/main/java/Main.java [new file with mode: 0644]

diff --git a/asciidoctorfeed.props b/asciidoctorfeed.props
new file mode 100644 (file)
index 0000000..1e487af
--- /dev/null
@@ -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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (file)
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 (executable)
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 (file)
index 0000000..ba3b108
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,24 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  
+  <artifactId>net.wpitchoune.asciidoctor</artifactId>
+  <groupId>net.wpitchoune.net</groupId>
+  <packaging>jar</packaging>
+  <name>asciidoctor</name>
+  <version>1.0</version>
+  
+  <dependencies>
+    <dependency>
+      <groupId>org.asciidoctor</groupId>
+      <artifactId>asciidoctorj</artifactId>
+      <version>1.5.4</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.rometools</groupId>
+      <artifactId>rome</artifactId>
+      <version>1.6.0</version>
+    </dependency>
+
+  </dependencies>
+</project>
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
new file mode 100644 (file)
index 0000000..c83bad8
--- /dev/null
@@ -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<SyndEntry> 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<SyndEntry>();
+               
+               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<String,Object>());
+                       
+                       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