date support
authorJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 4 Jul 2016 08:59:33 +0000 (10:59 +0200)
committerJean-Philippe Orsini <jeanfi@gmail.com>
Mon, 4 Jul 2016 08:59:33 +0000 (10:59 +0200)
src/main/java/net/wpitchoune/asciidoctor/Main.java

index 1e09ab0..355008c 100644 (file)
@@ -42,6 +42,7 @@ 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.feed.synd.SyndLinkImpl;
 import com.rometools.rome.io.FeedException;
 import com.rometools.rome.io.SyndFeedOutput;
 
@@ -103,17 +104,23 @@ public class Main {
                sb.append("</html>");           
         }
         
-        private static void appendHTMLContentHeader(StringBuffer sb, String title) {
+        private static void appendHTMLContentHeader(StringBuffer sb, String title, String date) {
                sb.append("<div id='header'>\n");
                sb.append("<h1>");
                sb.append(title);
                sb.append("</h1>\n");
+               if (date != null) {
+                       sb.append("<div class='date'>");
+                       sb.append(date);
+                       sb.append("</div>");
+               }
                sb.append("</div>");
         }               
         
         private static void generateHTMLFileItem(File file,
                                                 String title,
                                                 String content,
+                                                String date,
                                                 Configuration cfg) throws IOException {
                StringBuffer buf;
                
@@ -123,7 +130,7 @@ public class Main {
                
                buf.append("<body>\n");
                
-               appendHTMLContentHeader(buf, title);
+               appendHTMLContentHeader(buf, title, date);
                
                buf.append("<div id='content'>\n");
                buf.append(content);
@@ -145,7 +152,7 @@ public class Main {
                DocumentHeader h;
                SyndContentImpl c;
                StringBuffer news;
-               String itemTitle, itemContent, itemURI;
+               String itemTitle, itemContent, itemURI, itemDate;
                
                inDir = new File(args[0]);
                outDir = new File(args[1]);
@@ -167,7 +174,7 @@ public class Main {
                
                news.append("<body>\n");
                
-               appendHTMLContentHeader(news, cfg.getFeedTitle());
+               appendHTMLContentHeader(news, cfg.getFeedTitle(), null);
                
                news.append("<div id='content'>\n");
                
@@ -179,7 +186,12 @@ public class Main {
                        html = toHTMLFile(outDir, adoc);
                                
                        h = asciidoctor.readDocumentHeader(adoc);
-                                                           
+
+                       if (h.getAttributes().get("date") == null)
+                               itemDate = h.getAttributes().get("docdate").toString();
+                       else
+                               itemDate = h.getAttributes().get("date").toString();
+                       
                        asciidoctor.convert(new FileReader(adoc), desc, new HashMap<String,Object>());
                        
                        itemTitle = h.getDocumentTitle().getMain(); 
@@ -191,7 +203,6 @@ public class Main {
                        e.setUri(itemURI);
                        e.setLink(itemURI);
                        
-                       
                        c = toSyndContentImpl(itemContent);
                        
                        e.setDescription(c);
@@ -202,10 +213,13 @@ public class Main {
                        news.append("<h2>");
                        news.append(itemTitle);
                        news.append("</h2>");
+                       news.append("<div class='date'>");
+                       news.append(itemDate);
+                       news.append("</div>");
                        news.append(desc.toString());
                        news.append("</div>\n");     
                        
-                       generateHTMLFileItem(html, itemTitle, itemContent, cfg);
+                       generateHTMLFileItem(html, itemTitle, itemContent, itemDate, cfg);
                }
                
                news.append("</div>\n");
@@ -218,7 +232,6 @@ public class Main {
                SyndFeedOutput output = new SyndFeedOutput();
                output.output(feed, new File(outDir, "feed.xml"));
        
-               System.out.println(news.toString());
                Files.write(new File(outDir, "news.html").toPath(), news.toString().getBytes());
        }
 }