Add title in index pages, add reference in story
[gofetch.git] / src / be / nikiroo / gofetch / output / Html.java
index 50fe2d7fac8848e50c2efe41929567e2fa92c15c..0bcc833c330eb58b7b0ea24ac960bf0acf1650c8 100644 (file)
@@ -2,7 +2,9 @@ package be.nikiroo.gofetch.output;
 
 import be.nikiroo.gofetch.data.Comment;
 import be.nikiroo.gofetch.data.Story;
-import be.nikiroo.gofetch.support.BasicSupport.Type;
+import be.nikiroo.gofetch.support.BasicSupport;
+import be.nikiroo.gofetch.support.Type;
+import be.nikiroo.utils.StringUtils;
 
 public class Html extends Output {
        public Html(Type type, String hostname, String preselector, int port) {
@@ -10,7 +12,7 @@ public class Html extends Output {
        }
 
        @Override
-       public String getIndexHeader() {
+       public String getMainIndexHeader() {
                String sel = preselector;
                if (!sel.isEmpty()) {
                        sel = "/1" + sel;
@@ -21,7 +23,7 @@ public class Html extends Output {
                StringBuilder builder = new StringBuilder();
                appendPre(builder);
 
-               builder.append("<h1>News</h1>\n"//
+               builder.append("<h2>News</h2>\n"//
                                + "<p>You will find here a few pages full of news, mirroring <a href='"
                                + gopherUrl + "'>"
                                + gopherUrl
@@ -35,7 +37,17 @@ public class Html extends Output {
        }
 
        @Override
-       public String getIndexFooter() {
+       public String getMainIndexFooter() {
+               return "";
+       }
+
+       @Override
+       public String getIndexHeader(BasicSupport support) {
+               return "<h1>" + support.getDescription() + "</h1>\n<br/><br/>";
+       }
+
+       @Override
+       public String getIndexFooter(BasicSupport support) {
                return "";
        }
 
@@ -97,9 +109,10 @@ public class Html extends Output {
        private void appendHtml(StringBuilder builder, Comment comment, String space) {
                builder.append(space)
                                .append("<div class='comment' style='display: block; margin-left: 80px'>\n");
-               builder.append(space).append("  <h2>").append(comment.getTitle())
-                               .append("</h2>\n");
-               builder.append(space).append("  <div class='by' style='font-style: italic;'>")
+               builder.append(space).append("  <h3>").append(comment.getTitle())
+                               .append("</h3>\n");
+               builder.append(space)
+                               .append("  <div class='by' style='font-style: italic;'>")
                                .append(comment.getAuthor()).append("</div>\n");
                builder.append(space).append("  <div class='comment_content'>");
                for (String line : comment.getContentLines()) {
@@ -115,21 +128,25 @@ public class Html extends Output {
        private StringBuilder appendHtml(StringBuilder builder, Story story,
                        boolean resume) {
                if (resume) {
-                       builder.append("        <h1><a href='" + story.getId() + ".html'>"
-                                       + story.getTitle() + "</a></h1>\n");
+                       builder.append("        <h2><a href='" + story.getId() + ".html'>"
+                                       + story.getTitle() + "</a></h2>\n");
                } else {
-                       builder.append("        <h1>" + story.getTitle() + "</h1>\n");
+                       builder.append("        <h2>" + story.getTitle() + "</h2>\n");
                }
 
                builder.append("        <div class='details'>");
                if (story.getDetails() != null && !story.getDetails().isEmpty()) {
-                       builder.append("(").append(story.getDetails()).append(")");
+                       builder.append("(")
+                                       .append(StringUtils.xmlEscape(story.getDetails()))
+                                       .append(")");
                }
                builder.append("</div>\n");
                builder.append("        <br/>\n");
 
                if (!resume) {
                        builder.append("    <ul>\n");
+                       builder.append("    <li>Reference: <a href=''>" + story.getId()
+                                       + "</a></li>\n");
                        builder.append("        <li>News link: <a href='"
                                        + story.getUrlInternal() + "'>" + story.getUrlInternal()
                                        + "</a></li>\n");
@@ -142,12 +159,13 @@ public class Html extends Output {
 
                builder.append("        <div class='content' style='text-align: justify'>\n");
                if (resume) {
-                       builder.append("                " + story.getContent() + "\n");
+                       builder.append("                " + StringUtils.xmlEscape(story.getContent())
+                                       + "\n");
                } else {
                        builder.append("                "
-                                       + story.getFullContent().replace("\n", "<br/>")
-                                                       .replace("[ ", "<h2>").replace(" ]", "</h2>")
-                                       + "\n");
+                                       + StringUtils.xmlEscape(story.getFullContent())
+                                                       .replace("\n", "<br/>").replace("[ ", "<h3>")
+                                                       .replace(" ]", "</h3>") + "\n");
                }
                builder.append("        </div>\n");