mirror of https://github.com/halo-dev/halo
Fix #264 fatal render for rss
parent
983856e9ff
commit
acc1448f6d
|
@ -2,6 +2,7 @@ package run.halo.app.controller.content;
|
|||
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -22,6 +23,9 @@ import run.halo.app.service.OptionService;
|
|||
import run.halo.app.service.PostService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
@ -30,6 +34,7 @@ import static org.springframework.data.domain.Sort.Direction.DESC;
|
|||
* @author ryanwang
|
||||
* @date : 2019-03-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Controller
|
||||
public class ContentFeedController {
|
||||
|
||||
|
@ -144,6 +149,14 @@ public class ContentFeedController {
|
|||
private List<PostListVO> buildPosts(@NonNull Pageable pageable) {
|
||||
Page<Post> postPage = postService.pageBy(PostStatus.PUBLISHED, pageable);
|
||||
Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||
posts.getContent().forEach(postListVO -> {
|
||||
try {
|
||||
// Encode post url
|
||||
postListVO.setUrl(URLEncoder.encode(postListVO.getUrl(), StandardCharsets.UTF_8.name()));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.warn("Failed to encode url: " + postListVO.getUrl(), e);
|
||||
}
|
||||
});
|
||||
return posts.getContent();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue