🎨 新增自动添加缩略图的特性

pull/33/merge
ruibaby 2018-09-02 19:28:37 +08:00
parent 2bde328c35
commit aa3736c82f
17 changed files with 84 additions and 68 deletions

View File

@ -133,7 +133,12 @@ public enum BlogPropertiesEnum {
/**
*
*/
WIDGET_DAYCOUNT("widget_daycount");
WIDGET_DAYCOUNT("widget_daycount"),
/**
*
*/
DEFAULT_THUMBNAIL("/static/images/thumbnail/thumbnail.png");
private String prop;

View File

@ -4,6 +4,7 @@ import cc.ryanc.halo.model.domain.*;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.model.dto.JsonResult;
import cc.ryanc.halo.model.dto.LogsRecord;
import cc.ryanc.halo.model.enums.BlogPropertiesEnum;
import cc.ryanc.halo.model.enums.PostTypeEnum;
import cc.ryanc.halo.model.enums.ResultCodeEnum;
import cc.ryanc.halo.service.GalleryService;
@ -11,6 +12,7 @@ import cc.ryanc.halo.service.LinkService;
import cc.ryanc.halo.service.LogsService;
import cc.ryanc.halo.service.PostService;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.servlet.ServletUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
@ -232,6 +234,10 @@ public class PageController {
post.setPostDate(DateUtil.date());
post.setPostUpdate(DateUtil.date());
}
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
if (StringUtils.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
}
postService.saveByPost(post);
logsService.saveByLogs(new Logs(LogsRecord.PUSH_PAGE, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);

View File

@ -15,6 +15,7 @@ import cc.ryanc.halo.service.TagService;
import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.web.controller.core.BaseController;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.http.HtmlUtil;
import lombok.extern.slf4j.Slf4j;
@ -198,6 +199,10 @@ public class PostController extends BaseController {
post.setTags(tags);
}
post.setPostUrl(urlFilter(post.getPostUrl()));
//当没有选择文章缩略图的时候,自动分配一张内置的缩略图
if (StringUtils.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) {
post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg");
}
postService.saveByPost(post);
logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST, post.getPostTitle(), ServletUtil.getClientIP(request), DateUtil.date()));
return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), msg);

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 6.7 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -104,9 +104,9 @@
<div class="box-body">
<div>
<#if post??>
<img src="${post.postThumbnail?default("/static/images/thumbnail.png")}" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<img src="${post.postThumbnail?default("/static/images/thumbnail/thumbnail.png")}" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<#else >
<img src="/static/images/thumbnail.png" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<img src="/static/images/thumbnail/thumbnail.png" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
</#if>
</div>
</div>
@ -237,7 +237,7 @@
'postUrl' : $('#postUrl').html().toString(),
'postContentMd': editor.getMarkdown(),
'postContent': editor.getTextareaSavedHTML(),
'postThumbnail': $('#selectImg')[0].src,
'postThumbnail': $('#selectImg').attr('src'),
'allowComment' : $('#allowComment').val()
},
success: function (data) {

View File

@ -155,9 +155,9 @@
<div class="box-body">
<div>
<#if post??>
<img src="${post.postThumbnail?default("/static/images/thumbnail.png")}" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<img src="${post.postThumbnail?default("/static/images/thumbnail/thumbnail.png")}" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<#else >
<img src="/static/images/thumbnail.png" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
<img src="/static/images/thumbnail/thumbnail.png" class="img-responsive img-thumbnail" id="selectImg" onclick="openAttach('selectImg')" style="cursor: pointer;">
</#if>
</div>
</div>
@ -330,7 +330,7 @@
'postUrl' : $('#postUrl').html().toString(),
'postContentMd': editor.getMarkdown(),
'postContent': editor.getHTML(),
'postThumbnail': $('#selectImg')[0].src,
'postThumbnail': $('#selectImg').attr('src'),
'cateList' : cateList.toString(),
'tagList' : $('#tagList').tagEditor('getTags')[0].tags.toString(),
'allowComment' : $('#allowComment').val()

View File

@ -24,26 +24,26 @@
}
.native-wrap {
border: 1px solid #f0f0f0;
padding: 10px;
position: relative;
margin-left: 58px;
border: 1px solid #f0f0f0!important;
padding: 10px!important;
position: relative!important;
margin-left: 58px!important;
}
input, textarea, button {
outline: none;
outline: none!important;
}
.comment-submit,.native-list-one-img,.native-list-one-footer-time,.native-list-one-footer-reback,.native-info,.native-nav,.ua,.native-message{
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
-webkit-user-select:none!important;
-moz-user-select:none!important;
-ms-user-select:none!important;
user-select:none!important;
}
.comment-header {
width: 100%;
line-height: 1.8;
width: 100%!important;
line-height: 1.8!important;
}
.comment-input-who, .comment-input-email, .comment-input-website {
@ -69,15 +69,15 @@
}
.comment-OwO{
text-align: left;
vertical-align: middle;
padding-top: 10px;
text-align: left!important;
vertical-align: middle!important;
padding-top: 10px!important;
}
.comment-footer {
text-align: right;
vertical-align: middle;
padding-top: 10px;
text-align: right!important;
vertical-align: middle!important;
padding-top: 10px!important;
}
.comment-submit {
@ -91,7 +91,7 @@
color: #313131!important;
outline: none!important;
line-height: normal!important;
transition: all .3s ease-in-out;
transition: all .3s ease-in-out!important;
}
.comment-submit:hover{
@ -129,79 +129,79 @@
}
.native-list-one-img:hover{
transform: rotate(360deg);
transform: rotate(360deg)!important;
}
.native-list .native-list-one section {
overflow: hidden;
padding-bottom: 1rem;
border-bottom: 1px dashed #f5f5f5;
overflow: hidden!important;
padding-bottom: 1rem!important;
border-bottom: 1px dashed #f5f5f5!important;
}
.native-list .native-list-one section .native-list-one-head {
line-height: 1.5;
margin-bottom: .5rem;
margin-top: 0;
line-height: 1.5!important;
margin-bottom: .5rem!important;
margin-top: 0!important;
}
.native-list-one-head-name {
font-size: .875rem;
font-weight: 700;
cursor: pointer;
text-decoration: none;
color: #555;
font-size: .875rem!important;
font-weight: 700!important;
cursor: pointer!important;
text-decoration: none!important;
color: #555!important;
}
.native-list-one-head-admin{
padding: .1em 0.2em;
border-radius: 2px;
font-size: 70%;
font-weight: 700;
background-color: #87ceeb;
color: #fff;
display: inline;
padding: .1em 0.2em!important;
border-radius: 2px!important;
font-size: 70%!important;
font-weight: 700!important;
background-color: #87ceeb!important;
color: #fff!important;
display: inline!important;
}
.ua {
display: inline-block;
padding: .2rem .5rem;
background: #ededed;
color: #b3b1b1;
font-size: .75rem;
border-radius: .2rem;
margin-right: .3rem;
padding: .2rem .5rem!important;
background: #ededed!important;
color: #b3b1b1!important;
font-size: .75rem!important;
border-radius: .2rem!important;
margin-right: .3rem!important;
}
.native-list-one-content p {
font-size: 14px;
letter-spacing: 0;
margin: 0 0 1pc;
font-weight: 400;
font-size: 14px!important;
letter-spacing: 0!important;
margin: 0!important;
font-weight: 400!important;
}
.native-list-one-footer-time {
color: #b3b3b3;
font-size: .75rem;
margin-right: .875rem;
color: #b3b3b3!important;
font-size: .75rem!important;
margin-right: .875rem!important;
}
.native-list-one-footer-reback {
font-size: .8125rem;
color: #ef2f11;
cursor: pointer;
font-size: .8125rem!important;
color: #ef2f11!important;
cursor: pointer!important;
}
.native-info{
padding-top: 10px;
font-size: 12px;
color: #555;
padding-top: 10px!important;
font-size: 12px!important;
color: #555!important;
}
.comment-avatar{
position: relative;
float: left;
position: relative!important;
float: left!important;
}
.comment-avatar img{
border-radius: 100%;
-webkit-transition: 0.4s;
border-radius: 100%!important;
-webkit-transition: 0.4s!important;
-webkit-transition: -webkit-transform 0.4s ease-out;
transition: transform 0.4s ease-out;
-moz-transition: -moz-transform 0.4s ease-out;
@ -209,7 +209,7 @@
}
.comment-avatar img:hover{
transform: rotate(360deg);
transform: rotate(360deg)!important;
}
.native-nav{