Signed-off-by: Minecon724 <git@m724.eu>
This commit is contained in:
parent
42a73ece51
commit
159519c94d
3 changed files with 12 additions and 10 deletions
|
@ -1,3 +1,5 @@
|
||||||
# Render options here
|
# Render options here
|
||||||
|
|
||||||
compress: true
|
compress:
|
||||||
|
- gz
|
||||||
|
- zstd
|
|
@ -7,7 +7,6 @@ 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;
|
||||||
import org.apache.commons.compress.compressors.CompressorStreamFactory;
|
|
||||||
import org.apache.commons.io.file.PathUtils;
|
import org.apache.commons.io.file.PathUtils;
|
||||||
import org.eclipse.jgit.api.Git;
|
import org.eclipse.jgit.api.Git;
|
||||||
import org.eclipse.jgit.lib.RepositoryBuilder;
|
import org.eclipse.jgit.lib.RepositoryBuilder;
|
||||||
|
@ -145,7 +144,7 @@ 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()) {
|
if (!renderOptions.compress().isEmpty()) {
|
||||||
System.out.println("Compressing...");
|
System.out.println("Compressing...");
|
||||||
compressOutput();
|
compressOutput();
|
||||||
}
|
}
|
||||||
|
@ -191,10 +190,9 @@ public class BlogBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void compressOutput() throws IOException {
|
private void compressOutput() throws IOException {
|
||||||
var compressors = new FileCompressor[] {
|
var compressors = renderOptions.compress().stream()
|
||||||
new FileCompressor(CompressorStreamFactory.GZIP),
|
.map(FileCompressor::new)
|
||||||
new FileCompressor(CompressorStreamFactory.ZSTANDARD)
|
.toList();
|
||||||
};
|
|
||||||
|
|
||||||
Set<Path> tree;
|
Set<Path> tree;
|
||||||
try (var walk = Files.walk(outputDirectory)) {
|
try (var walk = Files.walk(outputDirectory)) {
|
||||||
|
|
|
@ -6,10 +6,12 @@ import org.snakeyaml.engine.v2.api.LoadSettings;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public record RenderOptions(
|
public record RenderOptions(
|
||||||
boolean compress
|
List<String> compress // TODO rename?
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Creates a {@link Site} object by reading and parsing the configuration file at the specified path.<br>
|
* Creates a {@link Site} object by reading and parsing the configuration file at the specified path.<br>
|
||||||
|
@ -23,14 +25,14 @@ public record RenderOptions(
|
||||||
var load = new Load(LoadSettings.builder().build());
|
var load = new Load(LoadSettings.builder().build());
|
||||||
var yaml = (Map<String, Object>) load.loadFromInputStream(Files.newInputStream(path));
|
var yaml = (Map<String, Object>) load.loadFromInputStream(Files.newInputStream(path));
|
||||||
|
|
||||||
boolean compress = true;
|
List<String> compress = new ArrayList<>();
|
||||||
|
|
||||||
for (var key : yaml.keySet()) {
|
for (var key : yaml.keySet()) {
|
||||||
var value = yaml.get(key);
|
var value = yaml.get(key);
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case "compress": {
|
case "compress": {
|
||||||
compress = (boolean) value;
|
compress = (List<String>) value;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
System.out.println("Unrecognized option (render): " + key);
|
System.out.println("Unrecognized option (render): " + key);
|
||||||
|
|
Loading…
Add table
Reference in a new issue