for now only includes compress true or false Signed-off-by: Minecon724 <git@m724.eu>
This commit is contained in:
parent
950645dcef
commit
a7ab3b400c
2 changed files with 55 additions and 4 deletions
|
@ -3,6 +3,7 @@ package eu.m724.blog;
|
||||||
import eu.m724.blog.compress.FileCompressor;
|
import eu.m724.blog.compress.FileCompressor;
|
||||||
import eu.m724.blog.data.Feed;
|
import eu.m724.blog.data.Feed;
|
||||||
import eu.m724.blog.data.Post;
|
import eu.m724.blog.data.Post;
|
||||||
|
import eu.m724.blog.data.RenderOptions;
|
||||||
import eu.m724.blog.data.Site;
|
import eu.m724.blog.data.Site;
|
||||||
import eu.m724.blog.template.TemplateRenderer;
|
import eu.m724.blog.template.TemplateRenderer;
|
||||||
import org.apache.commons.compress.compressors.CompressorException;
|
import org.apache.commons.compress.compressors.CompressorException;
|
||||||
|
@ -32,6 +33,7 @@ public class BlogBuilder {
|
||||||
|
|
||||||
private Site site;
|
private Site site;
|
||||||
private TemplateRenderer template;
|
private TemplateRenderer template;
|
||||||
|
private RenderOptions renderOptions;
|
||||||
|
|
||||||
private Path templateDirectory;
|
private Path templateDirectory;
|
||||||
private Path outputDirectory;
|
private Path outputDirectory;
|
||||||
|
@ -47,7 +49,7 @@ public class BlogBuilder {
|
||||||
|
|
||||||
this.workingDirectory = git.getRepository().getDirectory().toPath().getParent();
|
this.workingDirectory = git.getRepository().getDirectory().toPath().getParent();
|
||||||
this.templateDirectory = workingDirectory.resolve("template");
|
this.templateDirectory = workingDirectory.resolve("template");
|
||||||
this.outputDirectory = workingDirectory.resolve("generated_out");
|
this.outputDirectory = workingDirectory.resolve("generated_out");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -124,6 +126,9 @@ public class BlogBuilder {
|
||||||
if (site == null)
|
if (site == null)
|
||||||
this.site = Site.fromConfig(workingDirectory.resolve("site-config.yml"));
|
this.site = Site.fromConfig(workingDirectory.resolve("site-config.yml"));
|
||||||
|
|
||||||
|
if (renderOptions == null)
|
||||||
|
this.renderOptions = RenderOptions.fromConfig(workingDirectory.resolve("render.yml"));
|
||||||
|
|
||||||
if (template == null)
|
if (template == null)
|
||||||
this.template = new TemplateRenderer(templateDirectory);
|
this.template = new TemplateRenderer(templateDirectory);
|
||||||
|
|
||||||
|
@ -140,9 +145,10 @@ public class BlogBuilder {
|
||||||
|
|
||||||
Files.writeString(outputDirectory.resolve("posts.rss"), Feed.generateRss(site, posts));
|
Files.writeString(outputDirectory.resolve("posts.rss"), Feed.generateRss(site, posts));
|
||||||
|
|
||||||
|
if (renderOptions.compress()) {
|
||||||
System.out.println("Compressing...");
|
System.out.println("Compressing...");
|
||||||
compressOutput();
|
compressOutput();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Post> renderPosts() throws IOException {
|
private List<Post> renderPosts() throws IOException {
|
||||||
|
|
45
src/main/java/eu/m724/blog/data/RenderOptions.java
Normal file
45
src/main/java/eu/m724/blog/data/RenderOptions.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package eu.m724.blog.data;
|
||||||
|
|
||||||
|
import org.snakeyaml.engine.v2.api.Load;
|
||||||
|
import org.snakeyaml.engine.v2.api.LoadSettings;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public record RenderOptions(
|
||||||
|
boolean compress
|
||||||
|
) {
|
||||||
|
/**
|
||||||
|
* Creates a {@link Site} object by reading and parsing the configuration file at the specified path.<br>
|
||||||
|
* The configuration file must be a JSON file.
|
||||||
|
*
|
||||||
|
* @param path the path to the configuration file
|
||||||
|
* @return a {@link Site} object initialized with the data from the configuration file
|
||||||
|
* @throws IOException if an error occurs during file reading
|
||||||
|
*/
|
||||||
|
public static RenderOptions fromConfig(Path path) throws IOException {
|
||||||
|
var load = new Load(LoadSettings.builder().build());
|
||||||
|
var yaml = (Map<String, Object>) load.loadFromInputStream(Files.newInputStream(path));
|
||||||
|
|
||||||
|
boolean compress = true;
|
||||||
|
|
||||||
|
for (var key : yaml.keySet()) {
|
||||||
|
var value = yaml.get(key);
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case "compress": {
|
||||||
|
compress = (boolean) value;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
System.out.println("Unrecognized option (render): " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new RenderOptions(
|
||||||
|
compress
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue