🎨 代码优化

pull/33/merge
ruibaby 2018-08-23 15:46:27 +08:00
parent 64a5eb792e
commit dff55aca9e
14 changed files with 29 additions and 55 deletions

View File

@ -82,7 +82,7 @@ public class StartupConfig implements ApplicationListener<ApplicationStartedEven
* OwO * OwO
*/ */
private void loadOwo() { private void loadOwo() {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>(135);
map.put("@[nico]", "<img src='/static/plugins/OwO/paopao/nico.png' alt='nico.png' style='vertical-align: middle;'>"); map.put("@[nico]", "<img src='/static/plugins/OwO/paopao/nico.png' alt='nico.png' style='vertical-align: middle;'>");
map.put("@[OK]", "<img src='/static/plugins/OwO/paopao/OK.png' alt='OK.png' style='vertical-align: middle;'>"); map.put("@[OK]", "<img src='/static/plugins/OwO/paopao/OK.png' alt='OK.png' style='vertical-align: middle;'>");
map.put("@[what]", "<img src='/static/plugins/OwO/paopao/what.png' alt='what.png' style='vertical-align: middle;'>"); map.put("@[what]", "<img src='/static/plugins/OwO/paopao/what.png' alt='what.png' style='vertical-align: middle;'>");

View File

@ -84,7 +84,7 @@ public class OptionsServiceImpl implements OptionsService {
*/ */
@Override @Override
public Map<String, String> findAllOptions() { public Map<String, String> findAllOptions() {
Map<String, String> options = new HashMap<String, String>(); Map<String, String> options = new HashMap<>();
List<Options> optionsList = optionsRepository.findAll(); List<Options> optionsList = optionsRepository.findAll();
if (null != optionsList) { if (null != optionsList) {
optionsList.forEach(option -> options.put(option.getOptionName(), option.getOptionValue())); optionsList.forEach(option -> options.put(option.getOptionName(), option.getOptionValue()));

View File

@ -46,36 +46,6 @@ import java.util.*;
@Slf4j @Slf4j
public class HaloUtils { public class HaloUtils {
private static ArrayList<String> FILE_LIST = new ArrayList<>();
/**
*
*
* @param filePath filePath
* @return ArrayList
*/
public static ArrayList<String> getFiles(String filePath) {
try {
//获取项目根路径
File basePath = new File(ResourceUtils.getURL("classpath:").getPath());
//获取目标路径
File targetPath = new File(basePath.getAbsolutePath(), filePath);
File[] files = targetPath.listFiles();
//遍历文件
for (File file : files) {
if (file.isDirectory()) {
getFiles(filePath + "/" + file.getName());
} else {
String abPath = file.getAbsolutePath().substring(file.getAbsolutePath().indexOf("/upload"));
FILE_LIST.add(abPath);
}
}
} catch (Exception e) {
log.error("未知错误:{0}", e.getMessage());
}
return FILE_LIST;
}
/** /**
* *
* *
@ -205,7 +175,7 @@ public class HaloUtils {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("主题获取失败:", e.getMessage()); log.error("主题获取失败:{}", e.getMessage());
} }
return themes; return themes;
} }
@ -241,7 +211,7 @@ public class HaloUtils {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("未知错误:", e.getMessage()); log.error("获取主题模板失败:{}", e.getMessage());
} }
return tpls; return tpls;
} }

View File

@ -130,7 +130,7 @@ public class AttachmentController {
* @return Map * @return Map
*/ */
private Map<String, Object> uploadAttachment(MultipartFile file, HttpServletRequest request) { private Map<String, Object> uploadAttachment(MultipartFile file, HttpServletRequest request) {
Map<String, Object> result = new HashMap<String, Object>(); Map<String, Object> result = new HashMap<>(3);
if (!file.isEmpty()) { if (!file.isEmpty()) {
try { try {
//程序根路径,也就是/resources //程序根路径,也就是/resources

View File

@ -226,7 +226,7 @@ public class BackupController {
@Override @Override
public void run() { public void run() {
File file = new File(srcPath); File file = new File(srcPath);
Map<String, Object> content = new HashMap<>(); Map<String, Object> content = new HashMap<>(3);
try { try {
content.put("fileName", file.getName()); content.put("fileName", file.getName());
content.put("createAt", HaloUtils.getCreateTime(srcPath)); content.put("createAt", HaloUtils.getCreateTime(srcPath));

View File

@ -221,7 +221,7 @@ public class CommentController extends BaseController {
public void run() { public void run() {
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) { if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(8);
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("commentAuthor", lastComment.getCommentAuthor());
map.put("pageName", lastComment.getPost().getPostTitle()); map.put("pageName", lastComment.getPost().getPostTitle());
@ -263,7 +263,7 @@ public class CommentController extends BaseController {
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
try { try {
if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) { if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(6);
if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId());
} else { } else {

View File

@ -265,8 +265,7 @@ public class PageController {
@ResponseBody @ResponseBody
public JsonResult checkUrlExists(@PathParam("postUrl") String postUrl) { public JsonResult checkUrlExists(@PathParam("postUrl") String postUrl) {
Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc()); Post post = postService.findByPostUrl(postUrl, PostTypeEnum.POST_TYPE_PAGE.getDesc());
// TODO 还没写完 if (null != post) {
if (null != post || StringUtils.equals("archives", postUrl) || StringUtils.equals("galleries", postUrl)) {
return new JsonResult(ResultCodeEnum.FAIL.getCode(), "该路径已经存在!"); return new JsonResult(ResultCodeEnum.FAIL.getCode(), "该路径已经存在!");
} }
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), ""); return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "");

View File

@ -165,7 +165,7 @@ public class FrontCommentController {
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
try { try {
//发送邮件到博主 //发送邮件到博主
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(5);
map.put("author", userService.findUser().getUserDisplayName()); map.put("author", userService.findUser().getUserDisplayName());
map.put("pageName", post.getPostTitle()); map.put("pageName", post.getPostTitle());
if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) {
@ -202,7 +202,7 @@ public class FrontCommentController {
//发送通知给对方 //发送通知给对方
if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) {
if (Validator.isEmail(lastComment.getCommentAuthorEmail())) { if (Validator.isEmail(lastComment.getCommentAuthorEmail())) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>(8);
map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()));
map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("commentAuthor", lastComment.getCommentAuthor());
map.put("pageName", lastComment.getPost().getPostTitle()); map.put("pageName", lastComment.getPost().getPostTitle());

View File

@ -1,4 +1,4 @@
<!-- changyan comment --> <#-- changyan comment -->
<!--PC和WAP自适应版--> <!--PC和WAP自适应版-->
<style type="text/css" rel="stylesheet"> <style type="text/css" rel="stylesheet">
${options.changyan_css?if_exists} ${options.changyan_css?if_exists}
@ -11,4 +11,4 @@
var width = window.innerWidth || document.documentElement.clientWidth; var width = window.innerWidth || document.documentElement.clientWidth;
if (width < 960) { if (width < 960) {
window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })(); window.document.write('<script id="changyan_mobile_js" charset="utf-8" type="text/javascript" src="https://changyan.sohu.com/upload/mobile/wap-js/changyan_mobile.js?client_id=' + appid + '&conf=' + conf + '"><\/script>'); } else { var loadJs=function(d,a){var c=document.getElementsByTagName("head")[0]||document.head||document.documentElement;var b=document.createElement("script");b.setAttribute("type","text/javascript");b.setAttribute("charset","UTF-8");b.setAttribute("src",d);if(typeof a==="function"){if(window.attachEvent){b.onreadystatechange=function(){var e=b.readyState;if(e==="loaded"||e==="complete"){b.onreadystatechange=null;a()}}}else{b.onload=a}}c.appendChild(b)};loadJs("https://changyan.sohu.com/upload/changyan.js",function(){window.changyan.api.config({appid:appid,conf:conf})}); } })();
</script> </script>

View File

@ -1,4 +1,4 @@
<!--disqus comment--> <#--disqus comment-->
<style type="text/css" rel="stylesheet"> <style type="text/css" rel="stylesheet">
${options.disqus_css?if_exists} ${options.disqus_css?if_exists}
</style> </style>
@ -22,4 +22,4 @@
(d.head || d.body).appendChild(s); (d.head || d.body).appendChild(s);
})(); })();
</script> </script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>

View File

@ -1,4 +1,4 @@
<!-- livere_comment --> <#-- livere_comment -->
<style type="text/css" rel="stylesheet"> <style type="text/css" rel="stylesheet">
${options.livere_css?if_exists} ${options.livere_css?if_exists}
</style> </style>
@ -16,4 +16,4 @@
</script> </script>
<noscript> 为正常使用来必力评论功能请激活JavaScript</noscript> <noscript> 为正常使用来必力评论功能请激活JavaScript</noscript>
</div> </div>
</div> </div>

View File

@ -1,4 +1,4 @@
<!-- Valine comment --> <#-- Valine comment -->
<style type="text/css" rel="stylesheet"> <style type="text/css" rel="stylesheet">
${options.valine_css?if_exists} ${options.valine_css?if_exists}
</style> </style>
@ -23,4 +23,4 @@
avatar:'${options.valine_avatar?if_exists}', avatar:'${options.valine_avatar?if_exists}',
lang:'zh-cn' lang:'zh-cn'
}); });
</script> </script>

View File

@ -1,14 +1,14 @@
<!-- 统计代码 --> <#-- 统计代码 -->
<#macro statistics> <#macro statistics>
${options.statistics_code?if_exists} ${options.statistics_code?if_exists}
</#macro> </#macro>
<!-- 页脚信息 --> <#-- 页脚信息 -->
<#macro footer_info> <#macro footer_info>
${options.blog_footer_info?if_exists} ${options.blog_footer_info?if_exists}
</#macro> </#macro>
<!-- favicon --> <#-- favicon -->
<#macro favicon> <#macro favicon>
<#if options.blog_favicon??> <#if options.blog_favicon??>
<link rel="shortcut icon" type="images/x-icon" href="${options.blog_favicon}"> <link rel="shortcut icon" type="images/x-icon" href="${options.blog_favicon}">

View File

@ -14,7 +14,12 @@
<@commonTag method="links"> <@commonTag method="links">
<#if links?? && links?size gt 0> <#if links?? && links?size gt 0>
<#list links as link> <#list links as link>
<p><a href="${link.linkUrl}" target="_blank" rel="external">${link.linkName}</a> ${link.linkDesc}</p> <p>
<a href="${link.linkUrl}" target="_blank" rel="external">${link.linkName}</a>
<#if link.linkDesc!=''>
${link.linkDesc}
</#if>
</p>
</#list> </#list>
</#if> </#if>
</@commonTag> </@commonTag>
@ -24,4 +29,4 @@
</div> </div>
</div> </div>
</div> </div>
<@footer></@footer> <@footer></@footer>