Update anatole theme.

pull/146/head
ruibaby 2019-04-23 14:46:22 +08:00
parent 77196780ee
commit 81ba6e3c5f
7 changed files with 60 additions and 31 deletions

View File

@ -9,6 +9,8 @@ import run.halo.app.model.freemarker.method.RecentCommentsMethod;
import run.halo.app.model.freemarker.method.RecentPostsMethod; import run.halo.app.model.freemarker.method.RecentPostsMethod;
import run.halo.app.model.freemarker.tag.*; import run.halo.app.model.freemarker.tag.*;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService;
import run.halo.app.service.ThemeSettingService;
import run.halo.app.service.UserService; import run.halo.app.service.UserService;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
@ -32,6 +34,12 @@ public class FreeMarkerAutoConfiguration {
@Autowired @Autowired
private UserService userService; private UserService userService;
@Autowired
private ThemeService themeService;
@Autowired
private ThemeSettingService themeSettingService;
@Autowired @Autowired
private PostTagDirective postTagDirective; private PostTagDirective postTagDirective;
@ -67,6 +75,7 @@ public class FreeMarkerAutoConfiguration {
try { try {
configuration.setSharedVariable("options", optionsService.listOptions()); configuration.setSharedVariable("options", optionsService.listOptions());
configuration.setSharedVariable("user", userService.getCurrentUser().orElse(null)); configuration.setSharedVariable("user", userService.getCurrentUser().orElse(null));
configuration.setSharedVariable("settings", themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
//Freemarker custom tags //Freemarker custom tags
configuration.setSharedVariable("categoryTag", categoryTagDirective); configuration.setSharedVariable("categoryTag", categoryTagDirective);
configuration.setSharedVariable("commentTag", commentTagDirective); configuration.setSharedVariable("commentTag", commentTagDirective);

View File

@ -10,6 +10,7 @@ import org.springframework.stereotype.Component;
import run.halo.app.handler.theme.config.support.ThemeProperty; import run.halo.app.handler.theme.config.support.ThemeProperty;
import run.halo.app.service.OptionService; import run.halo.app.service.OptionService;
import run.halo.app.service.ThemeService; import run.halo.app.service.ThemeService;
import run.halo.app.service.ThemeSettingService;
import java.util.Map; import java.util.Map;
@ -29,12 +30,16 @@ public class FreemarkerConfigAwareListener {
private final ThemeService themeService; private final ThemeService themeService;
private final ThemeSettingService themeSettingService;
public FreemarkerConfigAwareListener(OptionService optionService, public FreemarkerConfigAwareListener(OptionService optionService,
Configuration configuration, Configuration configuration,
ThemeService themeService) { ThemeService themeService,
ThemeSettingService themeSettingService) {
this.optionService = optionService; this.optionService = optionService;
this.configuration = configuration; this.configuration = configuration;
this.themeService = themeService; this.themeService = themeService;
this.themeSettingService = themeSettingService;
} }
@Async @Async
@ -59,6 +64,8 @@ public class FreemarkerConfigAwareListener {
Map<String, String> options = optionService.listOptions(); Map<String, String> options = optionService.listOptions();
log.debug("Set shared variable options: [{}]", options); log.debug("Set shared variable options: [{}]", options);
configuration.setSharedVariable("options", options); configuration.setSharedVariable("options", options);
log.debug("Set shared variable theme settings: [{}]", options);
configuration.setSharedVariable("setting",themeSettingService.listAsMapBy(themeService.getActivatedThemeId()));
} catch (TemplateModelException e) { } catch (TemplateModelException e) {
log.warn("Failed to configure freemarker", e); log.warn("Failed to configure freemarker", e);
} }

View File

@ -1,11 +1,14 @@
package run.halo.app.service.impl; package run.halo.app.service.impl;
import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import run.halo.app.exception.ServiceException;
import run.halo.app.handler.theme.config.support.Group; import run.halo.app.handler.theme.config.support.Group;
import run.halo.app.handler.theme.config.support.Item; import run.halo.app.handler.theme.config.support.Item;
import run.halo.app.model.entity.ThemeSetting; import run.halo.app.model.entity.ThemeSetting;
@ -31,11 +34,15 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
private final ThemeService themeService; private final ThemeService themeService;
private final Configuration configuration;
public ThemeSettingServiceImpl(ThemeSettingRepository themeSettingRepository, public ThemeSettingServiceImpl(ThemeSettingRepository themeSettingRepository,
ThemeService themeService) { ThemeService themeService,
Configuration configuration) {
super(themeSettingRepository); super(themeSettingRepository);
this.themeSettingRepository = themeSettingRepository; this.themeSettingRepository = themeSettingRepository;
this.themeService = themeService; this.themeService = themeService;
this.configuration = configuration;
} }
@Override @Override
@ -94,6 +101,12 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
// Save the settings // Save the settings
settings.forEach((key, value) -> save(key, value.toString(), themeId)); settings.forEach((key, value) -> save(key, value.toString(), themeId));
try {
configuration.setSharedVariable("settings", listAsMapBy(themeService.getActivatedThemeId()));
} catch (TemplateModelException e) {
throw new ServiceException("Save theme settings error", e);
}
} }
@Override @Override

View File

@ -21,12 +21,12 @@
<link href="/anatole/source/css/style.min.css" type="text/css" rel="stylesheet" /> <link href="/anatole/source/css/style.min.css" type="text/css" rel="stylesheet" />
<link rel="alternate" type="application/rss+xml" title="atom 1.0" href="/feed.xml"> <link rel="alternate" type="application/rss+xml" title="atom 1.0" href="/feed.xml">
<style> <style>
<#if (options.anatole_style_post_title_lower!'true') == "false"> <#if !(settings.post_title_uppper!true)>
.post .post-title h3 { .post .post-title h3 {
text-transform: none; text-transform: none;
} }
</#if> </#if>
<#if (options.anatole_style_blog_title_lower!'true') == "false"> <#if !(settings.blog_title_uppper!true)>
.sidebar .logo-title .title h3 { .sidebar .logo-title .title h3 {
text-transform: none; text-transform: none;
} }
@ -37,12 +37,12 @@
background-color: #eee; background-color: #eee;
} }
::-webkit-scrollbar-thumb { ::-webkit-scrollbar-thumb {
background-color: ${options.anatole_style_scrollbar!'#3798e8'}; background-color: ${settings.scrollbar!'#3798e8'};
} }
::-webkit-scrollbar-track { ::-webkit-scrollbar-track {
background-color: #eee; background-color: #eee;
} }
${options.anatole_style_self!} ${settings.custom!}
</style> </style>
</head> </head>
<body> <body>

View File

@ -15,7 +15,7 @@
</li> </li>
</div> </div>
<div class="avatar"> <div class="avatar">
<img src="${options.anatole_style_right_icon!'/anatole/source/images/logo.png'}" /> <img src="${settings.icon!'/anatole/source/images/logo.png'}" />
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,12 +1,12 @@
<div class="sidebar animated fadeInDown"> <div class="sidebar animated fadeInDown">
<div class="logo-title"> <div class="logo-title">
<div class="title"> <div class="title">
<img src="${options.blog_logo!'/anatole/source/images/logo@2x.png'}" style="width:127px;<#if (options.anatole_style_avatar_circle!'false')=='true'>border-radius:50%</#if>" /> <img src="${options.blog_logo!'/anatole/source/images/logo@2x.png'}" style="width:127px;<#if settings.avatar_circle!false>border-radius:50%</#if>" />
<h3 title=""> <h3 title="">
<a href="${options.blog_url!}">${options.blog_title!'ANATOLE'}</a> <a href="${options.blog_url!}">${options.blog_title!'Anatole'}</a>
</h3> </h3>
<div class="description"> <div class="description">
<#if (options.anatole_style_hitokoto!'false')=="true"> <#if settings.hitokoto!false>
<p id="yiyan">获取中...</p> <p id="yiyan">获取中...</p>
<#else > <#else >
<p>${user.description!'A other Halo theme'}</p> <p>${user.description!'A other Halo theme'}</p>

View File

@ -1,6 +1,6 @@
<ul class="social-links"> <ul class="social-links">
<#if (options.theme_anatole_sns_rss!'true')=='true'> <#if settings.rss!true>
<li> <li>
<a target="_blank" href="${options.blog_url!}/atom.xml"> <a target="_blank" href="${options.blog_url!}/atom.xml">
<i class="fa fa-rss"></i> <i class="fa fa-rss"></i>
@ -8,73 +8,73 @@
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_twitter??> <#if settings.twitter??>
<li> <li>
<a target="_blank" href="https://twitter.com/${options.theme_anatole_sns_twitter}"> <a target="_blank" href="https://twitter.com/${settings.twitter}">
<i class="fa fa-twitter"></i> <i class="fa fa-twitter"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_facebook??> <#if settings.facebook??>
<li> <li>
<a target="_blank" href="https://www.facebook.com/${options.theme_anatole_sns_facebook}"> <a target="_blank" href="https://www.facebook.com/${settings.facebook}">
<i class="fa fa-facebook"></i> <i class="fa fa-facebook"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_instagram??> <#if settings.instagram??>
<li> <li>
<a target="_blank" href="https://www.instagram.com/${options.theme_anatole_sns_instagram}"> <a target="_blank" href="https://www.instagram.com/${settings.instagram}">
<i class="fa fa-instagram"></i> <i class="fa fa-instagram"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_dribbble??> <#if settings.dribbble??>
<li> <li>
<a target="_blank" href="https://dribbble.com/${options.theme_anatole_sns_dribbble}"> <a target="_blank" href="https://dribbble.com/${settings.dribbble}">
<i class="fa fa-dribbble"></i> <i class="fa fa-dribbble"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_weibo??> <#if settings.weibo??>
<li> <li>
<a target="_blank" href="https://weibo.com/${options.theme_anatole_sns_weibo}"> <a target="_blank" href="https://weibo.com/${settings.weibo}">
<i class="fa fa-weibo"></i> <i class="fa fa-weibo"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_qq??> <#if settings.qq??>
<li> <li>
<a target="_blank" href="tencent://message/?uin=${options.theme_anatole_sns_qq}&Site=&Menu=yes"> <a target="_blank" href="tencent://message/?uin=${settings.qq}&Site=&Menu=yes">
<i class="fa fa-qq"></i> <i class="fa fa-qq"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_telegram??> <#if settings.telegram??>
<li> <li>
<a target="_blank" href="https://t.me/${options.theme_anatole_sns_telegram}"> <a target="_blank" href="https://t.me/${settings.telegram}">
<i class="fa fa-telegram"></i> <i class="fa fa-telegram"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_email??> <#if settings.email??>
<li> <li>
<a target="_blank" href="mailto:${options.theme_anatole_sns_email}"> <a target="_blank" href="mailto:${settings.email}">
<i class="fa fa-envelope"></i> <i class="fa fa-envelope"></i>
</a> </a>
</li> </li>
</#if> </#if>
<#if options.theme_anatole_sns_github??> <#if settings.github??>
<li> <li>
<a target="_blank" href="https://github.com/${options.theme_anatole_sns_github}"> <a target="_blank" href="https://github.com/${settings.github}">
<i class="fa fa-github"></i> <i class="fa fa-github"></i>
</a> </a>
</li> </li>