added uri to the feed item
[asciidoctor_to_rss.git] / src / main / java / net / wpitchoune / asciidoctor / Main.java
index 5e687c3..1e09ab0 100644 (file)
@@ -22,6 +22,7 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.StringWriter;
@@ -88,8 +89,6 @@ public class Main {
                        LOG.info("There is no declared HTML header file.");
                        return ;
                }
-               
-               
 
                sb.append("<!DOCTYPE html>\n");
                sb.append("<html>\n");                          
@@ -99,6 +98,11 @@ public class Main {
                sb.append("</head>\n");
         }
         
+        private static void appendHTMLFooter(StringBuffer sb) {
+               sb.append("</body>\n");
+               sb.append("</html>");           
+        }
+        
         private static void appendHTMLContentHeader(StringBuffer sb, String title) {
                sb.append("<div id='header'>\n");
                sb.append("<h1>");
@@ -107,8 +111,27 @@ public class Main {
                sb.append("</div>");
         }               
         
-        private static void generateHTMLFileItem(String itemTitle, String itemContent) {
+        private static void generateHTMLFileItem(File file,
+                                                String title,
+                                                String content,
+                                                Configuration cfg) throws IOException {
+               StringBuffer buf;
+               
+               buf = new StringBuffer();
+               
+               appendHTMLHead(buf, cfg);
                
+               buf.append("<body>\n");
+               
+               appendHTMLContentHeader(buf, title);
+               
+               buf.append("<div id='content'>\n");
+               buf.append(content);
+               buf.append("</div>");
+               
+               appendHTMLFooter(buf);
+               
+               Files.write(file.toPath(), buf.toString().getBytes());
         }
         
        public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
@@ -122,7 +145,7 @@ public class Main {
                DocumentHeader h;
                SyndContentImpl c;
                StringBuffer news;
-               String itemTitle, itemContent;
+               String itemTitle, itemContent, itemURI;
                
                inDir = new File(args[0]);
                outDir = new File(args[1]);
@@ -164,7 +187,10 @@ public class Main {
                        
                        e = new SyndEntryImpl();
                        e.setTitle(itemTitle);
-                       e.setUri(cfg.getFeedBaseURL() + "/" + html.getName());
+                       itemURI = cfg.getFeedBaseURL() + "/" + html.getName(); 
+                       e.setUri(itemURI);
+                       e.setLink(itemURI);
+                       
                        
                        c = toSyndContentImpl(itemContent);
                        
@@ -172,20 +198,19 @@ public class Main {
                        
                        entries.add(e);
 
-                       news.append("\n<div>\n");
+                       news.append("\n<div>");
                        news.append("<h2>");
-                       news.append(h.getDocumentTitle().getMain());
-                       news.append("</h2>\n");
+                       news.append(itemTitle);
+                       news.append("</h2>");
                        news.append(desc.toString());
-                       news.append("\n</div>\n");     
+                       news.append("</div>\n");     
                        
-                       generateHTMLFileItem(itemTitle, itemContent);
+                       generateHTMLFileItem(html, itemTitle, itemContent, cfg);
                }
                
                news.append("</div>\n");
                
-               news.append("</body>\n");
-               news.append("</html>\n");
+               appendHTMLFooter(news);
                
                feed.setEntries(entries);