diff --git a/pom.xml b/pom.xml index c065770..d8c0de7 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,7 @@ + org.apache.maven.plugins maven-shade-plugin diff --git a/src/main/java/eu/m724/blog/Main.java b/src/main/java/eu/m724/blog/Main.java index dd52fd9..4e763d9 100644 --- a/src/main/java/eu/m724/blog/Main.java +++ b/src/main/java/eu/m724/blog/Main.java @@ -23,29 +23,37 @@ public class Main { var options = new Options() .addOption("h", "help", false, "Show help") .addOption("f", "force", false, "Overwrite current build") - .addOption("dir", "working-dir", true, "Working directory. Default: current directory") .addOption("t", "template-dir", true, "Template directory. Default: working directory/template") .addOption("o", "output-dir", true, "Output directory. Default: working directory/generated_out") - .addOption("s", "server", false, "Run webserver. Default: no"); + .addOption("s", "server", false, "Run webserver. Default: no") + .addOption("d", "draft", false, "Render drafts. Default: only with server"); CommandLine commandLine; + String wdStr; try { commandLine = new DefaultParser().parse(options, args); + if (commandLine.hasOption("help")) throw new ParseException("Showing help"); + + if (commandLine.getArgs().length == 0) + throw new ParseException("Missing required argument: WORKDIR"); + + wdStr = commandLine.getArgs()[0]; } catch (ParseException e) { System.out.println(e.getMessage()); - new HelpFormatter().printHelp("blog-software-java", options); + new HelpFormatter().printHelp("blog-software-java [OPTION]... [WORKDIR]", options); System.exit(1); return; } - var workingDirectory = Path.of(commandLine.getOptionValue("working-dir", ".")); + var workingDirectory = Path.of(wdStr); var templateDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("template").toString())); var outputDirectory = Path.of(commandLine.getOptionValue("output-dir", workingDirectory.resolve("generated_out").toString())); var force = commandLine.hasOption("force"); + var renderDrafts = commandLine.hasOption("draft"); var server = commandLine.hasOption("server"); var openBrowser = true; @@ -65,7 +73,7 @@ public class Main { if (force) { PathUtils.deleteDirectory(outputDirectory); } else { - throw new FileAlreadyExistsException(outputDirectory.toString(), null, "Output directory already exists"); + throw new FileAlreadyExistsException(outputDirectory.toString(), null, "Output directory already exists. --force?"); } } @@ -94,6 +102,11 @@ public class Main { path = postDirectory.relativize(path); var post = Post.fromFile(git, path); + if (post.draft() && !renderDrafts) { + System.out.println("Post " + path.getFileName() + ": draft, ignoring"); + continue; + } + var render = template.renderPost(site, post); var outFile = outputDirectory.resolve("post").resolve(path);