X-Git-Url: https://git.wpitchoune.net/gitweb/?p=asciidoctor_to_rss.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fwpitchoune%2Fasciidoctor%2FHTML.java;h=8c3bc0b8da8f5adf9f618506ad9a97e66e7a8027;hp=0b79da146037f62398526cb0370c291caf1cf3c6;hb=c1e2d41cde5071c8a14fe0d9ec74f8a4fe8611bb;hpb=8c8b7a5a3a2272e3856b9e1b306637db28b6a46a diff --git a/src/main/java/net/wpitchoune/asciidoctor/HTML.java b/src/main/java/net/wpitchoune/asciidoctor/HTML.java index 0b79da1..8c3bc0b 100644 --- a/src/main/java/net/wpitchoune/asciidoctor/HTML.java +++ b/src/main/java/net/wpitchoune/asciidoctor/HTML.java @@ -42,7 +42,7 @@ public final class HTML { this.config = config; } - public static void appendHTMLHead(StringBuffer sb, Configuration config) + public static void appendHTMLHead(StringBuffer sb, String title, Configuration config) throws IOException { File f; @@ -57,11 +57,14 @@ public final class HTML { sb.append("\n"); sb.append(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8)); + sb.append(""); + sb.append(title); + sb.append("\n"); sb.append("\n"); } - private void appendHTMLHead(StringBuffer sb) throws IOException { - appendHTMLHead(sb, config); + private void appendHTMLHead(StringBuffer sb, String title) throws IOException { + appendHTMLHead(sb, title, config); } public static void appendHTMLContentHeader(StringBuffer sb, String title) { @@ -83,7 +86,7 @@ public final class HTML { buf = new StringBuffer(); - appendHTMLHead(buf); + appendHTMLHead(buf, entry.getTitle()); buf.append("\n"); @@ -103,6 +106,32 @@ public final class HTML { return buf.toString(); } + private static void appendStartTag(StringBuffer buf, String tag, int indent, boolean newline) { + while (indent > 0) { + buf.append('\t'); + indent--; + } + buf.append('<'); + buf.append(tag); + buf.append(">"); + + if (newline) + buf.append('\n'); + } + + private static void appendEndTag(StringBuffer buf, String tag, int indent, boolean newline) { + while (indent > 0) { + buf.append('\t'); + indent--; + } + buf.append(""); + + if (newline) + buf.append('\n'); + } + public String toHTML(Collection entries) throws IOException { StringBuffer buf; List sortedEntries; @@ -110,38 +139,44 @@ public final class HTML { buf = new StringBuffer(); - appendHTMLHead(buf); + appendHTMLHead(buf, config.getFeedTitle()); - buf.append("\n"); + appendStartTag(buf, "body", 1, true); appendHTMLContentHeader(buf, config.getFeedTitle()); buf.append("
\n"); cmp = new Comparator() { - @Override public int compare(SyndEntry o1, SyndEntry o2) { return o2.getPublishedDate().compareTo(o1.getPublishedDate()); - } - + } }; sortedEntries = new ArrayList(entries); Collections.sort(sortedEntries, cmp); for(SyndEntry e: sortedEntries) { - buf.append("\n
"); - buf.append("

"); + appendStartTag(buf, "article", 3, true); + appendStartTag(buf, "header", 4, true); + appendStartTag(buf, "h1", 5, false); + buf.append(""); buf.append(e.getTitle()); - buf.append("

"); + buf.append(""); + appendEndTag(buf, "h1", 0, true); + if (e.getPublishedDate() != null) { - buf.append("
"); - buf.append(DATE_FORMATTER.format(e.getPublishedDate())); - buf.append("
"); + buf.append("
"); + buf.append(DATE_FORMATTER.format(e.getPublishedDate())); + buf.append("
\n"); } + + appendEndTag(buf, "header", 4, true); + buf.append(e.getDescription().getValue()); - buf.append("
\n"); + + appendEndTag(buf, "article", 3, true); } buf.append("
\n");