This commit is contained in:
parent
93244edd0e
commit
d0952423c7
3 changed files with 21 additions and 43 deletions
18
pom.xml
18
pom.xml
|
@ -41,15 +41,23 @@
|
||||||
<artifactId>commons-io</artifactId>
|
<artifactId>commons-io</artifactId>
|
||||||
<version>2.16.1</version>
|
<version>2.16.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>in.wilsonl.minifyhtml</groupId>
|
|
||||||
<artifactId>minify-html</artifactId>
|
|
||||||
<version>0.15.0</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<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>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
|
|
@ -3,8 +3,6 @@ package eu.m724.blog;
|
||||||
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.Site;
|
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.cli.*;
|
||||||
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;
|
||||||
|
@ -19,17 +17,11 @@ import java.util.Comparator;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Main {
|
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 {
|
public static void main(String[] args) throws IOException {
|
||||||
System.out.println("Hello world!");
|
System.out.println("Hello world!");
|
||||||
|
|
||||||
var options = new Options()
|
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("dir", "working-dir", true, "Working directory. Default: current directory")
|
||||||
.addOption("t", "template-dir", true, "Template directory. Default: working directory/template")
|
.addOption("t", "template-dir", true, "Template directory. Default: working directory/template")
|
||||||
.addOption("o", "output-dir", true, "Output directory. Default: working directory/generated_out")
|
.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 site = Site.fromConfig(git);
|
||||||
var template = new TemplateRenderer(outputDirectory, templateDirectory);
|
var template = new TemplateRenderer(templateDirectory);
|
||||||
|
|
||||||
Files.createDirectory(outputDirectory);
|
Files.createDirectory(outputDirectory);
|
||||||
|
|
||||||
|
@ -88,7 +80,8 @@ public class Main {
|
||||||
|
|
||||||
try (var stream = Files.walk(postDirectory)) {
|
try (var stream = Files.walk(postDirectory)) {
|
||||||
for (var path : stream.collect(Collectors.toSet())) {
|
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")) {
|
if (!path.toString().endsWith(".html")) {
|
||||||
System.out.println("Post " + path.getFileName() + ": unsupported file type");
|
System.out.println("Post " + path.getFileName() + ": unsupported file type");
|
||||||
|
@ -153,22 +146,7 @@ public class Main {
|
||||||
Files.createDirectories(parent);
|
Files.createDirectories(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
var type = Files.probeContentType(src);
|
Files.copy(src, dest);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,6 @@ package eu.m724.blog;
|
||||||
|
|
||||||
import eu.m724.blog.data.Post;
|
import eu.m724.blog.data.Post;
|
||||||
import eu.m724.blog.data.Site;
|
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.PebbleEngine;
|
||||||
import io.pebbletemplates.pebble.extension.AbstractExtension;
|
import io.pebbletemplates.pebble.extension.AbstractExtension;
|
||||||
import io.pebbletemplates.pebble.extension.Function;
|
import io.pebbletemplates.pebble.extension.Function;
|
||||||
|
@ -19,15 +17,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class TemplateRenderer {
|
public class TemplateRenderer {
|
||||||
private final Configuration configuration;
|
|
||||||
private final PebbleTemplate indexTemplate, articleTemplate;
|
private final PebbleTemplate indexTemplate, articleTemplate;
|
||||||
|
|
||||||
public TemplateRenderer(Path outputDirectory, Path templateDirectory) {
|
public TemplateRenderer(Path templateDirectory) {
|
||||||
this.configuration = new Configuration.Builder()
|
|
||||||
.setMinifyCss(true)
|
|
||||||
.setMinifyJs(true)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
var loader = new FileLoader();
|
var loader = new FileLoader();
|
||||||
loader.setPrefix(templateDirectory.toString());
|
loader.setPrefix(templateDirectory.toString());
|
||||||
loader.setSuffix(".html");
|
loader.setSuffix(".html");
|
||||||
|
@ -78,7 +70,7 @@ public class TemplateRenderer {
|
||||||
var writer = new StringWriter();
|
var writer = new StringWriter();
|
||||||
indexTemplate.evaluate(writer, context);
|
indexTemplate.evaluate(writer, context);
|
||||||
|
|
||||||
return MinifyHtml.minify(writer.toString(), configuration);
|
return writer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String renderPost(Site site, Post post) throws IOException {
|
public String renderPost(Site site, Post post) throws IOException {
|
||||||
|
@ -90,6 +82,6 @@ public class TemplateRenderer {
|
||||||
var writer = new StringWriter();
|
var writer = new StringWriter();
|
||||||
articleTemplate.evaluate(writer, context);
|
articleTemplate.evaluate(writer, context);
|
||||||
|
|
||||||
return MinifyHtml.minify(writer.toString(), configuration);
|
return writer.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue