+++ /dev/null
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.logging.Logger;
-
-import org.asciidoctor.Asciidoctor;
-import org.asciidoctor.Asciidoctor.Factory;
-import org.asciidoctor.ast.DocumentHeader;
-
-import com.rometools.rome.feed.synd.SyndContentImpl;
-import com.rometools.rome.feed.synd.SyndEntry;
-import com.rometools.rome.feed.synd.SyndEntryImpl;
-import com.rometools.rome.feed.synd.SyndFeed;
-import com.rometools.rome.feed.synd.SyndFeedImpl;
-import com.rometools.rome.io.FeedException;
-import com.rometools.rome.io.SyndFeedOutput;
-
-public class Main {
- private static final Logger LOG = Logger.getLogger(Main.class.getSimpleName());
- private static final String KEY_HTML_HEADER_FILE = "html.header.file";
- private static final String KEY_FEED_TITLE = "feed.title";
-
- private static File toHTMLFile(File dir, File adoc) {
- int idx;
- String name;
-
- name = adoc.getName();
-
- idx = name.lastIndexOf('.');
-
- if (idx >= 0)
- name = name.substring(0, idx);
-
- return new File(dir, name + ".html");
- }
-
- private static SyndContentImpl toSyndContentImpl(String description) {
- SyndContentImpl ret;
-
- ret = new SyndContentImpl();
- ret.setType("text/html");
- ret.setValue(description);
-
- return ret;
- }
-
- private static String getFeedTitle(Properties props) {
- return props.getProperty(KEY_FEED_TITLE);
- }
-
- private static void appendHTMLHeader(StringBuffer sb, Properties props)
- throws IOException {
- String fileName;
- File f;
-
- fileName = props.getProperty(KEY_HTML_HEADER_FILE);
-
- if (fileName == null) {
- LOG.info(KEY_HTML_HEADER_FILE + " is not set");
- return ;
- }
-
- f = new File(fileName);
-
- sb.append("<head>\n");
- sb.append(new String(Files.readAllBytes(f.toPath()),
- StandardCharsets.UTF_8));
- sb.append("</head>\n");
- }
-
- public static void main(String[] args) throws FileNotFoundException, IOException, FeedException {
- File inDir, html, outDir;
- File[] adocs;
- StringWriter desc;
- Asciidoctor asciidoctor;
- SyndFeed feed;
- Properties props;
- ArrayList<SyndEntry> entries;
- SyndEntryImpl e;
- InputStream in;
- DocumentHeader h;
- SyndContentImpl c;
- StringBuffer news;
-
- inDir = new File(args[0]);
- outDir = new File(args[1]);
-
- props = new Properties();
- in = new FileInputStream(args[2]);
- props.load(in);
- in.close();
-
- adocs = inDir.listFiles();
-
- asciidoctor = Factory.create();
-
- feed = new SyndFeedImpl();
- feed.setTitle(getFeedTitle(props));
- feed.setDescription(props.getProperty("feed.description"));
- feed.setLink(props.getProperty("feed.link"));
-
- entries = new ArrayList<SyndEntry>();
-
- news = new StringBuffer();
- news.append("<!DOCTYPE html>\n");
- news.append("<html>\n");
-
- appendHTMLHeader(news, props);
-
- news.append("<body>\n");
-
- news.append("<div id='header'>\n");
- news.append("<h1>");
- news.append(getFeedTitle(props));
- news.append("</h1>\n");
- news.append("</div>");
-
- news.append("<div id='content'>\n");
-
- for (File adoc: adocs) {
- if (!adoc.getName().endsWith(".adoc"))
- continue;
- desc = new StringWriter();
-
- html = toHTMLFile(outDir, adoc);
-
- h = asciidoctor.readDocumentHeader(adoc);
-
- asciidoctor.convert(new FileReader(adoc), desc, new HashMap<String,Object>());
-
- e = new SyndEntryImpl();
- e.setTitle(h.getDocumentTitle().getMain());
- e.setUri(props.getProperty("feed.baseurl") + "/" + html.getName());
-
- c = toSyndContentImpl(desc.toString());
-
- e.setDescription(c);
-
- entries.add(e);
-
- news.append("\n<div>\n");
- news.append("<h2>");
- news.append(h.getDocumentTitle().getMain());
- news.append("</h2>\n");
- news.append(desc.toString());
- news.append("\n</div>\n");
- }
-
- news.append("</div>\n");
- news.append("</body>\n");
- news.append("</html>\n");
-
- feed.setEntries(entries);
-
- feed.setFeedType("rss_2.0");
- 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());
- }
-}