Merge branch 'master' of ssh://git.wpitchoune.net/srv/git/asciidoctor_to_rss
authorJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 1 Jul 2016 11:15:26 +0000 (13:15 +0200)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Fri, 1 Jul 2016 11:15:26 +0000 (13:15 +0200)
asciidoctorrss.props
src/main/java/Main.java

index 1e487af..05273ad 100644 (file)
@@ -1,4 +1,6 @@
 feed.title=The feed title
-feed.description=The description of the feed
+feed.description=News of the wpitchoune.net website.
 feed.link=http://wpitchoune.net/news/feed.xml
-feed.baseurl=http://wpitchoune.net/news
\ No newline at end of file
+feed.baseurl=http://wpitchoune.net/news
+
+html.header.file=header.html
\ No newline at end of file
index 96b8407..6f97ae4 100644 (file)
@@ -22,7 +22,9 @@ import com.rometools.rome.io.FeedException;
 import com.rometools.rome.io.SyndFeedOutput;
 
 public class Main {
-        private static File getHTMLFile(File dir, File adoc) {
+       private static String KEY_HTML_HEADER = "html.header";
+       
+        private static File toHTMLFile(File dir, File adoc) {
                 int idx;
                 String name;
                 
@@ -36,10 +38,24 @@ 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;
                SyndFeed feed;
                Properties props;
@@ -48,6 +64,7 @@ public class Main {
                InputStream in;
                DocumentHeader h;
                SyndContentImpl c;
+               StringBuffer news;
                
                inDir = new File(args[0]);
                outDir = new File(args[1]);
@@ -68,34 +85,46 @@ public class Main {
                
                entries = new ArrayList<SyndEntry>();
                
+               news = new StringBuffer();
+               news.append("<html>\n");
+               news.append("<body>\n");
                for (File adoc: adocs) {
                        if (!adoc.getName().endsWith(".adoc"))
                                continue;                       
-                       sw = new StringWriter();
+                       desc = new StringWriter();
                                                
-                       html = getHTMLFile(outDir, adoc);
+                       html = toHTMLFile(outDir, adoc);
                                
                        h = asciidoctor.readDocumentHeader(adoc);
                                                            
-                       asciidoctor.convert(new FileReader(adoc), sw, new HashMap<String,Object>());
+                       asciidoctor.convert(new FileReader(adoc), desc, 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());
+                       c = toSyndContentImpl(desc.toString());
                        
                        e.setDescription(c);
                        
                        entries.add(e);
+
+                       news.append("\n<div>\n");
+                       news.append("<h2>");
+                       news.append(h.getDocumentTitle().getMain());
+                       news.append("</h2>\n");
+                       news.append(desc.toString());
+                       news.append("\n</div>\n");          
                }
+               news.append("</body>\n");
+               news.append("</html>\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
+}