import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.util.AbstractMap; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; import java.util.stream.Collectors; public class sigPlace { final static String ROOTDIR = "sitefiles"; final static String REFDIR = "ref"; final static String OUTDIR = "out"; static int PORT = 8080; final static HashMap map = new HashMap<>(Map.ofEntries( new AbstractMap.SimpleEntry<>("$SITENAME", "SigPlace"), new AbstractMap.SimpleEntry<>("$SITE_BACKCOL", "#111"), new AbstractMap.SimpleEntry<>("$TITLE_CONTENT_START", "

"), new AbstractMap.SimpleEntry<>("$TITLE_CONTENT_END", "

"), new AbstractMap.SimpleEntry<>("$CONTENT_END", "
"), new AbstractMap.SimpleEntry<>("$DATE_CONTENT_START", "
") )); final static HashMap ops = new HashMap<>(Map.ofEntries( new AbstractMap.SimpleEntry<>( "%DEFAULT", Paths.get(REFDIR,"DEFAULT.html")), new AbstractMap.SimpleEntry<>( "%FOOTER", Paths.get(REFDIR,"FOOTER.html")) )); public static void main(String[] args) { if (args.length>0&&args.length%2==0) { int i=0; while (i files = GetFilesInDir(ROOTDIR); for (Path f : files) { System.out.println(" Found "+f.getFileName()); try { System.out.println(" Preparing "+f.getFileName()); List content = Files.readAllLines(f); if (isHTMLFile(f)) { content.addAll(0,Files.readAllLines(ops.get("%DEFAULT"))); content.addAll(Files.readAllLines(ops.get("%FOOTER"))); } System.out.println(" Parsing "+f.getFileName()); for (int i=0;i0&&isHTMLFile(f)) { //Check for markdown pieces. if (s.charAt(0)=='-') { //Start of a title piece. s=s.replace("-",map.get("$TITLE_CONTENT_START")); s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+i+"\""); //Use ⤈ if there's more text to be shown than can fit. } else if (s.contains("===")) { s="


⤈ Click to expand.
"+map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+map.get("$CONTENT_END"); } } for (String key : map.keySet()) { s=s.replaceAll(Pattern.quote(key),map.get(key)); } content.set(i,s); } Path newf = Paths.get(OUTDIR,f.getFileName().toString()); System.out.println(" Writing to "+newf); Files.write(newf, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE); System.out.println(" "+newf.getFileName() + " conversion complete!"); } catch (IOException e) { e.printStackTrace(); } } System.out.println("Site has been built into the "+OUTDIR+" directory."); ExportCodeFile(); System.out.println("\nStarting web server..."); new sigServer(); } private static boolean isHTMLFile(Path f) { return f.getFileName().toString().contains(".html"); } private static void ExportCodeFile() { try { Path file = Paths.get("sigServer.java"); List data = Files.readAllLines(file); int i=0; while (!data.get(i++).contains("sigServer()")&&i GetFilesInDir(String directory) { Path dir = Paths.get(directory); try { return Files.list(dir).collect(Collectors.toSet()); } catch (IOException e) { e.printStackTrace(); } return null; } }