Commit e245a8fb authored by Liang Ding's avatar Liang Ding

#19

parent f4f44d75
...@@ -1764,8 +1764,7 @@ ...@@ -1764,8 +1764,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
...@@ -1786,14 +1785,12 @@ ...@@ -1786,14 +1785,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -1808,20 +1805,17 @@ ...@@ -1808,20 +1805,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -1938,8 +1932,7 @@ ...@@ -1938,8 +1932,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -1951,7 +1944,6 @@ ...@@ -1951,7 +1944,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -1966,7 +1958,6 @@ ...@@ -1966,7 +1958,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -1974,14 +1965,12 @@ ...@@ -1974,14 +1965,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -2000,7 +1989,6 @@ ...@@ -2000,7 +1989,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -2081,8 +2069,7 @@ ...@@ -2081,8 +2069,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -2094,7 +2081,6 @@ ...@@ -2094,7 +2081,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -2180,8 +2166,7 @@ ...@@ -2180,8 +2166,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
...@@ -2217,7 +2202,6 @@ ...@@ -2217,7 +2202,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -2237,7 +2221,6 @@ ...@@ -2237,7 +2221,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
...@@ -2281,14 +2264,12 @@ ...@@ -2281,14 +2264,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.3", "version": "3.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
......
...@@ -53,7 +53,7 @@ import java.util.Map; ...@@ -53,7 +53,7 @@ import java.util.Map;
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/DASHU">DASHU</a> * @author <a href="https://hacpai.com/member/DASHU">DASHU</a>
* @author <a href="https://vanessa.b3log.org">Vanessa</a> * @author <a href="https://vanessa.b3log.org">Vanessa</a>
* @version 1.2.4.17, Jul 17, 2019 * @version 1.2.4.18, Jan 7, 2020
* @since 0.3.1 * @since 0.3.1
*/ */
@RequestProcessor @RequestProcessor
...@@ -100,7 +100,7 @@ public class IndexProcessor { ...@@ -100,7 +100,7 @@ public class IndexProcessor {
* @param context the specified context * @param context the specified context
* @throws Exception exception * @throws Exception exception
*/ */
@RequestProcessing(value = {"", "/"}, method = HttpMethod.GET) @RequestProcessing(value = {"", "/", "/index.html"}, method = HttpMethod.GET)
public void showIndex(final RequestContext context) { public void showIndex(final RequestContext context) {
final Request request = context.getRequest(); final Request request = context.getRequest();
final Response response = context.getResponse(); final Response response = context.getResponse();
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.processor;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.Before;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.solo.processor.console.ConsoleAuthAdvice;
import org.b3log.solo.util.Mocks;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
/**
* Static site processor. HTML 静态站点生成 https://github.com/88250/solo/issues/19
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jan 7, 2020
* @since 3.9.0
*/
@RequestProcessor
@Before(ConsoleAuthAdvice.class)
public class StaticSiteProcessor {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(StaticSiteProcessor.class);
/**
* Name of generate directory.
*/
private static final String STATIC_SITE = "static-site";
/**
* Generates static site.
*
* @param context the specified context
*/
@RequestProcessing(value = "/static-site")
public void genStaticSite(final RequestContext context) {
try {
Latkes.setServerScheme("https");
Latkes.setServerHost("88250.github.io");
Latkes.setServerPort("");
requestFile("/index.html");
requestFile("/blog/info");
requestFile("/manifest.json");
Latkes.setServerScheme("http");
Latkes.setServerHost("localhost");
Latkes.setServerPort("8080");
copySkin();
copyJS();
copyImages();
copyFile("sw.js");
context.renderJSON(0);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Generates static site fialed", e);
context.renderJSON(-1);
}
}
private static void requestFile(final String uri) throws Exception {
final String staticSitePath = StaticSiteProcessor.class.getResource("/" + STATIC_SITE).toURI().getPath();
FileUtils.forceMkdirParent(new File(staticSitePath + uri));
final OutputStream outputStream = new FileOutputStream(staticSitePath + uri);
String html = Mocks.mockRequest(uri);
IOUtils.write(html, outputStream, StandardCharsets.UTF_8);
outputStream.close();
}
private static void copySkin() throws Exception {
final URI skins = StaticSiteProcessor.class.getResource("/skins").toURI();
FileUtils.forceMkdir(new File(StaticSiteProcessor.class.getResource("/" + STATIC_SITE).getPath() + "/skins/"));
final URI siteSkins = StaticSiteProcessor.class.getResource("/" + STATIC_SITE + "/skins").toURI();
FileUtils.deleteDirectory(new File(siteSkins));
FileUtils.copyDirectory(new File(skins), new File(siteSkins));
}
private static void copyJS() throws Exception {
final URI js = StaticSiteProcessor.class.getResource("/js").toURI();
FileUtils.forceMkdir(new File(StaticSiteProcessor.class.getResource("/" + STATIC_SITE).getPath() + "/js/"));
final URI siteJS = StaticSiteProcessor.class.getResource("/" + STATIC_SITE + "/js").toURI();
FileUtils.deleteDirectory(new File(siteJS));
FileUtils.copyDirectory(new File(js), new File(siteJS));
}
private static void copyImages() throws Exception {
final URI images = StaticSiteProcessor.class.getResource("/images").toURI();
FileUtils.forceMkdir(new File(StaticSiteProcessor.class.getResource("/" + STATIC_SITE).getPath() + "/images/"));
final URI siteImages = StaticSiteProcessor.class.getResource("/" + STATIC_SITE + "/images").toURI();
FileUtils.deleteDirectory(new File(siteImages));
FileUtils.copyDirectory(new File(images), new File(siteImages));
}
private static void copyFile(final String file) throws Exception {
final String sourcePath = StaticSiteProcessor.class.getResource("/").toURI().getPath();
FileUtils.forceMkdirParent(new File(sourcePath + "/" + file));
final String staticSitePath = StaticSiteProcessor.class.getResource("/" + STATIC_SITE).toURI().getPath();
FileUtils.copyFile(new File(sourcePath + "/" + file), new File(staticSitePath + "/" + file));
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-present, b3log.org
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.util;
import io.netty.handler.codec.http.*;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response;
/**
* Mock utilities.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jan 7, 2020
* @since 3.9.0
*/
public final class Mocks {
private Mocks() {
}
public static String mockRequest(final String uri) {
final Mocks.MockRequest request = Mocks.mockRequest();
request.setRequestURI(uri);
final Mocks.MockResponse response = Mocks.mockResponse();
Mocks.mockDispatcher(request, response);
return response.getString();
}
private static void mockDispatcher(final Request request, final Response response) {
new MockDispatcher().handle(request, response);
}
private static MockRequest mockRequest() {
final FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/a");
return new MockRequest(req);
}
private static MockResponse mockResponse() {
final HttpResponse res = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
final MockResponse response = new MockResponse(res);
return response;
}
private static class MockDispatcher {
public void handle(final Request req, final Response resp) {
Dispatcher.handle(req, resp);
}
}
private static class MockRequest extends Request {
public MockRequest(final FullHttpRequest req) {
super(null, req);
}
@Override
public String getRemoteAddr() {
return "localhost mock";
}
}
private static class MockResponse extends Response {
public MockResponse(final HttpResponse res) {
super(null, res);
}
}
}
...@@ -48,8 +48,6 @@ ...@@ -48,8 +48,6 @@
<input id="blogTitle" type="text"/> <input id="blogTitle" type="text"/>
<label for="blogSubtitle">${blogSubtitle1Label}</label> <label for="blogSubtitle">${blogSubtitle1Label}</label>
<input id="blogSubtitle" type="text"/> <input id="blogSubtitle" type="text"/>
<label for="blogHost">${blogHost1Label}</label>
<input id="blogHost" type="text" value="${serverHost}" readonly="true"/>
<label for="metaKeywords">${metaKeywords1Label}</label> <label for="metaKeywords">${metaKeywords1Label}</label>
<input id="metaKeywords" type="text"/> <input id="metaKeywords" type="text"/>
<label for="metaDescription">${metaDescription1Label}</label> <label for="metaDescription">${metaDescription1Label}</label>
......
...@@ -262,7 +262,6 @@ pageSizeLabel=Pagination Page Size ...@@ -262,7 +262,6 @@ pageSizeLabel=Pagination Page Size
pageSize1Label=Pagination Page Size: pageSize1Label=Pagination Page Size:
blogTitle1Label=Blog Title: blogTitle1Label=Blog Title:
blogSubtitle1Label=Blog Subtitle: blogSubtitle1Label=Blog Subtitle:
blogHost1Label=<a href="https://github.com/b3log/solo/issues/12716" target="_blank">Blog Domain</a>:
submmitCommentLabel=Commit Comment submmitCommentLabel=Commit Comment
saveLabel=Save saveLabel=Save
tagLabel=Tag tagLabel=Tag
......
...@@ -262,7 +262,6 @@ pageSizeLabel=\u5206\u9875\u6BCF\u9875\u663E\u793A\u6587\u7AE0\u6570 ...@@ -262,7 +262,6 @@ pageSizeLabel=\u5206\u9875\u6BCF\u9875\u663E\u793A\u6587\u7AE0\u6570
pageSize1Label=\u5206\u9875\u6BCF\u9875\u663E\u793A\u6587\u7AE0\u6570\uFF1A pageSize1Label=\u5206\u9875\u6BCF\u9875\u663E\u793A\u6587\u7AE0\u6570\uFF1A
blogTitle1Label=\u535A\u5BA2\u6807\u9898\uFF1A blogTitle1Label=\u535A\u5BA2\u6807\u9898\uFF1A
blogSubtitle1Label=\u535A\u5BA2\u5B50\u6807\u9898\uFF1A blogSubtitle1Label=\u535A\u5BA2\u5B50\u6807\u9898\uFF1A
blogHost1Label=<a href="https://github.com/b3log/solo/issues/12716" target="_blank">\u535A\u5BA2\u57DF\u540D</a>\uFF1A
submmitCommentLabel=\u63D0\u4EA4\u8BC4\u8BBA submmitCommentLabel=\u63D0\u4EA4\u8BC4\u8BBA
saveLabel=\u4FDD\u5B58 saveLabel=\u4FDD\u5B58
tagLabel=\u6807\u7B7E tagLabel=\u6807\u7B7E
......
我的静态博客站点。
愉快地使用 [Solo](https://solo.b3log.org) 博客系统生成 ❤
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment