Skip to content

Commit

Permalink
👽 0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ruibaby committed May 6, 2018
1 parent 2d650d7 commit edefe09
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 293 deletions.
2 changes: 1 addition & 1 deletion bin/halo.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
APP_NAME=halo-0.0.1.jar
APP_NAME=halo-0.0.2.jar

usage() {
echo "用法: sh halo.sh [start(启动)|stop(停止)|restart(重启)|status(状态)]"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>cc.ryanc</groupId>
<artifactId>halo</artifactId>
<version>0.0.1</version>
<version>0.0.2</version>
<name>halo</name>

<description>
Expand Down
23 changes: 21 additions & 2 deletions src/main/java/cc/ryanc/halo/repository/PostRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,33 @@ public interface PostRepository extends JpaRepository<Post,Long>{
@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<Post> findPostByYearAndMonth(@Param("year") String year,@Param("month") String month,Pageable pageable);

List<Post> findPostByCategories(Category category);
/**
* 根据分类目录查询文章
*
* @param category category
* @param pageable pageable
* @return Page<Post></>
*/
Page<Post> findPostByCategories(Category category,Pageable pageable);

/**
* 根据标签查询文章
*
* @param tag tag
* @param pageable pageable
* @return page
* @return Page<Post></>
*/
Page<Post> findPostsByTags(Tag tag,Pageable pageable);

/**
* 模糊查询文章
*
* @param postType 文章类型,post or page
* @param postStatus 0,1,2
* @param keyword 关键词
* @param pageable 分页信息
* @return Page<Post></>
*/
@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<Post> findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(String keyword,Pageable pageable);
}
19 changes: 19 additions & 0 deletions src/main/java/cc/ryanc/halo/service/PostService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.ryanc.halo.service;

import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive;
Expand Down Expand Up @@ -175,6 +176,15 @@ public interface PostService {
*/
List<Post> findPostByYear(String year);

/**
* 根据分类目录查询文章
*
* @param category category
* @param pageable pageable
* @return Page<Post></>
*/
Page<Post> findPostByCategories(Category category,Pageable pageable);

/**
* 根据标签查询文章
*
Expand All @@ -184,6 +194,15 @@ public interface PostService {
*/
Page<Post> findPostsByTags(Tag tag, Pageable pageable);

/**
* 搜索文章
*
* @param keyword 关键词
* @param pageable 分页信息
* @return Page<Post></>
*/
Page<Post> searchByKeywords(String keyword,Pageable pageable);

/**
* 生成rss
*
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/cc/ryanc/halo/service/impl/PostServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cc.ryanc.halo.service.impl;

import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.domain.Tag;
import cc.ryanc.halo.model.dto.Archive;
Expand Down Expand Up @@ -277,6 +278,18 @@ public Page<Post> findPostByYearAndMonth(String year, String month, Pageable pag
return postRepository.findPostByYearAndMonth(year, month, null);
}

/**
* 根据分类目录查询文章
*
* @param category category
* @param pageable pageable
* @return Page<Post></>
*/
@Override
public Page<Post> findPostByCategories(Category category, Pageable pageable) {
return postRepository.findPostByCategories(category,pageable);
}

/**
* 根据标签查询文章
*
Expand All @@ -289,6 +302,18 @@ public Page<Post> findPostsByTags(Tag tag, Pageable pageable) {
return postRepository.findPostsByTags(tag, pageable);
}

/**
* 搜索文章
*
* @param keyword 关键词
* @param pageable 分页信息
* @return List<Post></>
*/
@Override
public Page<Post> searchByKeywords(String keyword,Pageable pageable) {
return postRepository.findPostByPostTitleLikeOrPostContentLikeAndPostTypeAndPostStatus(keyword,pageable);
}

/**
* 生成rss
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public String saveGallery(@ModelAttribute Gallery gallery) {
} catch (Exception e) {
e.printStackTrace();
}
return "redirect:/admin/page/gallery";
return "redirect:/admin/page/galleries";
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
package cc.ryanc.halo.web.controller.front;

import cc.ryanc.halo.model.domain.Category;
import cc.ryanc.halo.model.domain.Post;
import cc.ryanc.halo.model.dto.HaloConst;
import cc.ryanc.halo.service.CategoryService;
import cc.ryanc.halo.service.PostService;
import cc.ryanc.halo.web.controller.core.BaseController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
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.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -16,7 +27,19 @@
*/
@Controller
@RequestMapping(value = "categories")
public class CategoriesController {
public class CategoriesController extends BaseController {

@Autowired
private CategoryService categoryService;

@Autowired
private PostService postService;

public String categories(Model model){
List<Category> categories = categoryService.findAllCategories();
model.addAttribute("categories",categories);
return this.render("categories");
}

/**
* 根据分类路径查询文章
Expand All @@ -28,7 +51,30 @@ public class CategoriesController {
@GetMapping(value = "{cateUrl}")
public String categories(Model model,
@PathVariable("cateUrl") String cateUrl) {
List<Post> posts;
return null;
return this.categories(model,cateUrl,1);
}

/**
* 根据分类目录查询所有文章 分页
*
* @param model model
* @param cateUrl 分类目录路径
* @param page 页码
* @return string
*/
public String categories(Model model,
@PathVariable("cateUrl") String cateUrl,
@PathVariable("page") Integer page){
Category category = categoryService.findByCateUrl(cateUrl);
Sort sort = new Sort(Sort.Direction.DESC,"postDate");
Integer size = 10;
if(!StringUtils.isBlank(HaloConst.OPTIONS.get("index_posts"))){
size = Integer.parseInt(HaloConst.OPTIONS.get("index_posts"));
}
Pageable pageable = new PageRequest(page-1,size,sort);
Page<Post> posts = postService.findPostByCategories(category,pageable);
model.addAttribute("posts",posts);
model.addAttribute("category",category);
return this.render("category");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,18 @@ public List<Post> ajaxIndex(@PathParam(value = "page") Integer page) {
List<Post> posts = postService.findPostByStatus(0, HaloConst.POST_TYPE_POST, pageable).getContent();
return posts;
}

/**
* 搜索文章
*
* @param keyword keyword
* @param model model
* @return 模板路径/themes/{theme}/index
*/
@GetMapping(value = "search")
public String search(@PathParam("keyword") String keyword,Model model){
Page<Post> posts = postService.searchByKeywords(keyword,null);
model.addAttribute("posts",posts);
return this.render("index");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ public String tags(Model model,
Page<Post> posts = postService.findPostsByTags(tag, pageable);
model.addAttribute("posts", posts);
model.addAttribute("tag", tag);
return this.render("tags");
return this.render("tag");
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spring:
jpa:
hibernate:
ddl-auto: update
show-sql: false
show-sql: true
freemarker:
allow-request-override: false
cache: false
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin/admin_page.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
</#list>
<#else>
<tr>
<td colspan="3" style="text-align: center;">暂无页面</td>
<td colspan="5" style="text-align: center;">暂无页面</td>
</tr>
</#if>
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin/admin_page_gallery.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<div class="form-group">
<label for="galleryThumbnailUrl" class="col-sm-2 control-label">缩略图地址:</label>
<div class="col-sm-4">
<input type="url" class="form-control" id="galleryThumbnailUrl" name="galleryThumbnailUrl">
<input type="text" class="form-control" id="galleryThumbnailUrl" name="galleryThumbnailUrl">
</div>
</div>
</div>
Expand Down
15 changes: 11 additions & 4 deletions src/main/resources/templates/admin/widget/_gallery-detail.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,31 @@
<div class="form-group">
<label for="galleryDesc" class="col-sm-2 control-label">图片描述:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="galleryDesc" name="galleryDesc" value="${gallery.galleryDesc}" >
<input type="text" class="form-control" id="galleryDesc" name="galleryDesc" value="${gallery.galleryDesc?if_exists}" >
</div>
</div>
<div class="form-group">
<label for="galleryDate" class="col-sm-2 control-label">图片日期:</label>
<div class="col-sm-10">
<input type="date" class="form-control" id="galleryDate" name="galleryDate" value="${gallery.galleryDate}">
<input type="date" class="form-control" id="galleryDate" name="galleryDate" value="${gallery.galleryDate?if_exists}">
</div>
</div>
<div class="form-group">
<label for="galleryLocation" class="col-sm-2 control-label">拍摄地点:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="galleryLocation" name="galleryLocation" value="${gallery.galleryLocation}" >
<input type="text" class="form-control" id="galleryLocation" name="galleryLocation" value="${gallery.galleryLocation?if_exists}" >
</div>
</div>
<div class="form-group">
<label for="galleryUrl" class="col-sm-2 control-label">图片地址:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="galleryUrl" name="galleryUrl" value="${gallery.galleryUrl}" disabled>
<input type="text" class="form-control" id="galleryUrl" name="galleryUrl" value="${gallery.galleryUrl}">
</div>
</div>
<div class="form-group">
<label for="galleryUrl" class="col-sm-2 control-label">缩略图地址:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="galleryThumbnailUrl" name="galleryThumbnailUrl" value="${gallery.galleryThumbnailUrl}">
</div>
</div>
</div>
Expand Down Expand Up @@ -115,6 +121,7 @@
}
function btn_save() {
$('#galleryForm').submit();
parent.location.reload();
}
</script>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,10 @@
<i class="material-icons mdl-color-text--white" role="presentation">search</i>
</label>

<form autocomplete="off" id="search-form" method="get" action="//google.com/search" accept-charset="UTF-8" class="mdl-textfield__expandable-holder" target="_blank">
<input class="mdl-textfield__input search-input" type="search" name="q" id="search" placeholder="">
<form autocomplete="off" id="search-form" method="get" action="/search" accept-charset="UTF-8" class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input search-input" type="search" name="keyword" id="search" placeholder="">
<label id="search-form-label" class="mdl-textfield__label" for="search"></label>

<input type="hidden" name="sitesearch" value="">
</form>
</div>
<!--
<% if( theme.search.use === 'swiftype' ) { %>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable" method="post" action="">
<label id="search-label" class="mdl-button mdl-js-ripple-effect mdl-js-button mdl-button--fab mdl-color--accent mdl-shadow--4dp" for="search">
<i class="material-icons mdl-color-text--white" role="presentation">search</i>
</label>
<form autocomplete="off" id="search-form" class="mdl-textfield__expandable-holder" action="">
<input class="mdl-textfield__input search-input st-default-search-input" type="text" name="q" id="search">
<label id="search-form-label" class="mdl-textfield__label" for="search"></label>
</form>
</div>
<% } %>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable" method="post" action="">
<label id="search-label" class="mdl-button mdl-js-ripple-effect mdl-js-button mdl-button--fab mdl-color--accent mdl-shadow--4dp" for="search">
<i class="material-icons mdl-color-text--white" role="presentation">search</i>
</label>
<form autocomplete="off" id="search-form" class="mdl-textfield__expandable-holder">
<input type="text" id="search" class="form-control mdl-textfield__input search-input" name="q" results="0" placeholder=""/>
<label id="search-form-label" class="mdl-textfield__label" for="search"></label>
</form>
</div>
<div id="local-search-result"></div>
-->

Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<@commonTag method="categories">
<#list categories as cate>
<li>
<a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">4</span></a>
<a class="sidebar_archives-link" href="/categories/${cate.cateUrl}/">${cate.cateName}<span class="sidebar_archives-count">${cate.posts?size}</span></a>
</li>
</#list>
</@commonTag>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit edefe09

Please sign in to comment.