Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
IEQEFCR
halo
提交
6f6ed51e
H
halo
项目概览
IEQEFCR
/
halo
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
halo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6f6ed51e
编写于
4月 21, 2019
作者:
RYAN0UP
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/v1' into v1
上级
21956071
2292db3c
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
89 addition
and
35 deletion
+89
-35
src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java
...ain/java/run/halo/app/config/WebMvcAutoConfiguration.java
+5
-3
src/main/java/run/halo/app/service/PostService.java
src/main/java/run/halo/app/service/PostService.java
+18
-0
src/main/java/run/halo/app/service/impl/PostServiceImpl.java
src/main/java/run/halo/app/service/impl/PostServiceImpl.java
+21
-0
src/main/java/run/halo/app/web/controller/base/ControllerExceptionHandler.java
...o/app/web/controller/base/ControllerExceptionHandler.java
+9
-0
src/main/java/run/halo/app/web/controller/content/ContentFeedController.java
...alo/app/web/controller/content/ContentFeedController.java
+36
-32
未找到文件。
src/main/java/run/halo/app/config/WebMvcAutoConfiguration.java
浏览文件 @
6f6ed51e
...
...
@@ -3,7 +3,6 @@ package run.halo.app.config;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
freemarker.template.TemplateExceptionHandler
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.jackson.JsonComponentModule
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
...
...
@@ -44,8 +43,11 @@ public class WebMvcAutoConfiguration implements WebMvcConfigurer {
private
static
final
String
FILE_PROTOCOL
=
"file:///"
;
@Autowired
private
HaloProperties
haloProperties
;
private
final
HaloProperties
haloProperties
;
public
WebMvcAutoConfiguration
(
HaloProperties
haloProperties
)
{
this
.
haloProperties
=
haloProperties
;
}
@Override
public
void
extendMessageConverters
(
List
<
HttpMessageConverter
<?>>
converters
)
{
...
...
src/main/java/run/halo/app/service/PostService.java
浏览文件 @
6f6ed51e
...
...
@@ -193,4 +193,22 @@ public interface PostService extends CrudService<Post, Integer> {
*/
@NonNull
Page
<
PostListVO
>
convertToListVo
(
@NonNull
Page
<
Post
>
postPage
);
/**
* Lists all posts by post status.
*
* @param status post status must not be null
* @return a list of post
*/
@NonNull
List
<
Post
>
listAllBy
(
@NonNull
PostStatus
status
);
/**
* Filters post content if the password is not blank.
*
* @param post original post must not be null
* @return filtered post
*/
@NonNull
Post
filterIfEncrypt
(
@NonNull
Post
post
);
}
src/main/java/run/halo/app/service/impl/PostServiceImpl.java
浏览文件 @
6f6ed51e
...
...
@@ -416,6 +416,27 @@ public class PostServiceImpl extends AbstractCrudService<Post, Integer> implemen
});
}
@Override
public
List
<
Post
>
listAllBy
(
PostStatus
status
)
{
Assert
.
notNull
(
status
,
"Post status must not be null"
);
return
postRepository
.
findAllByStatus
(
status
);
}
@Override
public
Post
filterIfEncrypt
(
Post
post
)
{
Assert
.
notNull
(
post
,
"Post must not be null"
);
if
(
StringUtils
.
isNotBlank
(
post
.
getPassword
()))
{
String
tip
=
"The post is encrypted by author"
;
post
.
setSummary
(
tip
);
post
.
setOriginalContent
(
tip
);
post
.
setFormatContent
(
tip
);
}
return
post
;
}
/**
* Converts to post minimal output dto.
*
...
...
src/main/java/run/halo/app/web/controller/base/ControllerExceptionHandler.java
浏览文件 @
6f6ed51e
package
run.halo.app.web.controller.base
;
import
org.springframework.web.HttpMediaTypeNotAcceptableException
;
import
run.halo.app.exception.HaloException
;
import
run.halo.app.model.support.BaseResponse
;
import
run.halo.app.utils.ExceptionUtils
;
...
...
@@ -82,6 +83,14 @@ public class ControllerExceptionHandler {
return
baseResponse
;
}
@ExceptionHandler
(
HttpMediaTypeNotAcceptableException
.
class
)
@ResponseStatus
(
HttpStatus
.
NOT_ACCEPTABLE
)
public
BaseResponse
handleHttpMediaTypeNotAcceptableException
(
HttpMediaTypeNotAcceptableException
e
)
{
BaseResponse
<?>
baseResponse
=
handleBaseException
(
e
);
baseResponse
.
setStatus
(
HttpStatus
.
NOT_ACCEPTABLE
.
value
());
return
baseResponse
;
}
@ExceptionHandler
(
HttpMessageNotReadableException
.
class
)
@ResponseStatus
(
HttpStatus
.
BAD_REQUEST
)
public
BaseResponse
handleHttpMessageNotReadableException
(
HttpMessageNotReadableException
e
)
{
...
...
src/main/java/run/halo/app/web/controller/content/ContentFeedController.java
浏览文件 @
6f6ed51e
package
run.halo.app.web.controller.content
;
import
run.halo.app.model.entity.Post
;
import
run.halo.app.model.enums.PostStatus
;
import
run.halo.app.model.enums.PostType
;
import
run.halo.app.service.OptionService
;
import
run.halo.app.service.PostService
;
import
cn.hutool.core.util.StrUtil
;
import
freemarker.template.Template
;
import
freemarker.template.TemplateException
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.http.MediaType
;
import
org.springframework.lang.NonNull
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.freemarker.FreeMarkerTemplateUtils
;
...
...
@@ -20,11 +15,14 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
import
run.halo.app.model.entity.Post
;
import
run.halo.app.model.enums.PostStatus
;
import
run.halo.app.service.OptionService
;
import
run.halo.app.service.PostService
;
import
java.io.IOException
;
import
java.util.List
;
import
static
org
.
springframework
.
data
.
domain
.
Sort
.
Direction
.
DESC
;
/**
* @author : RYAN0UP
* @date : 2019-03-21
...
...
@@ -38,6 +36,10 @@ public class ContentFeedController {
private
final
FreeMarkerConfigurer
freeMarker
;
private
final
static
String
UTF_8_SUFFIX
=
";charset=UTF-8"
;
private
final
static
String
XML_MEDIA_TYPE
=
MediaType
.
APPLICATION_XML_VALUE
+
UTF_8_SUFFIX
;
public
ContentFeedController
(
PostService
postService
,
OptionService
optionService
,
FreeMarkerConfigurer
freeMarker
)
{
...
...
@@ -54,14 +56,11 @@ public class ContentFeedController {
* @throws IOException IOException
* @throws TemplateException TemplateException
*/
@GetMapping
(
value
=
{
"feed"
,
"feed.xml"
,
"rss"
,
"rss.xml"
},
produces
=
"application/xml;charset=UTF-8"
)
@GetMapping
(
value
=
{
"feed"
,
"feed.xml"
,
"rss"
,
"rss.xml"
},
produces
=
XML_MEDIA_TYPE
)
@ResponseBody
public
String
feed
(
Model
model
)
throws
IOException
,
TemplateException
{
int
rssPageSize
=
optionService
.
getRssPageSize
();
final
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"postDate"
);
final
Pageable
pageable
=
PageRequest
.
of
(
0
,
rssPageSize
,
sort
);
model
.
addAttribute
(
"posts"
,
buildPosts
(
pageable
));
final
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/rss.ftl"
);
model
.
addAttribute
(
"posts"
,
buildPosts
(
buildPostPageable
(
optionService
.
getRssPageSize
())));
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/rss.ftl"
);
return
FreeMarkerTemplateUtils
.
processTemplateIntoString
(
template
,
model
);
}
...
...
@@ -73,14 +72,11 @@ public class ContentFeedController {
* @throws IOException IOException
* @throws TemplateException TemplateException
*/
@GetMapping
(
value
=
{
"atom"
,
"atom.xml"
},
produces
=
"application/xml;charset=UTF-8"
)
@GetMapping
(
value
=
{
"atom"
,
"atom.xml"
},
produces
=
XML_MEDIA_TYPE
)
@ResponseBody
public
String
atom
(
Model
model
)
throws
IOException
,
TemplateException
{
int
pageSize
=
optionService
.
getPostPageSize
();
final
Sort
sort
=
new
Sort
(
Sort
.
Direction
.
DESC
,
"createTime"
);
final
Pageable
pageable
=
PageRequest
.
of
(
0
,
pageSize
,
sort
);
model
.
addAttribute
(
"posts"
,
buildPosts
(
pageable
));
final
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/atom.ftl"
);
model
.
addAttribute
(
"posts"
,
buildPosts
(
buildPostPageable
(
optionService
.
getPostPageSize
())));
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/atom.ftl"
);
return
FreeMarkerTemplateUtils
.
processTemplateIntoString
(
template
,
model
);
}
...
...
@@ -92,11 +88,11 @@ public class ContentFeedController {
* @throws IOException IOException
* @throws TemplateException TemplateException
*/
@GetMapping
(
value
=
{
"sitemap"
,
"sitemap.xml"
},
produces
=
"application/xml;charset=UTF-8"
)
@GetMapping
(
value
=
{
"sitemap"
,
"sitemap.xml"
},
produces
=
XML_MEDIA_TYPE
)
@ResponseBody
public
String
sitemapXml
(
Model
model
)
throws
IOException
,
TemplateException
{
model
.
addAttribute
(
"posts"
,
buildPosts
(
null
));
final
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/sitemap_xml.ftl"
);
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/sitemap_xml.ftl"
);
return
FreeMarkerTemplateUtils
.
processTemplateIntoString
(
template
,
model
);
}
...
...
@@ -106,7 +102,7 @@ public class ContentFeedController {
* @param model model
* @return String
*/
@GetMapping
(
value
=
"sitemap.html"
,
produces
=
{
"text/html"
}
)
@GetMapping
(
value
=
"sitemap.html"
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
public
String
sitemapHtml
(
Model
model
)
{
model
.
addAttribute
(
"posts"
,
buildPosts
(
null
));
return
"common/web/sitemap_html"
;
...
...
@@ -120,13 +116,24 @@ public class ContentFeedController {
* @throws IOException IOException
* @throws TemplateException TemplateException
*/
@GetMapping
(
value
=
"robots.txt"
,
produces
=
{
"text/plain"
}
)
@GetMapping
(
value
=
"robots.txt"
,
produces
=
MediaType
.
TEXT_PLAIN_VALUE
)
@ResponseBody
public
String
robots
(
Model
model
)
throws
IOException
,
TemplateException
{
final
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/robots.ftl"
);
Template
template
=
freeMarker
.
getConfiguration
().
getTemplate
(
"common/web/robots.ftl"
);
return
FreeMarkerTemplateUtils
.
processTemplateIntoString
(
template
,
model
);
}
/**
* Builds page info for post.
*
* @param size page size
* @return page info
*/
@NonNull
private
Pageable
buildPostPageable
(
int
size
)
{
return
PageRequest
.
of
(
0
,
size
,
Sort
.
by
(
DESC
,
"createTime"
));
}
/**
* Build posts for feed
*
...
...
@@ -134,13 +141,10 @@ public class ContentFeedController {
* @return List<Post>
*/
private
List
<
Post
>
buildPosts
(
Pageable
pageable
)
{
final
Page
<
Post
>
postsPage
=
postService
.
pageBy
(
PostStatus
.
PUBLISHED
,
pageable
).
map
(
post
->
{
if
(
StrUtil
.
isNotEmpty
(
post
.
getPassword
()))
{
post
.
setFormatContent
(
"该文章为加密文章"
);
post
.
setSummary
(
"该文章为加密文章"
);
}
return
post
;
});
return
postsPage
.
getContent
();
if
(
pageable
==
null
)
{
return
postService
.
listAllBy
(
PostStatus
.
PUBLISHED
);
}
return
postService
.
pageBy
(
PostStatus
.
PUBLISHED
,
pageable
).
map
(
postService:
:
filterIfEncrypt
).
getContent
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录