This commit is contained in:
parent
9b681dbec1
commit
cbb7dab7f3
2 changed files with 19 additions and 5 deletions
1
pom.xml
1
pom.xml
|
@ -58,6 +58,7 @@
|
|||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue