Some refactoring
Some checks are pending
/ build (push) Waiting to run

Signed-off-by: Minecon724 <git@m724.eu>
This commit is contained in:
Minecon724 2025-03-06 15:11:10 +01:00
parent d03f90b7f6
commit 1354d94817
Signed by untrusted user who does not match committer: Minecon724
GPG key ID: 3CCC4D267742C8E8
11 changed files with 53 additions and 128 deletions

56
pom.xml
View file

@ -19,63 +19,77 @@
</properties> </properties>
<dependencies> <dependencies>
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
<dependency> <dependency>
<groupId>commons-cli</groupId> <groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId> <artifactId>commons-cli</artifactId>
<version>1.9.0</version> <version>1.9.0</version> <!-- Released Aug 14, 2024 -->
<optional>true</optional> <optional>true</optional>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit -->
<dependency> <dependency>
<groupId>org.eclipse.jgit</groupId> <groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId> <artifactId>org.eclipse.jgit</artifactId>
<version>7.1.0.202411261347-r</version> <version>7.1.0.202411261347-r</version> <!-- Released Dec 04, 2024 -->
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/io.pebbletemplates/pebble -->
<dependency> <dependency>
<groupId>io.pebbletemplates</groupId> <groupId>io.pebbletemplates</groupId>
<artifactId>pebble</artifactId> <artifactId>pebble</artifactId>
<version>3.2.3</version> <version>3.2.3</version> <!-- Released Feb 04, 2025 -->
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.snakeyaml/snakeyaml-engine -->
<dependency> <dependency>
<groupId>org.snakeyaml</groupId> <groupId>org.snakeyaml</groupId>
<artifactId>snakeyaml-engine</artifactId> <artifactId>snakeyaml-engine</artifactId>
<version>2.9</version> <version>2.9</version> <!-- Released Jan 15, 2025 -->
</dependency>
<dependency>
<groupId>commons-io</groupId> <!-- https://stackoverflow.com/questions/32184114 -->
<artifactId>commons-io</artifactId>
<version>2.18.0</version>
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency> <dependency>
<groupId>org.apache.commons</groupId> <groupId>commons-io</groupId>
<artifactId>commons-compress</artifactId> <artifactId>commons-io</artifactId>
<version>1.27.1</version> <version>2.18.0</version> <!-- Released Nov 19, 2024 -->
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-compress -->
<dependency>
<groupId>org.apache.commons</groupId> <!-- https://stackoverflow.com/questions/32184114 -->
<artifactId>commons-compress</artifactId>
<version>1.27.1</version> <!-- Released Aug 20, 2024 -->
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.luben/zstd-jni -->
<dependency> <dependency>
<groupId>com.github.luben</groupId> <groupId>com.github.luben</groupId>
<artifactId>zstd-jni</artifactId> <artifactId>zstd-jni</artifactId>
<version>1.5.6-10</version> <version>1.5.7-1</version> <!-- Released Feb 20, 2025 -->
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
<version>2.0.16</version> <version>2.0.17</version> <!-- Released Feb 25, 2025 -->
</dependency> </dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>slf4j-simple</artifactId>
<version>2.0.16</version> <version>2.0.17</version> <!-- Released Feb 25, 2025 -->
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId> <artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version> <version>3.4.2</version> <!-- Released Jun 19, 2024 -->
<configuration> <configuration>
<archive> <archive>
<manifest> <manifest>
@ -86,10 +100,11 @@
</configuration> </configuration>
</plugin> </plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-shade-plugin -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version> <version>3.6.0</version> <!-- Released May 31, 2024 -->
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -115,10 +130,11 @@
</executions> </executions>
</plugin> </plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jarsigner-plugin -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId> <artifactId>maven-jarsigner-plugin</artifactId>
<version>3.1.0</version> <version>3.1.0</version> <!-- Released Sep 03, 2024 -->
<executions> <executions>
<execution> <execution>
<id>sign</id> <id>sign</id>
@ -140,11 +156,11 @@
</configuration> </configuration>
</plugin> </plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-release-plugin -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId> <artifactId>maven-release-plugin</artifactId>
<version>3.1.1</version> <version>3.1.1</version> <!-- Released Jul 14, 2024 -->
</plugin> </plugin>
</plugins> </plugins>
</build> </build>

View file

@ -1,10 +1,10 @@
package eu.m724.blog; 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.object.Feed;
import eu.m724.blog.data.Post; import eu.m724.blog.object.Post;
import eu.m724.blog.data.RenderOptions; import eu.m724.blog.object.RenderOptions;
import eu.m724.blog.data.Site; import eu.m724.blog.object.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.io.file.PathUtils; import org.apache.commons.io.file.PathUtils;
@ -203,7 +203,7 @@ public class BlogBuilder {
var fileHashes = new HashMap<String, String>(); var fileHashes = new HashMap<String, String>();
if (renderOptions.remapAssets()) { 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) -> { assetHashes.forEach((k, v) -> {
fileHashes.put("assets/" + k, v); // TODO this seems like a hack fileHashes.put("assets/" + k, v); // TODO this seems like a hack
@ -213,7 +213,7 @@ public class BlogBuilder {
} }
if (renderOptions.remapTemplateStatic()) { 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) -> { templateStaticHashes.forEach((k, v) -> {
fileHashes.put("static/" + k, v); // TODO this seems like a hack fileHashes.put("static/" + k, v); // TODO this seems like a hack

View file

@ -8,7 +8,7 @@ import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.CRC32C; import java.util.zip.CRC32C;
public class StaticCacheRemapper { public class CacheBuster {
public static Map<String, String> copyTree(Path srcDir, Path destDir) throws IOException { public static Map<String, String> copyTree(Path srcDir, Path destDir) throws IOException {
var map = new HashMap<String, String>(); var map = new HashMap<String, String>();

View file

@ -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<String, Object> 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<String> getArgumentNames() {
return List.of("blur");
}
}
*/

View file

@ -43,7 +43,6 @@ public class Main {
builder.build(); builder.build();
var end = System.nanoTime(); var end = System.nanoTime();
// BAD
LOGGER.info("Exported to {} in {} ms", outputDirectory.toAbsolutePath(), "%.2f".formatted((end - start) / 1000000.0)); LOGGER.info("Exported to {} in {} ms", outputDirectory.toAbsolutePath(), "%.2f".formatted((end - start) / 1000000.0));
builder.startServer(openBrowser); builder.startServer(openBrowser);

View file

@ -1,4 +1,4 @@
package eu.m724.blog.data; package eu.m724.blog.object;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;

View file

@ -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.Git;
import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.GitAPIException;

View file

@ -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.Load;
import org.snakeyaml.engine.v2.api.LoadSettings; import org.snakeyaml.engine.v2.api.LoadSettings;

View file

@ -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.Load;
import org.snakeyaml.engine.v2.api.LoadSettings; import org.snakeyaml.engine.v2.api.LoadSettings;

View file

@ -1,7 +1,7 @@
package eu.m724.blog.template; package eu.m724.blog.template;
import eu.m724.blog.StaticCacheRemapper; import eu.m724.blog.CacheBuster;
import eu.m724.blog.data.Site; import eu.m724.blog.object.Site;
import io.pebbletemplates.pebble.extension.AbstractExtension; import io.pebbletemplates.pebble.extension.AbstractExtension;
import io.pebbletemplates.pebble.extension.Function; import io.pebbletemplates.pebble.extension.Function;
import io.pebbletemplates.pebble.template.EvaluationContext; import io.pebbletemplates.pebble.template.EvaluationContext;
@ -34,7 +34,7 @@ public class TemplateExtension extends AbstractExtension {
var hash = fileHashes.get(path); var hash = fileHashes.get(path);
if (hash != null) { if (hash != null) {
path = StaticCacheRemapper.insertHashInPath(path, hash); path = CacheBuster.insertHashInPath(path, hash);
} }
return site.directory() + "/" + path; return site.directory() + "/" + path;
@ -52,7 +52,7 @@ public class TemplateExtension extends AbstractExtension {
var hash = fileHashes.get(path); var hash = fileHashes.get(path);
if (hash != null) { if (hash != null) {
path = StaticCacheRemapper.insertHashInPath(path, hash); path = CacheBuster.insertHashInPath(path, hash);
} }
return site.directory() + "/" + path; return site.directory() + "/" + path;

View file

@ -1,7 +1,7 @@
package eu.m724.blog.template; package eu.m724.blog.template;
import eu.m724.blog.data.Post; import eu.m724.blog.object.Post;
import eu.m724.blog.data.Site; import eu.m724.blog.object.Site;
import io.pebbletemplates.pebble.PebbleEngine; import io.pebbletemplates.pebble.PebbleEngine;
import io.pebbletemplates.pebble.loader.FileLoader; import io.pebbletemplates.pebble.loader.FileLoader;
import io.pebbletemplates.pebble.template.PebbleTemplate; import io.pebbletemplates.pebble.template.PebbleTemplate;