From 1354d94817b19500019b121d670c9e6adaaa4ea3 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Thu, 6 Mar 2025 15:11:10 +0100 Subject: [PATCH] Some refactoring Signed-off-by: Minecon724 --- pom.xml | 56 +++++++----- src/main/java/eu/m724/blog/BlogBuilder.java | 12 +-- ...ticCacheRemapper.java => CacheBuster.java} | 2 +- src/main/java/eu/m724/blog/ImageFilter.java | 88 ------------------- src/main/java/eu/m724/blog/Main.java | 1 - .../eu/m724/blog/{data => object}/Feed.java | 2 +- .../eu/m724/blog/{data => object}/Post.java | 2 +- .../blog/{data => object}/RenderOptions.java | 4 +- .../eu/m724/blog/{data => object}/Site.java | 2 +- .../m724/blog/template/TemplateExtension.java | 8 +- .../m724/blog/template/TemplateRenderer.java | 4 +- 11 files changed, 53 insertions(+), 128 deletions(-) rename src/main/java/eu/m724/blog/{StaticCacheRemapper.java => CacheBuster.java} (98%) delete mode 100644 src/main/java/eu/m724/blog/ImageFilter.java rename src/main/java/eu/m724/blog/{data => object}/Feed.java (98%) rename src/main/java/eu/m724/blog/{data => object}/Post.java (99%) rename src/main/java/eu/m724/blog/{data => object}/RenderOptions.java (94%) rename src/main/java/eu/m724/blog/{data => object}/Site.java (98%) diff --git a/pom.xml b/pom.xml index 4ff01c3..4db4052 100644 --- a/pom.xml +++ b/pom.xml @@ -19,63 +19,77 @@ + commons-cli commons-cli - 1.9.0 + 1.9.0 true + + org.eclipse.jgit org.eclipse.jgit - 7.1.0.202411261347-r + 7.1.0.202411261347-r + + io.pebbletemplates pebble - 3.2.3 + 3.2.3 + + org.snakeyaml snakeyaml-engine - 2.9 - - - commons-io - commons-io - 2.18.0 + 2.9 + - org.apache.commons - commons-compress - 1.27.1 + commons-io + commons-io + 2.18.0 + + + + org.apache.commons + commons-compress + 1.27.1 + + com.github.luben zstd-jni - 1.5.6-10 + 1.5.7-1 + org.slf4j slf4j-api - 2.0.16 + 2.0.17 + org.slf4j slf4j-simple - 2.0.16 + 2.0.17 + org.apache.maven.plugins maven-jar-plugin - 3.4.2 + 3.4.2 @@ -86,10 +100,11 @@ + org.apache.maven.plugins maven-shade-plugin - 3.6.0 + 3.6.0 package @@ -115,10 +130,11 @@ + org.apache.maven.plugins maven-jarsigner-plugin - 3.1.0 + 3.1.0 sign @@ -140,11 +156,11 @@ - + org.apache.maven.plugins maven-release-plugin - 3.1.1 + 3.1.1 diff --git a/src/main/java/eu/m724/blog/BlogBuilder.java b/src/main/java/eu/m724/blog/BlogBuilder.java index 5f6cc3a..2bb997c 100644 --- a/src/main/java/eu/m724/blog/BlogBuilder.java +++ b/src/main/java/eu/m724/blog/BlogBuilder.java @@ -1,10 +1,10 @@ package eu.m724.blog; import eu.m724.blog.compress.FileCompressor; -import eu.m724.blog.data.Feed; -import eu.m724.blog.data.Post; -import eu.m724.blog.data.RenderOptions; -import eu.m724.blog.data.Site; +import eu.m724.blog.object.Feed; +import eu.m724.blog.object.Post; +import eu.m724.blog.object.RenderOptions; +import eu.m724.blog.object.Site; import eu.m724.blog.template.TemplateRenderer; import org.apache.commons.compress.compressors.CompressorException; import org.apache.commons.io.file.PathUtils; @@ -203,7 +203,7 @@ public class BlogBuilder { var fileHashes = new HashMap(); if (renderOptions.remapAssets()) { - var assetHashes = StaticCacheRemapper.copyTree(workingDirectory.resolve("assets"), outputDirectory.resolve("assets")); + var assetHashes = CacheBuster.copyTree(workingDirectory.resolve("assets"), outputDirectory.resolve("assets")); assetHashes.forEach((k, v) -> { fileHashes.put("assets/" + k, v); // TODO this seems like a hack @@ -213,7 +213,7 @@ public class BlogBuilder { } if (renderOptions.remapTemplateStatic()) { - var templateStaticHashes = StaticCacheRemapper.copyTree(templateDirectory.resolve("static"), outputDirectory.resolve("static")); + var templateStaticHashes = CacheBuster.copyTree(templateDirectory.resolve("static"), outputDirectory.resolve("static")); templateStaticHashes.forEach((k, v) -> { fileHashes.put("static/" + k, v); // TODO this seems like a hack diff --git a/src/main/java/eu/m724/blog/StaticCacheRemapper.java b/src/main/java/eu/m724/blog/CacheBuster.java similarity index 98% rename from src/main/java/eu/m724/blog/StaticCacheRemapper.java rename to src/main/java/eu/m724/blog/CacheBuster.java index 1c6b988..1c37258 100644 --- a/src/main/java/eu/m724/blog/StaticCacheRemapper.java +++ b/src/main/java/eu/m724/blog/CacheBuster.java @@ -8,7 +8,7 @@ import java.util.Map; import java.util.stream.Collectors; import java.util.zip.CRC32C; -public class StaticCacheRemapper { +public class CacheBuster { public static Map copyTree(Path srcDir, Path destDir) throws IOException { var map = new HashMap(); diff --git a/src/main/java/eu/m724/blog/ImageFilter.java b/src/main/java/eu/m724/blog/ImageFilter.java deleted file mode 100644 index cf5dfb9..0000000 --- a/src/main/java/eu/m724/blog/ImageFilter.java +++ /dev/null @@ -1,88 +0,0 @@ -/*package eu.m724.blog; - -import io.pebbletemplates.pebble.error.PebbleException; -import io.pebbletemplates.pebble.extension.Filter; -import io.pebbletemplates.pebble.template.EvaluationContext; -import io.pebbletemplates.pebble.template.PebbleTemplate; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.awt.image.ConvolveOp; -import java.awt.image.Kernel; -import java.io.IOException; -import java.nio.Buffer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.List; -import java.util.Map; - -public class ImageFilter implements Filter { - private final Path directory; - - public ImageFilter(Path directory) { - this.directory = directory; - } - - @Override - public Object apply(Object input, Map args, PebbleTemplate self, EvaluationContext context, int lineNumber) throws PebbleException { - Path path = null; - System.out.println("filter"); - - if (input instanceof Path p) { - path = directory.resolve(p); - } else if (input instanceof String s) { - path = Path.of(directory.toString(), s); - } - - System.out.println(path); - - if (path == null || !Files.isRegularFile(path)) - return null; - - var filter = "fx-"; - var out = path.resolveSibling("f").resolve(filter + path.getFileName()); - - if (Files.isRegularFile(out)) { - return directory.relativize(out).toString(); - } - - System.out.println(path); - BufferedImage image; - try (var is = Files.newInputStream(path)) { - image = ImageIO.read(is); - } catch (IOException e) { - System.err.println("Error processing " + path + " with " + filter + ": " + e.getMessage()); - return null; - } - - var blur = ((Long) args.getOrDefault("blur", 0)).intValue(); - - if (blur > 0) { - int size = blur * 2 + 1; - float[] data = new float[size * size]; - - Arrays.fill(data, 1.0f / (size * size)); - - Kernel kernel = new Kernel(size, size, data); - ConvolveOp op = new ConvolveOp(kernel, ConvolveOp.EDGE_ZERO_FILL, null); - image = op.filter(image, null); - } - - try (var os = Files.newOutputStream(out)) { - ImageIO.write(image, "webp", os); - } catch (IOException e) { - System.err.println("Error processing " + path + " with " + filter + ": " + e.getMessage()); - return null; - } - - return directory.relativize(out).toString(); - } - - @Override - public List getArgumentNames() { - return List.of("blur"); - } -} -*/ \ No newline at end of file diff --git a/src/main/java/eu/m724/blog/Main.java b/src/main/java/eu/m724/blog/Main.java index ac3989a..7a4ee03 100644 --- a/src/main/java/eu/m724/blog/Main.java +++ b/src/main/java/eu/m724/blog/Main.java @@ -43,7 +43,6 @@ public class Main { builder.build(); var end = System.nanoTime(); - // BAD LOGGER.info("Exported to {} in {} ms", outputDirectory.toAbsolutePath(), "%.2f".formatted((end - start) / 1000000.0)); builder.startServer(openBrowser); diff --git a/src/main/java/eu/m724/blog/data/Feed.java b/src/main/java/eu/m724/blog/object/Feed.java similarity index 98% rename from src/main/java/eu/m724/blog/data/Feed.java rename to src/main/java/eu/m724/blog/object/Feed.java index 2210d88..d4c4a4d 100644 --- a/src/main/java/eu/m724/blog/data/Feed.java +++ b/src/main/java/eu/m724/blog/object/Feed.java @@ -1,4 +1,4 @@ -package eu.m724.blog.data; +package eu.m724.blog.object; import java.time.format.DateTimeFormatter; import java.util.List; diff --git a/src/main/java/eu/m724/blog/data/Post.java b/src/main/java/eu/m724/blog/object/Post.java similarity index 99% rename from src/main/java/eu/m724/blog/data/Post.java rename to src/main/java/eu/m724/blog/object/Post.java index 7c6e77e..28af3b5 100644 --- a/src/main/java/eu/m724/blog/data/Post.java +++ b/src/main/java/eu/m724/blog/object/Post.java @@ -1,4 +1,4 @@ -package eu.m724.blog.data; +package eu.m724.blog.object; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; diff --git a/src/main/java/eu/m724/blog/data/RenderOptions.java b/src/main/java/eu/m724/blog/object/RenderOptions.java similarity index 94% rename from src/main/java/eu/m724/blog/data/RenderOptions.java rename to src/main/java/eu/m724/blog/object/RenderOptions.java index cd50df4..d123bba 100644 --- a/src/main/java/eu/m724/blog/data/RenderOptions.java +++ b/src/main/java/eu/m724/blog/object/RenderOptions.java @@ -1,7 +1,5 @@ -package eu.m724.blog.data; +package eu.m724.blog.object; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.snakeyaml.engine.v2.api.Load; import org.snakeyaml.engine.v2.api.LoadSettings; diff --git a/src/main/java/eu/m724/blog/data/Site.java b/src/main/java/eu/m724/blog/object/Site.java similarity index 98% rename from src/main/java/eu/m724/blog/data/Site.java rename to src/main/java/eu/m724/blog/object/Site.java index 4f176fe..8b55841 100644 --- a/src/main/java/eu/m724/blog/data/Site.java +++ b/src/main/java/eu/m724/blog/object/Site.java @@ -1,4 +1,4 @@ -package eu.m724.blog.data; +package eu.m724.blog.object; import org.snakeyaml.engine.v2.api.Load; import org.snakeyaml.engine.v2.api.LoadSettings; diff --git a/src/main/java/eu/m724/blog/template/TemplateExtension.java b/src/main/java/eu/m724/blog/template/TemplateExtension.java index 4eb8902..472622b 100644 --- a/src/main/java/eu/m724/blog/template/TemplateExtension.java +++ b/src/main/java/eu/m724/blog/template/TemplateExtension.java @@ -1,7 +1,7 @@ package eu.m724.blog.template; -import eu.m724.blog.StaticCacheRemapper; -import eu.m724.blog.data.Site; +import eu.m724.blog.CacheBuster; +import eu.m724.blog.object.Site; import io.pebbletemplates.pebble.extension.AbstractExtension; import io.pebbletemplates.pebble.extension.Function; import io.pebbletemplates.pebble.template.EvaluationContext; @@ -34,7 +34,7 @@ public class TemplateExtension extends AbstractExtension { var hash = fileHashes.get(path); if (hash != null) { - path = StaticCacheRemapper.insertHashInPath(path, hash); + path = CacheBuster.insertHashInPath(path, hash); } return site.directory() + "/" + path; @@ -52,7 +52,7 @@ public class TemplateExtension extends AbstractExtension { var hash = fileHashes.get(path); if (hash != null) { - path = StaticCacheRemapper.insertHashInPath(path, hash); + path = CacheBuster.insertHashInPath(path, hash); } return site.directory() + "/" + path; diff --git a/src/main/java/eu/m724/blog/template/TemplateRenderer.java b/src/main/java/eu/m724/blog/template/TemplateRenderer.java index b95144a..010fd0d 100644 --- a/src/main/java/eu/m724/blog/template/TemplateRenderer.java +++ b/src/main/java/eu/m724/blog/template/TemplateRenderer.java @@ -1,7 +1,7 @@ package eu.m724.blog.template; -import eu.m724.blog.data.Post; -import eu.m724.blog.data.Site; +import eu.m724.blog.object.Post; +import eu.m724.blog.object.Site; import io.pebbletemplates.pebble.PebbleEngine; import io.pebbletemplates.pebble.loader.FileLoader; import io.pebbletemplates.pebble.template.PebbleTemplate;