Remove minify temporarily
All checks were successful
/ build (push) Successful in 39s

This commit is contained in:
Minecon724 2025-01-18 21:36:25 +01:00
parent 93244edd0e
commit d0952423c7
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 21 additions and 43 deletions

18
pom.xml
View file

@ -41,15 +41,23 @@
<artifactId>commons-io</artifactId>
<version>2.16.1</version>
</dependency>
<dependency>
<groupId>in.wilsonl.minifyhtml</groupId>
<artifactId>minify-html</artifactId>
<version>0.15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>eu.m724.blog.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>

View file

@ -3,8 +3,6 @@ package eu.m724.blog;
import eu.m724.blog.data.Feed;
import eu.m724.blog.data.Post;
import eu.m724.blog.data.Site;
import in.wilsonl.minifyhtml.Configuration;
import in.wilsonl.minifyhtml.MinifyHtml;
import org.apache.commons.cli.*;
import org.apache.commons.io.file.PathUtils;
import org.eclipse.jgit.api.Git;
@ -19,17 +17,11 @@ import java.util.Comparator;
import java.util.stream.Collectors;
public class Main {
// TODO put this somewhere else
private static final Configuration configuration = new Configuration.Builder()
.setMinifyCss(true)
.setMinifyJs(true)
.build();
public static void main(String[] args) throws IOException {
System.out.println("Hello world!");
var options = new Options()
.addOption("f", "force", false, "Overwrite current build. Default: no")
.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")
@ -75,7 +67,7 @@ public class Main {
}
var site = Site.fromConfig(git);
var template = new TemplateRenderer(outputDirectory, templateDirectory);
var template = new TemplateRenderer(templateDirectory);
Files.createDirectory(outputDirectory);
@ -88,7 +80,8 @@ public class Main {
try (var stream = Files.walk(postDirectory)) {
for (var path : stream.collect(Collectors.toSet())) {
if (!Files.isRegularFile(path)) continue;
if (!Files.isRegularFile(path))
continue; // directory is created below
if (!path.toString().endsWith(".html")) {
System.out.println("Post " + path.getFileName() + ": unsupported file type");
@ -153,25 +146,10 @@ public class Main {
Files.createDirectories(parent);
}
var type = Files.probeContentType(src);
String content = null;
if (type.equals("text/html")) {
content = MinifyHtml.minify(Files.readString(src), configuration);
} else if (type.equals("text/css")) {
content = MinifyHtml.minify(Files.readString(src), configuration);
} else if (type.equals("text/javascript")) {
content = MinifyHtml.minify(Files.readString(src), configuration);
}
if (content != null) {
Files.writeString(dest, content);
} else {
Files.copy(src, dest);
}
}
}
}
return true;
}

View file

@ -2,8 +2,6 @@ package eu.m724.blog;
import eu.m724.blog.data.Post;
import eu.m724.blog.data.Site;
import in.wilsonl.minifyhtml.Configuration;
import in.wilsonl.minifyhtml.MinifyHtml;
import io.pebbletemplates.pebble.PebbleEngine;
import io.pebbletemplates.pebble.extension.AbstractExtension;
import io.pebbletemplates.pebble.extension.Function;
@ -19,15 +17,9 @@ import java.util.List;
import java.util.Map;
public class TemplateRenderer {
private final Configuration configuration;
private final PebbleTemplate indexTemplate, articleTemplate;
public TemplateRenderer(Path outputDirectory, Path templateDirectory) {
this.configuration = new Configuration.Builder()
.setMinifyCss(true)
.setMinifyJs(true)
.build();
public TemplateRenderer(Path templateDirectory) {
var loader = new FileLoader();
loader.setPrefix(templateDirectory.toString());
loader.setSuffix(".html");
@ -78,7 +70,7 @@ public class TemplateRenderer {
var writer = new StringWriter();
indexTemplate.evaluate(writer, context);
return MinifyHtml.minify(writer.toString(), configuration);
return writer.toString();
}
public String renderPost(Site site, Post post) throws IOException {
@ -90,6 +82,6 @@ public class TemplateRenderer {
var writer = new StringWriter();
articleTemplate.evaluate(writer, context);
return MinifyHtml.minify(writer.toString(), configuration);
return writer.toString();
}
}