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 d440f268e..17b8f0fac 100644 --- a/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java +++ b/src/main/java/cc/ryanc/halo/model/tag/ArticleTagDirective.java @@ -41,6 +41,9 @@ public class ArticleTagDirective implements TemplateDirectiveModel { case "archivesLess": environment.setVariable("archivesLess", builder.build().wrap(postService.findPostGroupByYear())); break; + case "hotPosts": + environment.setVariable("hotPosts", builder.build().wrap(postService.hotPosts())); + break; default: break; } diff --git a/src/main/java/cc/ryanc/halo/repository/PostRepository.java b/src/main/java/cc/ryanc/halo/repository/PostRepository.java index 4203def32..3485a18ce 100644 --- a/src/main/java/cc/ryanc/halo/repository/PostRepository.java +++ b/src/main/java/cc/ryanc/halo/repository/PostRepository.java @@ -180,4 +180,12 @@ public interface PostRepository extends JpaRepository { */ @Query(value = "select * from halo_post where post_status = 0 and post_type='post' and post_title like '%=:keyword%' or post_content like '%=:keyword%'", nativeQuery = true) Page findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(String keyword, Pageable pageable); + + /** + * 按热度从大到小排序 + * + * @param postStatus 文章状态 + * @return List + */ + List findPostsByPostTypeOrderByPostViewsDesc(String postStatus); } diff --git a/src/main/java/cc/ryanc/halo/service/PostService.java b/src/main/java/cc/ryanc/halo/service/PostService.java index b2f1486db..dc53115f3 100755 --- a/src/main/java/cc/ryanc/halo/service/PostService.java +++ b/src/main/java/cc/ryanc/halo/service/PostService.java @@ -202,6 +202,13 @@ public interface PostService { */ Page searchByKeywords(String keyword,Pageable pageable); + /** + * 热门文章 + * + * @return List + */ + List hotPosts(); + /** * 生成rss * 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 2b3520f90..c2bd55e03 100755 --- a/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java +++ b/src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java @@ -315,6 +315,16 @@ public class PostServiceImpl implements PostService { return postRepository.findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(keyword,pageable); } + /** + * 热门文章 + * + * @return List + */ + @Override + public List hotPosts() { + return postRepository.findPostsByPostTypeOrderByPostViewsDesc(HaloConst.POST_TYPE_POST); + } + /** * 生成rss * diff --git a/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java b/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java index 5ba498b3e..3df92484d 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java @@ -15,6 +15,8 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.List; + /** * @author : RYAN0UP * @date : 2018/6/6 @@ -47,6 +49,16 @@ public class ApiPostController { return new JsonResult(200,"success",posts); } + @GetMapping(value = "/hot") + public JsonResult hotPosts() { + List posts = postService.hotPosts(); + if (null != posts && posts.size() > 0) { + return new JsonResult(200, "success", posts); + } else { + return new JsonResult(200, "empty"); + } + } + /** * 获取单个文章信息 * diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java index 51de90904..407ca5efa 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java @@ -17,6 +17,7 @@ import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import java.util.Date; import java.util.List; diff --git a/src/main/resources/static/js/app.js b/src/main/resources/static/js/app.js index 3918af70e..03c935f64 100755 --- a/src/main/resources/static/js/app.js +++ b/src/main/resources/static/js/app.js @@ -31,7 +31,6 @@ function initMenu() { if(pathName=="/admin/menus/edit"){ pathName="/admin/menus"; } - console.log(pathName); $(".sidebar-menu").children().each(function () { var li = $(this); li.find('a').each(function () { diff --git a/src/main/resources/templates/admin/admin_theme-editor.ftl b/src/main/resources/templates/admin/admin_theme-editor.ftl index bd76d45f3..517281388 100644 --- a/src/main/resources/templates/admin/admin_theme-editor.ftl +++ b/src/main/resources/templates/admin/admin_theme-editor.ftl @@ -77,6 +77,9 @@ <#break> <#case "gallery.ftl"> 图库页面 + <#case "module/options.ftl"> + 设置选项 + <#break > <#break> diff --git a/src/main/resources/templates/admin/module/_macro.ftl b/src/main/resources/templates/admin/module/_macro.ftl index e270e6522..3669b38c1 100644 --- a/src/main/resources/templates/admin/module/_macro.ftl +++ b/src/main/resources/templates/admin/module/_macro.ftl @@ -20,6 +20,7 @@ + <#if options.admin_loading?default("false") == "true"> @@ -47,6 +48,9 @@ <@compress single_line=true> + - +