X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fwpitchoune%2Fasciidoctor%2FMain.java;h=4cfe7fdd3756f8bddae6525806f1f9ad6f4fdd78;hb=c91f9f4b786aedc2e0119964eafd08596da63152;hp=adbb92dd27d6684f3139844d0296405051c09604;hpb=94281535899dbc050e86cea4f2eeca068cb5193e;p=asciidoctor_to_rss.git diff --git a/src/main/java/net/wpitchoune/asciidoctor/Main.java b/src/main/java/net/wpitchoune/asciidoctor/Main.java index adbb92d..4cfe7fd 100644 --- a/src/main/java/net/wpitchoune/asciidoctor/Main.java +++ b/src/main/java/net/wpitchoune/asciidoctor/Main.java @@ -19,18 +19,17 @@ package net.wpitchoune.asciidoctor; */ 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; import java.nio.charset.StandardCharsets; import java.nio.file.Files; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; -import java.util.Properties; import java.util.logging.Logger; import org.asciidoctor.Asciidoctor; @@ -42,7 +41,6 @@ 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; @@ -57,6 +55,10 @@ public class Main { private static final Asciidoctor asciidoctor = Factory.create(); + private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-dd-MM"); + + + private static File toHTMLFile(File dir, File adoc) { int idx; String name; @@ -141,7 +143,7 @@ public class Main { Files.write(file.toPath(), buf.toString().getBytes()); } - public static void main(String[] args) throws FileNotFoundException, IOException, FeedException { + public static void main(String[] args) throws FileNotFoundException, IOException, FeedException, ParseException { File inDir, html, outDir; File[] adocs; StringWriter desc; @@ -152,7 +154,8 @@ public class Main { DocumentHeader h; SyndContentImpl c; StringBuffer news; - String itemTitle, itemContent, itemURI, itemDate; + String itemTitle, itemContent, itemURI, strDate; + Date itemDate; inDir = new File(args[0]); outDir = new File(args[1]); @@ -188,9 +191,11 @@ public class Main { h = asciidoctor.readDocumentHeader(adoc); if (h.getAttributes().get("date") == null) - itemDate = h.getAttributes().get("docdate").toString(); + strDate = h.getAttributes().get("docdate").toString(); else - itemDate = h.getAttributes().get("date").toString(); + strDate = h.getAttributes().get("date").toString(); + + itemDate = DATE_FORMATTER.parse(strDate); asciidoctor.convert(new FileReader(adoc), desc, new HashMap()); @@ -202,6 +207,7 @@ public class Main { itemURI = cfg.getFeedBaseURL() + "/" + html.getName(); e.setUri(itemURI); e.setLink(itemURI); + e.setPublishedDate(itemDate); c = toSyndContentImpl(itemContent); @@ -213,10 +219,15 @@ public class Main { news.append("

"); news.append(itemTitle); news.append("

"); + if (news != null) { + news.append("
"); + news.append(DATE_FORMATTER.format(itemDate)); + news.append("
"); + } news.append(desc.toString()); news.append("\n"); - generateHTMLFileItem(html, itemTitle, itemContent, itemDate, cfg); + generateHTMLFileItem(html, itemTitle, itemContent, itemDate.toString(), cfg); } news.append("\n");