projects
/
asciidoctor_to_rss.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed date output
[asciidoctor_to_rss.git]
/
src
/
main
/
java
/
net
/
wpitchoune
/
asciidoctor
/
Main.java
diff --git
a/src/main/java/net/wpitchoune/asciidoctor/Main.java
b/src/main/java/net/wpitchoune/asciidoctor/Main.java
index
f68f354
..
4cfe7fd
100644
(file)
--- 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.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
-import java.io.FileWriter;
import java.io.IOException;
import java.io.IOException;
-import java.io.InputStream;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
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.ArrayList;
+import java.util.Date;
import java.util.HashMap;
import java.util.HashMap;
-import java.util.Properties;
import java.util.logging.Logger;
import org.asciidoctor.Asciidoctor;
import java.util.logging.Logger;
import org.asciidoctor.Asciidoctor;
@@
-56,6
+55,10
@@
public class Main {
private static final Asciidoctor asciidoctor = Factory.create();
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;
private static File toHTMLFile(File dir, File adoc) {
int idx;
String name;
@@
-114,6
+117,7
@@
public class Main {
private static void generateHTMLFileItem(File file,
String title,
String content,
private static void generateHTMLFileItem(File file,
String title,
String content,
+ String date,
Configuration cfg) throws IOException {
StringBuffer buf;
Configuration cfg) throws IOException {
StringBuffer buf;
@@
-126,6
+130,11
@@
public class Main {
appendHTMLContentHeader(buf, title);
buf.append("<div id='content'>\n");
appendHTMLContentHeader(buf, title);
buf.append("<div id='content'>\n");
+ if (date != null) {
+ buf.append("<div class='date'>");
+ buf.append(date);
+ buf.append("</div>");
+ }
buf.append(content);
buf.append("</div>");
buf.append(content);
buf.append("</div>");
@@
-134,7
+143,7
@@
public class Main {
Files.write(file.toPath(), buf.toString().getBytes());
}
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;
File inDir, html, outDir;
File[] adocs;
StringWriter desc;
@@
-145,7
+154,8
@@
public class Main {
DocumentHeader h;
SyndContentImpl c;
StringBuffer news;
DocumentHeader h;
SyndContentImpl c;
StringBuffer news;
- String itemTitle, itemContent;
+ String itemTitle, itemContent, itemURI, strDate;
+ Date itemDate;
inDir = new File(args[0]);
outDir = new File(args[1]);
inDir = new File(args[0]);
outDir = new File(args[1]);
@@
-179,7
+189,14
@@
public class Main {
html = toHTMLFile(outDir, adoc);
h = asciidoctor.readDocumentHeader(adoc);
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<String,Object>());
itemTitle = h.getDocumentTitle().getMain();
asciidoctor.convert(new FileReader(adoc), desc, new HashMap<String,Object>());
itemTitle = h.getDocumentTitle().getMain();
@@
-187,7
+204,10
@@
public class Main {
e = new SyndEntryImpl();
e.setTitle(itemTitle);
e = new SyndEntryImpl();
e.setTitle(itemTitle);
- e.setUri(cfg.getFeedBaseURL() + "/" + html.getName());
+ itemURI = cfg.getFeedBaseURL() + "/" + html.getName();
+ e.setUri(itemURI);
+ e.setLink(itemURI);
+ e.setPublishedDate(itemDate);
c = toSyndContentImpl(itemContent);
c = toSyndContentImpl(itemContent);
@@
-199,10
+219,15
@@
public class Main {
news.append("<h2>");
news.append(itemTitle);
news.append("</h2>");
news.append("<h2>");
news.append(itemTitle);
news.append("</h2>");
+ if (news != null) {
+ news.append("<div class='date'>");
+ news.append(DATE_FORMATTER.format(itemDate));
+ news.append("</div>");
+ }
news.append(desc.toString());
news.append("</div>\n");
news.append(desc.toString());
news.append("</div>\n");
- generateHTMLFileItem(html, itemTitle, itemContent, cfg);
+ generateHTMLFileItem(html, itemTitle, itemContent,
itemDate.toString(),
cfg);
}
news.append("</div>\n");
}
news.append("</div>\n");
@@
-215,7
+240,6
@@
public class Main {
SyndFeedOutput output = new SyndFeedOutput();
output.output(feed, new File(outDir, "feed.xml"));
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());
}
}
Files.write(new File(outDir, "news.html").toPath(), news.toString().getBytes());
}
}