Skip to content

Commit

Permalink
🎨 #19 静态站点生成
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed Jan 13, 2020
1 parent f0537aa commit 2d43e74
Showing 1 changed file with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;

Expand Down Expand Up @@ -88,10 +89,20 @@ public synchronized void genSite(final RequestContext context) {
FileUtils.deleteDirectory(new File(staticSitePath));
FileUtils.forceMkdir(new File(staticSitePath));

final URL u = new URL(url);

final String curScheme = Latkes.getServerScheme();
final String curHost = Latkes.getServerHost();
final String curPort = Latkes.getServerPort();

// 切换至静态站点生成模式
Latkes.setServerScheme("https");
Latkes.setServerHost(url);
Latkes.setServerPort("");
Latkes.setServerScheme(u.getProtocol());
Latkes.setServerHost(u.getHost());
if (-1 != u.getPort()) {
Latkes.setServerPort(String.valueOf(u.getPort()));
} else {
Latkes.setServerPort("");
}
Solos.GEN_STATIC_SITE = true;

genURI("/tags.html");
Expand All @@ -116,9 +127,9 @@ public synchronized void genSite(final RequestContext context) {
genFile("CHANGE_LOGS.md");

// 恢复之前的动态运行模式
Latkes.setServerScheme("http");
Latkes.setServerHost("localhost");
Latkes.setServerPort("8080");
Latkes.setServerScheme(curScheme);
Latkes.setServerHost(curHost);
Latkes.setServerPort(curPort);
Solos.GEN_STATIC_SITE = false;

LOGGER.log(Level.INFO, "Static site generated [dir=" + staticSitePath + "]");
Expand Down

0 comments on commit 2d43e74

Please sign in to comment.