Commit a94aaea3 authored by Liang Ding's avatar Liang Ding

#12722

parent 61ac33fa
...@@ -52,6 +52,11 @@ public final class Option { ...@@ -52,6 +52,11 @@ public final class Option {
public static final String OPTION_CATEGORY = "optionCategory"; public static final String OPTION_CATEGORY = "optionCategory";
// oId constants // oId constants
/**
* Key of hljs theme. 在设置中可选择语法高亮主题 https://github.com/b3log/solo/issues/12722
*/
public static final String ID_C_HLJS_THEME = "hljsTheme";
/** /**
* Key of enable syn GitHub. 博文定时同步 GitHub 仓库 https://github.com/b3log/solo/issues/12676 * Key of enable syn GitHub. 博文定时同步 GitHub 仓库 https://github.com/b3log/solo/issues/12676
*/ */
...@@ -289,11 +294,16 @@ public final class Option { ...@@ -289,11 +294,16 @@ public final class Option {
* Default preference. * Default preference.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.2.0.3, Mar 19, 2019 * @version 2.3.0.0, Mar 29, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
public static final class DefaultPreference { public static final class DefaultPreference {
/**
* Default hljs theme.
*/
public static final String DEFAULT_HLJS_THEME = "atom-one-light";
/** /**
* Default enable sync GitHub. * Default enable sync GitHub.
*/ */
......
...@@ -161,6 +161,7 @@ public class AdminConsole { ...@@ -161,6 +161,7 @@ public class AdminConsole {
} }
dataModelService.fillFaviconURL(dataModel, preference); dataModelService.fillFaviconURL(dataModel, preference);
dataModelService.fillUsite(dataModel); dataModelService.fillUsite(dataModel);
dataModelService.fillCommon(context, dataModel, preference);
} catch (final Exception e) { } catch (final Exception e) {
LOGGER.log(Level.ERROR, "Admin index render failed", e); LOGGER.log(Level.ERROR, "Admin index render failed", e);
} }
......
...@@ -59,7 +59,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT; ...@@ -59,7 +59,7 @@ import static org.b3log.solo.model.Article.ARTICLE_CONTENT;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a> * @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.7.0.7, Mar 19, 2019 * @version 1.7.0.8, Mar 29, 2019
* @since 0.3.1 * @since 0.3.1
*/ */
@Service @Service
...@@ -600,6 +600,12 @@ public class DataModelService { ...@@ -600,6 +600,12 @@ public class DataModelService {
// 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614 // 使用 Marked 时代码高亮问题 https://github.com/b3log/solo/issues/12614
dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE); dataModel.put(Common.MARKED_AVAILABLE, Markdowns.MARKDOWN_HTTP_AVAILABLE);
String hljsTheme = preference.getString(Option.ID_C_HLJS_THEME);
if (StringUtils.isBlank(hljsTheme)) {
hljsTheme = Option.DefaultPreference.DEFAULT_HLJS_THEME;
}
dataModel.put(Option.ID_C_HLJS_THEME, hljsTheme);
} }
/** /**
......
...@@ -474,6 +474,12 @@ public class InitService { ...@@ -474,6 +474,12 @@ public class InitService {
private void initPreference(final JSONObject requestJSONObject) throws Exception { private void initPreference(final JSONObject requestJSONObject) throws Exception {
LOGGER.debug("Initializing preference...."); LOGGER.debug("Initializing preference....");
final JSONObject hljsThemeOpt = new JSONObject();
hljsThemeOpt.put(Keys.OBJECT_ID, Option.ID_C_HLJS_THEME);
hljsThemeOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
hljsThemeOpt.put(Option.OPTION_VALUE, DefaultPreference.DEFAULT_HLJS_THEME);
optionRepository.add(hljsThemeOpt);
final JSONObject syncGitHubOpt = new JSONObject(); final JSONObject syncGitHubOpt = new JSONObject();
syncGitHubOpt.put(Keys.OBJECT_ID, Option.ID_C_SYNC_GITHUB); syncGitHubOpt.put(Keys.OBJECT_ID, Option.ID_C_SYNC_GITHUB);
syncGitHubOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE); syncGitHubOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
......
...@@ -315,6 +315,10 @@ public class PreferenceMgmtService { ...@@ -315,6 +315,10 @@ public class PreferenceMgmtService {
syncGitHubOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SYNC_GITHUB)); syncGitHubOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_SYNC_GITHUB));
optionRepository.update(Option.ID_C_SYNC_GITHUB, syncGitHubOpt); optionRepository.update(Option.ID_C_SYNC_GITHUB, syncGitHubOpt);
final JSONObject hljsThemeOpt = optionRepository.get(Option.ID_C_HLJS_THEME);
hljsThemeOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_HLJS_THEME));
optionRepository.update(Option.ID_C_HLJS_THEME, hljsThemeOpt);
final JSONObject customVarsOpt = optionRepository.get(Option.ID_C_CUSTOM_VARS); final JSONObject customVarsOpt = optionRepository.get(Option.ID_C_CUSTOM_VARS);
customVarsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_CUSTOM_VARS)); customVarsOpt.put(Option.OPTION_VALUE, preference.optString(Option.ID_C_CUSTOM_VARS));
optionRepository.update(Option.ID_C_CUSTOM_VARS, customVarsOpt); optionRepository.update(Option.ID_C_CUSTOM_VARS, customVarsOpt);
......
...@@ -37,7 +37,7 @@ import java.sql.Statement; ...@@ -37,7 +37,7 @@ import java.sql.Statement;
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 19, 2019 * @version 1.0.0.0, Mar 19, 2019
* @since 3.3.0 * @since 3.4.0
*/ */
public final class V330_340 { public final class V330_340 {
......
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2019, b3log.org & hacpai.com
*
* 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.upgrade;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.BeanManager;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.Transaction;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.OptionRepository;
import org.json.JSONObject;
/**
* Upgrade script from v3.3.0 to v3.4.0.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Mar 29, 2019
* @since 3.5.0
*/
public final class V340_350 {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(V340_350.class);
/**
* Performs upgrade from v3.3.0 to v3.4.0.
*
* @throws Exception upgrade fails
*/
public static void perform() throws Exception {
final String fromVer = "3.4.0";
final String toVer = "3.5.0";
LOGGER.log(Level.INFO, "Upgrading from version [" + fromVer + "] to version [" + toVer + "]....");
final BeanManager beanManager = BeanManager.getInstance();
final OptionRepository optionRepository = beanManager.getReference(OptionRepository.class);
try {
final Transaction transaction = optionRepository.beginTransaction();
JSONObject hljsThemeOpt = optionRepository.get(Option.ID_C_HLJS_THEME);
if (null == hljsThemeOpt) {
hljsThemeOpt = new JSONObject();
hljsThemeOpt.put(Keys.OBJECT_ID, Option.ID_C_HLJS_THEME);
hljsThemeOpt.put(Option.OPTION_CATEGORY, Option.CATEGORY_C_PREFERENCE);
hljsThemeOpt.put(Option.OPTION_VALUE, Option.DefaultPreference.DEFAULT_HLJS_THEME);
optionRepository.add(hljsThemeOpt);
}
final JSONObject versionOpt = optionRepository.get(Option.ID_C_VERSION);
versionOpt.put(Option.OPTION_VALUE, toVer);
optionRepository.update(Option.ID_C_VERSION, versionOpt);
transaction.commit();
LOGGER.log(Level.INFO, "Upgraded from version [" + fromVer + "] to version [" + toVer + "] successfully");
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Upgrade failed!", e);
throw new Exception("Upgrade failed from version [" + fromVer + "] to version [" + toVer + "]");
}
}
}
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