Commit ff58a432 authored by Liang Ding's avatar Liang Ding

Fix #12901

parent fe6e4cc2
...@@ -17,10 +17,13 @@ ...@@ -17,10 +17,13 @@
*/ */
package org.b3log.solo.processor; package org.b3log.solo.processor;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.Latkes; import org.b3log.latke.Latkes;
import org.b3log.latke.ioc.Inject; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.model.Pagination; import org.b3log.latke.model.Pagination;
import org.b3log.latke.model.User; import org.b3log.latke.model.User;
import org.b3log.latke.servlet.HttpMethod; import org.b3log.latke.servlet.HttpMethod;
...@@ -35,16 +38,23 @@ import org.b3log.solo.service.*; ...@@ -35,16 +38,23 @@ import org.b3log.solo.service.*;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.InputStream;
/** /**
* Blog processor. * Blog processor.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.3.1.8, Feb 7, 2019 * @version 1.4.0.0, Oct 2, 2019
* @since 0.4.6 * @since 0.4.6
*/ */
@RequestProcessor @RequestProcessor
public class BlogProcessor { public class BlogProcessor {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(BlogProcessor.class);
/** /**
* Article query service. * Article query service.
*/ */
...@@ -75,6 +85,44 @@ public class BlogProcessor { ...@@ -75,6 +85,44 @@ public class BlogProcessor {
@Inject @Inject
private OptionQueryService optionQueryService; private OptionQueryService optionQueryService;
/**
* PWA manifest JSON template.
*/
private static String PWA_MANIFESTO_JSON;
static {
try (final InputStream tplStream = BlogProcessor.class.getResourceAsStream("/manifest.json.tpl")) {
PWA_MANIFESTO_JSON = IOUtils.toString(tplStream, "UTF-8");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Loads PWA manifest.json template failed", e);
}
}
/**
* Gets PWA manifest.json.
*
* @param context the specified context
*/
@RequestProcessing(value = "/manifest.json", method = HttpMethod.GET)
public void getPWAManifestJSON(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
renderer.setPretty(true);
context.setRenderer(renderer);
final JSONObject preference = optionQueryService.getPreference();
if (null == preference) {
return;
}
final String name = preference.optString(Option.ID_C_BLOG_TITLE);
PWA_MANIFESTO_JSON = StringUtils.replace(PWA_MANIFESTO_JSON, "${name}", name);
final String description = preference.optString(Option.ID_C_BLOG_SUBTITLE);
PWA_MANIFESTO_JSON = StringUtils.replace(PWA_MANIFESTO_JSON, "${description}", description);
final JSONObject jsonObject = new JSONObject(PWA_MANIFESTO_JSON);
final JSONObject admin = userQueryService.getAdmin();
final String adminName = admin.optString(User.USER_NAME);
PWA_MANIFESTO_JSON = StringUtils.replace(PWA_MANIFESTO_JSON, "${shortName}", adminName);
renderer.setJSONObject(jsonObject);
}
/** /**
* Gets blog information. * Gets blog information.
* <ul> * <ul>
...@@ -111,12 +159,7 @@ public class BlogProcessor { ...@@ -111,12 +159,7 @@ public class BlogProcessor {
jsonObject.put("runtimeMode", Latkes.getRuntimeMode()); jsonObject.put("runtimeMode", Latkes.getRuntimeMode());
jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase()); jsonObject.put("runtimeDatabase", Latkes.getRuntimeDatabase());
jsonObject.put("locale", Latkes.getLocale()); jsonObject.put("locale", Latkes.getLocale());
String userName = ""; final String userName = userQueryService.getAdmin().optString(User.USER_NAME);
try {
userName = userQueryService.getAdmin().optString(User.USER_NAME);
} catch (final Exception e) {
// ignored
}
jsonObject.put("userName", userName); jsonObject.put("userName", userName);
} }
......
{ {
"name": "Solo - 博客", "name": "${name}",
"short_name": "Solo", "short_name": "${shortName}",
"start_url": ".", "start_url": ".",
"display": "standalone", "display": "standalone",
"background_color": "#f1f2f7", "background_color": "#f1f2f7",
"orientation": "portrait", "orientation": "portrait",
"theme_color": "#1fb5ad", "theme_color": "#1fb5ad",
"description": "一个用 Java 实现的博客系统,为你或你的团队创建个博客吧!", "description": "${description}",
"icons": [ "icons": [
{ {
"src": "images/logo/logo@48.png", "src": "images/logo/logo@48.png",
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
--> -->
<!-- <!--
Description: Static resources definition. Description: Static resources definition.
Version: 2.8.0.61, Mar 17, 2019 Version: 2.8.0.62, Oct 2, 2019
Author: Liang Ding Author: Liang Ding
Author: Liyuan Li Author: Liyuan Li
--> -->
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
<include path="/robots.txt"/> <include path="/robots.txt"/>
<include path="/sw.js"/> <include path="/sw.js"/>
<include path="/manifest.json"/>
<include path="/js/**.js"/> <include path="/js/**.js"/>
<include path="/js/**/*.js"/> <include path="/js/**/*.js"/>
......
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