diff --git a/src/main/java/cc/ryanc/halo/model/dto/HaloConst.java b/src/main/java/cc/ryanc/halo/model/dto/HaloConst.java index 262a182ff..851511844 100644 --- a/src/main/java/cc/ryanc/halo/model/dto/HaloConst.java +++ b/src/main/java/cc/ryanc/halo/model/dto/HaloConst.java @@ -35,4 +35,8 @@ public class HaloConst { * user_session */ public static String USER_SESSION_KEY = "user_session"; + + public static String POST_TYPE_POST = "post"; + + public static String POST_TYPE_PAGE = "page"; } diff --git a/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java b/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java index 4d20babbb..95e530515 100644 --- a/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java +++ b/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java @@ -1,5 +1,6 @@ package cc.ryanc.halo.model.tag; +import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.PostService; import freemarker.core.Environment; import freemarker.template.*; @@ -29,7 +30,7 @@ public class ArticleTagDirective implements TemplateDirectiveModel { String method = map.get(METHOD_KEY).toString(); switch (method){ case "postsCount": - environment.setVariable("postsCount",builder.build().wrap(postService.findAllPosts().size())); + environment.setVariable("postsCount",builder.build().wrap(postService.findAllPosts(HaloConst.POST_TYPE_POST).size())); break; case "archives": environment.setVariable("archives",builder.build().wrap(postService.findPostGroupByYearAndMonth())); diff --git a/src/main/java/cc/ryanc/halo/repository/PostRepository.java b/src/main/java/cc/ryanc/halo/repository/PostRepository.java index 62d7b64eb..e220817cf 100644 --- a/src/main/java/cc/ryanc/halo/repository/PostRepository.java +++ b/src/main/java/cc/ryanc/halo/repository/PostRepository.java @@ -25,17 +25,25 @@ public interface PostRepository extends JpaRepository{ * * @return list */ - @Query(value = "SELECT * FROM halo_post ORDER BY post_date DESC LIMIT 5",nativeQuery = true) + @Query(value = "SELECT * FROM halo_post where post_type='post' ORDER BY post_date DESC LIMIT 5",nativeQuery = true) List findTopFive(); + /** + * 查询所有文章 根据文章类型 + * + * @param postType post or page + * @return List + */ + List findPostsByPostType(String postType); + /** * 分页查询文章 * - * @param pageable pageable - * @return page + * @param postType post or page + * @param pageable 分页信息 + * @return Page */ - @Override - Page findAll(Pageable pageable); + Page findPostsByPostType(String postType,Pageable pageable); /** * 模糊查询 @@ -49,19 +57,21 @@ public interface PostRepository extends JpaRepository{ /** * 根据文章的状态查询 分页 * - * @param status status - * @param pageable pageable - * @return page + * @param status 0,1,2 + * @param postType post or page + * @param pageable 分页信息 + * @return Page */ - Page findPostsByPostStatus(Integer status,Pageable pageable); + Page findPostsByPostStatusAndPostType(Integer status,String postType,Pageable pageable); /** * 根据文章的状态查询 * - * @param status status - * @return List + * @param status 0,1,2 + * @param postType post or page + * @return List */ - List findPostsByPostStatus(Integer status); + List findPostsByPostStatusAndPostType(Integer status,String postType); /** * 根据路径查询文章 @@ -74,35 +84,37 @@ public interface PostRepository extends JpaRepository{ /** * 查询之后文章 * - * @param postDate postDate - * @param postStatus postStatus - * @return list + * @param postDate 发布时间 + * @param postStatus 0,1,2 + * @param postType post or page + * @return List */ - List findByPostDateAfterAndPostStatusOrderByPostDateDesc(Date postDate, Integer postStatus); + List findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(Date postDate, Integer postStatus,String postType); /** * 查询之前的文章 * - * @param postDate postDate - * @param postStatus postStatus - * @return list + * @param postDate 发布时间 + * @param postStatus 0,1,2 + * @param postType post or page + * @return List */ - List findByPostDateBeforeAndPostStatusOrderByPostDateAsc(Date postDate,Integer postStatus); + List findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(Date postDate,Integer postStatus,String postType); /** * 查询文章归档信息 根据年份和月份 * - * @return list + * @return List */ - @Query(value = "select year(post_date) as year,month(post_date) as month,count(*) as count from halo_post where post_status=0 group by year(post_date),month(post_date) order by year desc,month desc",nativeQuery = true) + @Query(value = "select year(post_date) as year,month(post_date) as month,count(*) as count from halo_post where post_status=0 and post_type='post' group by year(post_date),month(post_date) order by year desc,month desc",nativeQuery = true) List findPostGroupByYearAndMonth(); /** * 查询文章归档信息 根据年份 - * @return + * @return List */ - @Query(value = "select year(post_date) as year,count(*) as count from halo_post where post_status=0 group by year(post_date) order by year desc",nativeQuery = true) + @Query(value = "select year(post_date) as year,count(*) as count from halo_post where post_status=0 and post_type='post' group by year(post_date) order by year desc",nativeQuery = true) List findPostGroupByYear(); /** @@ -110,18 +122,18 @@ public interface PostRepository extends JpaRepository{ * * @param year year * @param month month - * @return list + * @return List */ - @Query(value = "select *,year(post_date) as year,month(post_date) as month from halo_post where post_status=0 and year(post_date)=:year and month(post_date)=:month order by post_date desc",nativeQuery = true) + @Query(value = "select *,year(post_date) as year,month(post_date) as month from halo_post where post_status=0 and post_type='post' and year(post_date)=:year and month(post_date)=:month order by post_date desc",nativeQuery = true) List findPostByYearAndMonth(@Param("year") String year,@Param("month") String month); /** * 根据年份查询文章 * * @param year year - * @return list + * @return List */ - @Query(value = "select *,year(post_date) as year from halo_post where post_status=0 and year(post_date)=:year order by post_date desc",nativeQuery = true) + @Query(value = "select *,year(post_date) as year from halo_post where post_status=0 and post_type='post' and year(post_date)=:year order by post_date desc",nativeQuery = true) List findPostByYear(@Param("year") String year); /** @@ -130,9 +142,9 @@ public interface PostRepository extends JpaRepository{ * @param year year * @param month month * @param pageable pageable - * @return page + * @return Page */ - @Query(value = "select * from halo_post where post_status=0 and year(post_date)=:year and month(post_date)=:month order by post_date desc",countQuery = "select count(*) from halo_post where post_status=0 and year(post_date)=:year and month(post_date)=:month",nativeQuery = true) + @Query(value = "select * from halo_post where post_status=0 and post_type='post' and year(post_date)=:year and month(post_date)=:month order by post_date desc",countQuery = "select count(*) from halo_post where post_status=0 and year(post_date)=:year and month(post_date)=:month",nativeQuery = true) Page findPostByYearAndMonth(@Param("year") String year,@Param("month") String month,Pageable pageable); List findPostByCategories(Category category); diff --git a/src/main/java/cc/ryanc/halo/service/PostService.java b/src/main/java/cc/ryanc/halo/service/PostService.java index a9e8947a9..128ebeb02 100755 --- a/src/main/java/cc/ryanc/halo/service/PostService.java +++ b/src/main/java/cc/ryanc/halo/service/PostService.java @@ -35,14 +35,6 @@ public interface PostService { */ Post removeByPostId(Long postId); - /** - * 修改文章 - * - * @param post Post - * @return Post - */ - Post updateByPost(Post post); - /** * 修改文章状态 * @@ -62,17 +54,19 @@ public interface PostService { /** * 获取文章列表 分页 * - * @param pageable Pageable - * @return Page + * @param postType post or page + * @param pageable 分页信息 + * @return Page */ - Page findAllPosts(Pageable pageable); + Page findAllPosts(String postType,Pageable pageable); /** * 获取文章列表 不分页 * - * @return List + * @param postType post or page + * @return List */ - List findAllPosts(); + List findAllPosts(String postType); /** * 模糊查询文章 @@ -86,19 +80,21 @@ public interface PostService { /** * 根据文章状态查询 分页 * - * @param status status - * @param pageable pageable - * @return page + * @param status 0,1,2 + * @param postType post or page + * @param pageable 分页信息 + * @return Page */ - Page findPostByStatus(Integer status,Pageable pageable); + Page findPostByStatus(Integer status,String postType,Pageable pageable); /** * 根据文章状态查询 * - * @param status status - * @return list + * @param status 0,1,2 + * @param postType post or page + * @return List */ - List findPostByStatus(Integer status); + List findPostByStatus(Integer status,String postType); /** * 根据编号查询文章 diff --git a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java index fee054ff8..6ae26bf24 100755 --- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java @@ -3,6 +3,7 @@ package cc.ryanc.halo.service.impl; import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Tag; import cc.ryanc.halo.model.dto.Archive; +import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.repository.PostRepository; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.util.HaloUtil; @@ -53,17 +54,6 @@ public class PostServiceImpl implements PostService { return post.get(); } - /** - * 修改文章 - * - * @param post Post - * @return post - */ - @Override - public Post updateByPost(Post post) { - return postRepository.save(post); - } - /** * 修改文章状态 * @@ -85,7 +75,7 @@ public class PostServiceImpl implements PostService { */ @Override public void updateAllSummary(Integer postSummary) { - List posts = this.findAllPosts(); + List posts = this.findAllPosts(HaloConst.POST_TYPE_POST); for(Post post:posts){ if(!(HaloUtil.htmlToText(post.getPostContent()).length() */ @Override - public Page findAllPosts(Pageable pageable) { - return postRepository.findAll(pageable); + public Page findAllPosts(String postType,Pageable pageable) { + return postRepository.findPostsByPostType(postType,pageable); } /** - * 查询所有文章 不分页 + * 获取文章列表 不分页 * - * @return List + * @param postType post or page + * @return List */ @Override - public List findAllPosts() { - return postRepository.findAll(); + public List findAllPosts(String postType) { + return postRepository.findPostsByPostType(postType); } /** @@ -128,26 +120,28 @@ public class PostServiceImpl implements PostService { } /** - * 根据状态分页查询文章 + * 根据文章状态查询 分页 * - * @param status status - * @param pageable pageable - * @return page + * @param status 0,1,2 + * @param postType post or page + * @param pageable 分页信息 + * @return Page */ @Override - public Page findPostByStatus(Integer status, Pageable pageable) { - return postRepository.findPostsByPostStatus(status,pageable); + public Page findPostByStatus(Integer status,String postType, Pageable pageable) { + return postRepository.findPostsByPostStatusAndPostType(status,postType,pageable); } /** - * 根据状态查询文章 + * 根据文章状态查询 * - * @param status status - * @return list + * @param status 0,1,2 + * @param postType post or page + * @return List */ @Override - public List findPostByStatus(Integer status) { - return postRepository.findPostsByPostStatus(status); + public List findPostByStatus(Integer status,String postType) { + return postRepository.findPostsByPostStatusAndPostType(status,postType); } /** @@ -190,7 +184,7 @@ public class PostServiceImpl implements PostService { */ @Override public List findByPostDateAfter(Date postDate) { - return postRepository.findByPostDateAfterAndPostStatusOrderByPostDateDesc(postDate,0); + return postRepository.findByPostDateAfterAndPostStatusAndPostTypeOrderByPostDateDesc(postDate,0,HaloConst.POST_TYPE_POST); } /** @@ -201,7 +195,7 @@ public class PostServiceImpl implements PostService { */ @Override public List findByPostDateBefore(Date postDate) { - return postRepository.findByPostDateBeforeAndPostStatusOrderByPostDateAsc(postDate,0); + return postRepository.findByPostDateBeforeAndPostStatusAndPostTypeOrderByPostDateAsc(postDate,0,HaloConst.POST_TYPE_POST); } diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/AdminController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/AdminController.java index 574de8cdc..746ee3e13 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/AdminController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/AdminController.java @@ -63,7 +63,7 @@ public class AdminController extends BaseController{ @GetMapping(value = {"","/index"}) public String index(Model model,HttpSession session){ //查询文章条数 - Integer postCount = postService.findAllPosts().size(); + Integer postCount = postService.findAllPosts(HaloConst.POST_TYPE_POST).size(); model.addAttribute("postCount",postCount); //查询评论的条数 diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java index ee2c24756..f4e9948d5 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java @@ -1,6 +1,7 @@ package cc.ryanc.halo.web.controller.admin; import cc.ryanc.halo.model.domain.Post; +import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.util.HaloUtil; import lombok.extern.slf4j.Slf4j; @@ -73,7 +74,7 @@ public class BackupController { */ @GetMapping(value = "/backupPost") public String backupPosts(){ - List posts = postService.findAllPosts(); + List posts = postService.findAllPosts(HaloConst.POST_TYPE_POST); try { File path = new File(ResourceUtils.getURL("classpath:").getPath()); String savePath = path.getAbsolutePath()+"/backup/posts/posts_backup_"+HaloUtil.getStringDate("yyyy_MM_dd_HH_mm_ss"); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java index 617f9222c..36257a112 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java @@ -1,12 +1,15 @@ package cc.ryanc.halo.web.controller.admin; -import cc.ryanc.halo.model.domain.Gallery; -import cc.ryanc.halo.model.domain.Link; +import cc.ryanc.halo.model.domain.*; +import cc.ryanc.halo.model.dto.HaloConst; +import cc.ryanc.halo.model.dto.LogsRecord; import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.LinkService; +import cc.ryanc.halo.service.LogsService; +import cc.ryanc.halo.service.PostService; +import cc.ryanc.halo.util.HaloUtil; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; -import org.jsoup.helper.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -16,6 +19,8 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; import javax.websocket.server.PathParam; import java.util.List; import java.util.Optional; @@ -37,6 +42,15 @@ public class PageController { @Autowired private GalleryService galleryService; + @Autowired + private PostService postService; + + @Autowired + private LogsService logsService; + + @Autowired + private HttpServletRequest request; + /** * 页面管理页面 * @@ -44,7 +58,9 @@ public class PageController { * @return 模板路径admin/admin_page */ @GetMapping - public String pages(){ + public String pages(Model model){ + List posts = postService.findAllPosts(HaloConst.POST_TYPE_PAGE); + model.addAttribute("pages",posts); return "admin/admin_page"; } @@ -182,4 +198,36 @@ public class PageController { } return true; } + + + /** + * 跳转到新建页面 + * + * @return 模板路径 + */ + @GetMapping(value = "/new") + public String newPage(Model model){ + return "admin/admin_page_md_editor"; + } + + /** + * 发表页面 + * @param post post + * @param session session + */ + @PostMapping(value = "/new/push") + @ResponseBody + public void pushPage(@ModelAttribute Post post, HttpSession session){ + try{ + post.setPostDate(HaloUtil.getDate()); + //发表用户 + User user = (User)session.getAttribute(HaloConst.USER_SESSION_KEY); + post.setUser(user); + post.setPostType(HaloConst.POST_TYPE_PAGE); + postService.saveByPost(post); + logsService.saveByLogs(new Logs(LogsRecord.PUSH_POST,post.getPostTitle(),HaloUtil.getIpAddr(request),HaloUtil.getDate())); + }catch (Exception e){ + log.error("未知错误:{0}",e.getMessage()); + } + } } diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java index 25a082946..01c06bb84 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java @@ -67,11 +67,11 @@ public class PostController extends BaseController{ @RequestParam(value = "size",defaultValue = "10") Integer size){ Sort sort = new Sort(Sort.Direction.DESC,"postDate"); Pageable pageable = new PageRequest(page,size,sort); - Page posts = postService.findPostByStatus(status,pageable); + Page posts = postService.findPostByStatus(status,HaloConst.POST_TYPE_POST,pageable); model.addAttribute("posts",posts); - model.addAttribute("publishCount",postService.findPostByStatus(0,pageable).getTotalElements()); - model.addAttribute("draftCount",postService.findPostByStatus(1,pageable).getTotalElements()); - model.addAttribute("trashCount",postService.findPostByStatus(2,pageable).getTotalElements()); + model.addAttribute("publishCount",postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable).getTotalElements()); + model.addAttribute("draftCount",postService.findPostByStatus(1,HaloConst.POST_TYPE_POST,pageable).getTotalElements()); + model.addAttribute("trashCount",postService.findPostByStatus(2,HaloConst.POST_TYPE_POST,pageable).getTotalElements()); model.addAttribute("status",status); return "admin/admin_post"; } @@ -127,8 +127,7 @@ public class PostController extends BaseController{ List tags = tagService.findAllTags(); model.addAttribute("categories",categories); model.addAttribute("tags",tags); - model.addAttribute("btnPush","发布"); - return "admin/admin_editor"; + return "admin/admin_post_md_editor"; } /** @@ -237,11 +236,10 @@ public class PostController extends BaseController{ model.addAttribute("post",post.get()); List categories = categoryService.findAllCategories(); model.addAttribute("categories",categories); - model.addAttribute("btnPush","更新"); }catch (Exception e){ log.error("未知错误:{0}",e.getMessage()); } - return "admin/admin_editor"; + return "admin/admin_post_md_editor"; } /** diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/ArchivesController.java b/src/main/java/cc/ryanc/halo/web/controller/front/ArchivesController.java index c6db9ad64..7475c54c1 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/ArchivesController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/ArchivesController.java @@ -1,6 +1,7 @@ package cc.ryanc.halo.web.controller.front; import cc.ryanc.halo.model.domain.Post; +import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.web.controller.core.BaseController; import lombok.extern.slf4j.Slf4j; @@ -56,7 +57,7 @@ public class ArchivesController extends BaseController { //所有文章数据,分页,material主题适用 Sort sort = new Sort(Sort.Direction.DESC,"postDate"); Pageable pageable = new PageRequest(page-1,5,sort); - Page posts = postService.findPostByStatus(0,pageable); + Page posts = postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable); model.addAttribute("posts",posts); return this.render("archives"); } diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java b/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java index dfb2dd4e8..eb502471c 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/IndexController.java @@ -1,7 +1,6 @@ package cc.ryanc.halo.web.controller.front; import cc.ryanc.halo.model.domain.Post; -import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.web.controller.core.BaseController; @@ -66,7 +65,7 @@ public class IndexController extends BaseController { } //所有文章数据,分页 Pageable pageable = new PageRequest(page-1,size,sort); - Page posts = postService.findPostByStatus(0,pageable); + Page posts = postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable); model.addAttribute("posts",posts); return this.render("index"); @@ -91,7 +90,7 @@ public class IndexController extends BaseController { //文章数据,只获取文章,没有分页 Pageable pageable = new PageRequest(page-1,size,sort); - List posts = postService.findPostByStatus(0,pageable).getContent(); + List posts = postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable).getContent(); return posts; } } diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/OthersController.java b/src/main/java/cc/ryanc/halo/web/controller/front/OthersController.java index e9b00832d..a50909e44 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/OthersController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/OthersController.java @@ -9,7 +9,6 @@ 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.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; @@ -42,7 +41,7 @@ public class OthersController { //获取文章列表并根据时间排序 Sort sort = new Sort(Sort.Direction.DESC,"postDate"); Pageable pageable = new PageRequest(0,Integer.parseInt(rssPosts),sort); - Page postsPage = postService.findPostByStatus(0,pageable); + Page postsPage = postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable); List posts = postsPage.getContent(); return postService.buildRss(posts); } @@ -58,7 +57,7 @@ public class OthersController { //获取文章列表并根据时间排序 Sort sort = new Sort(Sort.Direction.DESC,"postDate"); Pageable pageable = new PageRequest(0,999,sort); - Page postsPage = postService.findPostByStatus(0,pageable); + Page postsPage = postService.findPostByStatus(0,HaloConst.POST_TYPE_POST,pageable); List posts = postsPage.getContent(); return postService.buildSiteMap(posts); } diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/PagesController.java b/src/main/java/cc/ryanc/halo/web/controller/front/PagesController.java index 40f2febc6..b6d30ed66 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/PagesController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/PagesController.java @@ -2,7 +2,7 @@ package cc.ryanc.halo.web.controller.front; import cc.ryanc.halo.model.domain.Gallery; import cc.ryanc.halo.model.domain.Link; -import cc.ryanc.halo.model.dto.Archive; +import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.service.GalleryService; import cc.ryanc.halo.service.LinkService; import cc.ryanc.halo.service.PostService; @@ -11,6 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import java.util.List; @@ -69,4 +70,18 @@ public class PagesController extends BaseController { model.addAttribute("links",links); return this.render("links"); } + + /** + * 渲染自定义页面 + * + * @param postUrl 页面路径 + * @param model model + * @return 模板路径/themes/{theme}/post + */ + @GetMapping(value = "/{postUrl}") + public String getPage(@PathVariable String postUrl,Model model){ + Post post = postService.findByPostUrl(postUrl); + model.addAttribute("post",post); + return this.render("post"); + } } diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java b/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java index f3aa920b4..e7fde2210 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/TagsController.java @@ -2,7 +2,6 @@ package cc.ryanc.halo.web.controller.front; import cc.ryanc.halo.model.domain.Post; import cc.ryanc.halo.model.domain.Tag; -import cc.ryanc.halo.model.dto.Archive; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.TagService; diff --git a/src/main/resources/templates/admin/admin_comment.ftl b/src/main/resources/templates/admin/admin_comment.ftl index 094121043..6a18fdae3 100755 --- a/src/main/resources/templates/admin/admin_comment.ftl +++ b/src/main/resources/templates/admin/admin_comment.ftl @@ -51,7 +51,7 @@ ${comment.commentAuthor} ${comment.commentContent} - ${comment.post.postTitle} + ${comment.post.postTitle} ${comment.commentDate} diff --git a/src/main/resources/templates/admin/admin_editor.ftl b/src/main/resources/templates/admin/admin_editor.ftl deleted file mode 100755 index 02bc4b623..000000000 --- a/src/main/resources/templates/admin/admin_editor.ftl +++ /dev/null @@ -1,5 +0,0 @@ -<#if (options.post_editor?default('editor.md'))=='editor.md'> - <#include "admin_md-editor.ftl"> -<#else > - <#include "admin_rt-editor.ftl"> - \ No newline at end of file diff --git a/src/main/resources/templates/admin/admin_page.ftl b/src/main/resources/templates/admin/admin_page.ftl index 4b8295ea6..e8aa3a249 100755 --- a/src/main/resources/templates/admin/admin_page.ftl +++ b/src/main/resources/templates/admin/admin_page.ftl @@ -14,7 +14,7 @@

页面

- + 新建页面