X-Git-Url: https://git.wpitchoune.net/gitweb/?p=asciidoctor_to_rss.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fwpitchoune%2Fasciidoctor%2FMain.java;h=d5b19a1ce0ea9a01a631745e56b8036363d6096e;hp=43f0a88d081928821c1987cbf00b502b47c8a5ac;hb=c1e2d41cde5071c8a14fe0d9ec74f8a4fe8611bb;hpb=fe214ade97ce439e19fc80fcf945f695638f16ed diff --git a/src/main/java/net/wpitchoune/asciidoctor/Main.java b/src/main/java/net/wpitchoune/asciidoctor/Main.java index 43f0a88..d5b19a1 100644 --- a/src/main/java/net/wpitchoune/asciidoctor/Main.java +++ b/src/main/java/net/wpitchoune/asciidoctor/Main.java @@ -23,14 +23,12 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; 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.logging.Logger; import org.asciidoctor.Asciidoctor; import org.asciidoctor.Asciidoctor.Factory; @@ -51,10 +49,10 @@ import com.rometools.rome.io.SyndFeedOutput; * @author jeanfi@gmail.com */ public class Main { - private static final Logger LOG = Logger.getLogger(Main.class.getSimpleName()); - 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; @@ -79,66 +77,6 @@ public class Main { return ret; } - private static void appendHTMLHead(StringBuffer sb, Configuration cfg) - throws IOException { - File f; - - f = cfg.getHTMLHeaderFile(); - if (f == null) { - LOG.info("There is no declared HTML header file."); - return ; - } - - sb.append("\n"); - sb.append("\n"); - sb.append("\n"); - sb.append(new String(Files.readAllBytes(f.toPath()), - StandardCharsets.UTF_8)); - sb.append("\n"); - } - - private static void appendHTMLFooter(StringBuffer sb) { - sb.append("\n"); - sb.append(""); - } - - private static void appendHTMLContentHeader(StringBuffer sb, String title) { - sb.append(""); - } - - private static void generateHTMLFileItem(File file, - String title, - String content, - String date, - Configuration cfg) throws IOException { - StringBuffer buf; - - buf = new StringBuffer(); - - appendHTMLHead(buf, cfg); - - buf.append("\n"); - - appendHTMLContentHeader(buf, title); - - buf.append("
\n"); - if (date != null) { - buf.append("
"); - buf.append(date); - buf.append("
"); - } - buf.append(content); - buf.append("
"); - - appendHTMLFooter(buf); - - Files.write(file.toPath(), buf.toString().getBytes()); - } - public static void main(String[] args) throws FileNotFoundException, IOException, FeedException, ParseException { File inDir, html, outDir; File[] adocs; @@ -148,13 +86,8 @@ public class Main { ArrayList entries; SyndEntryImpl e; DocumentHeader h; - SyndContentImpl c; - StringBuffer news; String itemTitle, itemContent, itemURI, strDate; Date itemDate; - SimpleDateFormat sdf; - - sdf = new SimpleDateFormat("yyyy-dd-MM"); inDir = new File(args[0]); outDir = new File(args[1]); @@ -170,16 +103,6 @@ public class Main { entries = new ArrayList(); - news = new StringBuffer(); - - appendHTMLHead(news, cfg); - - news.append("\n"); - - appendHTMLContentHeader(news, cfg.getFeedTitle()); - - news.append("
\n"); - for (File adoc: adocs) { if (!adoc.getName().endsWith(".adoc")) continue; @@ -194,7 +117,7 @@ public class Main { else strDate = h.getAttributes().get("date").toString(); - itemDate = sdf.parse(strDate); + itemDate = DATE_FORMATTER.parse(strDate); asciidoctor.convert(new FileReader(adoc), desc, new HashMap()); @@ -208,37 +131,20 @@ public class Main { e.setLink(itemURI); e.setPublishedDate(itemDate); - c = toSyndContentImpl(itemContent); + e.setDescription(toSyndContentImpl(itemContent)); - e.setDescription(c); + entries.add(e); - entries.add(e); - - news.append("\n
"); - news.append("

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

"); - if (news != null) { - news.append("
"); - news.append(itemDate); - news.append("
"); - } - news.append(desc.toString()); - news.append("
\n"); - - generateHTMLFileItem(html, itemTitle, itemContent, itemDate.toString(), cfg); + Files.write(html.toPath(), new HTML(cfg).toHTML(e).getBytes()); } - news.append("
\n"); - - appendHTMLFooter(news); - feed.setEntries(entries); feed.setFeedType("rss_2.0"); SyndFeedOutput output = new SyndFeedOutput(); output.output(feed, new File(outDir, "feed.xml")); - Files.write(new File(outDir, "news.html").toPath(), news.toString().getBytes()); + Files.write(new File(outDir, "news.html").toPath(), + new HTML(cfg).toHTML(feed.getEntries()).getBytes()); } }