X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fwpitchoune%2Fasciidoctor%2FMain.java;h=feb103a45ce7ce7fe6664df60f199ed7707e054b;hb=1dcb4b2f8e2eeb6b48ff80a02ac1df3dbb31ec21;hp=1e09ab05848de427c4130d9f22fd69306c9e0f79;hpb=af6778182487ef8a3a0603f31665314cd4b896f3;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 1e09ab0..feb103a 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; @@ -56,6 +55,8 @@ 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; @@ -114,6 +115,7 @@ public class Main { private static void generateHTMLFileItem(File file, String title, String content, + Date date, Configuration cfg) throws IOException { StringBuffer buf; @@ -126,6 +128,11 @@ public class Main { appendHTMLContentHeader(buf, title); buf.append("
\n"); + if (date != null) { + buf.append("
"); + buf.append(DATE_FORMATTER.format(date)); + buf.append("
"); + } buf.append(content); buf.append("
"); @@ -134,7 +141,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; @@ -145,7 +152,8 @@ public class Main { DocumentHeader h; SyndContentImpl c; StringBuffer news; - String itemTitle, itemContent, itemURI; + String itemTitle, itemContent, itemURI, strDate; + Date itemDate; inDir = new File(args[0]); outDir = new File(args[1]); @@ -179,7 +187,14 @@ public class Main { html = toHTMLFile(outDir, adoc); h = asciidoctor.readDocumentHeader(adoc); - + + if (h.getAttributes().get("date") == null) + strDate = h.getAttributes().get("docdate").toString(); + else + strDate = h.getAttributes().get("date").toString(); + + itemDate = DATE_FORMATTER.parse(strDate); + asciidoctor.convert(new FileReader(adoc), desc, new HashMap()); itemTitle = h.getDocumentTitle().getMain(); @@ -190,7 +205,7 @@ public class Main { itemURI = cfg.getFeedBaseURL() + "/" + html.getName(); e.setUri(itemURI); e.setLink(itemURI); - + e.setPublishedDate(itemDate); c = toSyndContentImpl(itemContent); @@ -202,10 +217,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, cfg); + generateHTMLFileItem(html, itemTitle, itemContent, itemDate, cfg); } news.append("\n"); @@ -218,7 +238,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()); } }