mirror of https://github.com/halo-dev/halo
refactor: pagination tag. (#625)
parent
38b4bb4aeb
commit
fd251a4724
|
@ -1,6 +1,5 @@
|
||||||
package run.halo.app.controller.content;
|
package run.halo.app.controller.content;
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
@ -73,49 +72,9 @@ public class ContentSearchController {
|
||||||
|
|
||||||
final Page<PostListVO> posts = postService.convertToListVo(postPage);
|
final Page<PostListVO> posts = postService.convertToListVo(postPage);
|
||||||
|
|
||||||
// TODO remove this variable
|
|
||||||
final int[] rainbow = PageUtil.rainbow(page, posts.getTotalPages(), 3);
|
|
||||||
|
|
||||||
// Next page and previous page url.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
} else {
|
|
||||||
nextPageFullPath.append("/");
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("search");
|
|
||||||
prePageFullPath.append("search");
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(posts.getNumber() + 2)
|
|
||||||
.append(optionService.getPathSuffix())
|
|
||||||
.append("?keyword=")
|
|
||||||
.append(keyword);
|
|
||||||
|
|
||||||
if (posts.getNumber() == 1) {
|
|
||||||
prePageFullPath.append("?keyword=")
|
|
||||||
.append(keyword);
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(posts.getNumber())
|
|
||||||
.append(optionService.getPathSuffix())
|
|
||||||
.append("?keyword=")
|
|
||||||
.append(keyword);
|
|
||||||
}
|
|
||||||
|
|
||||||
model.addAttribute("is_search", true);
|
model.addAttribute("is_search", true);
|
||||||
model.addAttribute("keyword", keyword);
|
model.addAttribute("keyword", keyword);
|
||||||
model.addAttribute("posts", posts);
|
model.addAttribute("posts", posts);
|
||||||
model.addAttribute("rainbow", rainbow);
|
|
||||||
model.addAttribute("nextPageFullPath", nextPageFullPath.toString());
|
|
||||||
model.addAttribute("prePageFullPath", prePageFullPath.toString());
|
|
||||||
model.addAttribute("meta_keywords", optionService.getSeoKeywords());
|
model.addAttribute("meta_keywords", optionService.getSeoKeywords());
|
||||||
model.addAttribute("meta_description", optionService.getSeoDescription());
|
model.addAttribute("meta_description", optionService.getSeoDescription());
|
||||||
return themeService.render("search");
|
return themeService.render("search");
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class PostModel {
|
||||||
postService.publishVisitEvent(post.getId());
|
postService.publishVisitEvent(post.getId());
|
||||||
|
|
||||||
AdjacentPostVO adjacentPostVO = postService.getAdjacentPosts(post);
|
AdjacentPostVO adjacentPostVO = postService.getAdjacentPosts(post);
|
||||||
adjacentPostVO.getOptionalPrePost().ifPresent(prePost -> model.addAttribute("prePost", postService.convertToDetailVo(prePost)));
|
adjacentPostVO.getOptionalPrevPost().ifPresent(prevPost -> model.addAttribute("prevPost", postService.convertToDetailVo(prevPost)));
|
||||||
adjacentPostVO.getOptionalNextPost().ifPresent(nextPost -> model.addAttribute("nextPost", postService.convertToDetailVo(nextPost)));
|
adjacentPostVO.getOptionalNextPost().ifPresent(nextPost -> model.addAttribute("nextPost", postService.convertToDetailVo(nextPost)));
|
||||||
|
|
||||||
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
|
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package run.halo.app.core.freemarker.tag;
|
package run.halo.app.core.freemarker.tag;
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.entity.Category;
|
import run.halo.app.model.entity.Category;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.support.Pagination;
|
|
||||||
import run.halo.app.model.support.RainbowPage;
|
|
||||||
import run.halo.app.service.CategoryService;
|
import run.halo.app.service.CategoryService;
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.service.PostCategoryService;
|
import run.halo.app.service.PostCategoryService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -33,15 +28,11 @@ public class CategoryTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private final PostCategoryService postCategoryService;
|
private final PostCategoryService postCategoryService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
|
||||||
|
|
||||||
public CategoryTagDirective(Configuration configuration,
|
public CategoryTagDirective(Configuration configuration,
|
||||||
CategoryService categoryService,
|
CategoryService categoryService,
|
||||||
PostCategoryService postCategoryService,
|
PostCategoryService postCategoryService) {
|
||||||
OptionService optionService) {
|
|
||||||
this.categoryService = categoryService;
|
this.categoryService = categoryService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
this.optionService = optionService;
|
|
||||||
configuration.setSharedVariable("categoryTag", this);
|
configuration.setSharedVariable("categoryTag", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,81 +54,6 @@ public class CategoryTagDirective implements TemplateDirectiveModel {
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(categoryService.count()));
|
env.setVariable("count", builder.build().wrap(categoryService.count()));
|
||||||
break;
|
break;
|
||||||
case "pagination":
|
|
||||||
// Get params
|
|
||||||
int page = Integer.parseInt(params.get("page").toString());
|
|
||||||
int total = Integer.parseInt(params.get("total").toString());
|
|
||||||
int display = Integer.parseInt(params.get("display").toString());
|
|
||||||
String slug = params.get("slug").toString();
|
|
||||||
|
|
||||||
// Create pagination object.
|
|
||||||
Pagination pagination = new Pagination();
|
|
||||||
|
|
||||||
// Generate next page full path and pre page full path.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
} else {
|
|
||||||
nextPageFullPath.append("/");
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append(optionService.getCategoriesPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
prePageFullPath.append(optionService.getCategoriesPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(page + 2)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
prePageFullPath.append(optionService.getPathSuffix());
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(page)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
|
||||||
pagination.setPrePageFullPath(prePageFullPath.toString());
|
|
||||||
|
|
||||||
// Generate rainbow page number.
|
|
||||||
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
|
||||||
|
|
||||||
List<RainbowPage> rainbowPages = new ArrayList<>();
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
|
||||||
.append(optionService.getCategoriesPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
|
|
||||||
fullPath.append("/page/");
|
|
||||||
|
|
||||||
for (int current : rainbow) {
|
|
||||||
RainbowPage rainbowPage = new RainbowPage();
|
|
||||||
rainbowPage.setPage(current);
|
|
||||||
rainbowPage.setFullPath(fullPath.toString() + current + optionService.getPathSuffix());
|
|
||||||
rainbowPage.setIsCurrent(page + 1 == current);
|
|
||||||
rainbowPages.add(rainbowPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setRainbowPages(rainbowPages);
|
|
||||||
pagination.setHasNext(total != page + 1);
|
|
||||||
pagination.setHasPrev(page != 0);
|
|
||||||
env.setVariable("pagination", builder.build().wrap(pagination));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,113 +0,0 @@
|
||||||
package run.halo.app.core.freemarker.tag;
|
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import freemarker.core.Environment;
|
|
||||||
import freemarker.template.*;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
import run.halo.app.model.support.HaloConst;
|
|
||||||
import run.halo.app.model.support.Pagination;
|
|
||||||
import run.halo.app.model.support.RainbowPage;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ryanwang
|
|
||||||
* @date 2020-03-06
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class JournalTagDirective implements TemplateDirectiveModel {
|
|
||||||
|
|
||||||
private final OptionService optionService;
|
|
||||||
|
|
||||||
public JournalTagDirective(Configuration configuration,
|
|
||||||
OptionService optionService) {
|
|
||||||
this.optionService = optionService;
|
|
||||||
configuration.setSharedVariable("journalTag", this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
|
||||||
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
|
||||||
|
|
||||||
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
|
||||||
String method = params.get(HaloConst.METHOD_KEY).toString();
|
|
||||||
switch (method) {
|
|
||||||
case "pagination":
|
|
||||||
// Get params
|
|
||||||
int page = Integer.parseInt(params.get("page").toString());
|
|
||||||
int total = Integer.parseInt(params.get("total").toString());
|
|
||||||
int display = Integer.parseInt(params.get("display").toString());
|
|
||||||
String slug = params.get("slug").toString();
|
|
||||||
|
|
||||||
// Create pagination object.
|
|
||||||
Pagination pagination = new Pagination();
|
|
||||||
|
|
||||||
// Generate next page full path and pre page full path.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
} else {
|
|
||||||
nextPageFullPath.append("/");
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append(optionService.getJournalsPrefix());
|
|
||||||
prePageFullPath.append(optionService.getJournalsPrefix());
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(page + 2)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
prePageFullPath.append(optionService.getPathSuffix());
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(page)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
|
||||||
pagination.setPrePageFullPath(prePageFullPath.toString());
|
|
||||||
|
|
||||||
// Generate rainbow page number.
|
|
||||||
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
|
||||||
|
|
||||||
List<RainbowPage> rainbowPages = new ArrayList<>();
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
|
||||||
.append(optionService.getJournalsPrefix());
|
|
||||||
|
|
||||||
fullPath.append("/page/");
|
|
||||||
|
|
||||||
for (int current : rainbow) {
|
|
||||||
RainbowPage rainbowPage = new RainbowPage();
|
|
||||||
rainbowPage.setPage(current);
|
|
||||||
rainbowPage.setFullPath(fullPath.toString() + current + optionService.getPathSuffix());
|
|
||||||
rainbowPage.setIsCurrent(page + 1 == current);
|
|
||||||
rainbowPages.add(rainbowPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setRainbowPages(rainbowPages);
|
|
||||||
pagination.setHasNext(total != page + 1);
|
|
||||||
pagination.setHasPrev(page != 0);
|
|
||||||
env.setVariable("pagination", builder.build().wrap(pagination));
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,317 @@
|
||||||
|
package run.halo.app.core.freemarker.tag;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.PageUtil;
|
||||||
|
import freemarker.core.Environment;
|
||||||
|
import freemarker.template.*;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import run.halo.app.model.support.HaloConst;
|
||||||
|
import run.halo.app.model.support.Pagination;
|
||||||
|
import run.halo.app.model.support.RainbowPage;
|
||||||
|
import run.halo.app.service.OptionService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ryanwang
|
||||||
|
* @date 2020-03-07
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PaginationTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
|
private final OptionService optionService;
|
||||||
|
|
||||||
|
public PaginationTagDirective(Configuration configuration,
|
||||||
|
OptionService optionService) {
|
||||||
|
this.optionService = optionService;
|
||||||
|
configuration.setSharedVariable("paginationTag", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
|
||||||
|
final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
|
||||||
|
if (params.containsKey(HaloConst.METHOD_KEY)) {
|
||||||
|
|
||||||
|
// Get params
|
||||||
|
String method = params.get(HaloConst.METHOD_KEY).toString();
|
||||||
|
int page = Integer.parseInt(params.get("page").toString());
|
||||||
|
int total = Integer.parseInt(params.get("total").toString());
|
||||||
|
int display = Integer.parseInt(params.get("display").toString());
|
||||||
|
|
||||||
|
// Create pagination object.
|
||||||
|
Pagination pagination = new Pagination();
|
||||||
|
|
||||||
|
// Generate next page full path and pre page full path.
|
||||||
|
StringBuilder nextPageFullPath = new StringBuilder();
|
||||||
|
StringBuilder prevPageFullPath = new StringBuilder();
|
||||||
|
|
||||||
|
if (optionService.isEnabledAbsolutePath()) {
|
||||||
|
nextPageFullPath.append(optionService.getBlogBaseUrl());
|
||||||
|
prevPageFullPath.append(optionService.getBlogBaseUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
||||||
|
|
||||||
|
List<RainbowPage> rainbowPages = new ArrayList<>();
|
||||||
|
StringBuilder fullPath = new StringBuilder();
|
||||||
|
|
||||||
|
if (optionService.isEnabledAbsolutePath()) {
|
||||||
|
fullPath.append(optionService.getBlogBaseUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
String pathSuffix = optionService.getPathSuffix();
|
||||||
|
|
||||||
|
switch (method) {
|
||||||
|
case "index":
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append("/");
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "archives":
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append(optionService.getArchivesPrefix());
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append(optionService.getArchivesPrefix());
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.
|
||||||
|
append(pathSuffix);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append(optionService.getArchivesPrefix());
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "search":
|
||||||
|
String keyword = params.get("keyword").toString();
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append("search");
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append("search");
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix)
|
||||||
|
.append("?keyword=")
|
||||||
|
.append(keyword);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append(pathSuffix)
|
||||||
|
.append("?keyword=")
|
||||||
|
.append(keyword);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix)
|
||||||
|
.append("?keyword=")
|
||||||
|
.append(keyword);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append("search");
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix + "?keyword=" + keyword);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "tagPosts":
|
||||||
|
String tagSlug = params.get("slug").toString();
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append(optionService.getTagsPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(tagSlug);
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append(optionService.getTagsPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(tagSlug);
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append(pathSuffix);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append(optionService.getTagsPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(tagSlug);
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "categoryPosts":
|
||||||
|
String categorySlug = params.get("slug").toString();
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append(optionService.getCategoriesPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(categorySlug);
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append(optionService.getCategoriesPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(categorySlug);
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append(pathSuffix);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append(optionService.getCategoriesPrefix())
|
||||||
|
.append("/")
|
||||||
|
.append(categorySlug);
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "photos":
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append(optionService.getPhotosPrefix());
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append(optionService.getPhotosPrefix());
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append(pathSuffix);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append(optionService.getPhotosPrefix());
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "journals":
|
||||||
|
|
||||||
|
nextPageFullPath.append("/")
|
||||||
|
.append(optionService.getJournalsPrefix());
|
||||||
|
prevPageFullPath.append("/")
|
||||||
|
.append(optionService.getJournalsPrefix());
|
||||||
|
|
||||||
|
nextPageFullPath.append("/page/")
|
||||||
|
.append(page + 2)
|
||||||
|
.append(pathSuffix);
|
||||||
|
|
||||||
|
if (page == 1) {
|
||||||
|
prevPageFullPath.append(pathSuffix);
|
||||||
|
} else {
|
||||||
|
prevPageFullPath.append("/page/")
|
||||||
|
.append(page)
|
||||||
|
.append(pathSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
fullPath.append("/")
|
||||||
|
.append(optionService.getJournalsPrefix());
|
||||||
|
|
||||||
|
fullPath.append("/page/");
|
||||||
|
|
||||||
|
for (int current : rainbow) {
|
||||||
|
RainbowPage rainbowPage = new RainbowPage();
|
||||||
|
rainbowPage.setPage(current);
|
||||||
|
rainbowPage.setFullPath(fullPath.toString() + current + pathSuffix);
|
||||||
|
rainbowPage.setIsCurrent(page + 1 == current);
|
||||||
|
rainbowPages.add(rainbowPage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
||||||
|
pagination.setPrevPageFullPath(prevPageFullPath.toString());
|
||||||
|
pagination.setRainbowPages(rainbowPages);
|
||||||
|
pagination.setHasNext(total != page + 1);
|
||||||
|
pagination.setHasPrev(page != 0);
|
||||||
|
env.setVariable("pagination", builder.build().wrap(pagination));
|
||||||
|
}
|
||||||
|
body.render(env.getOut());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +1,13 @@
|
||||||
package run.halo.app.core.freemarker.tag;
|
package run.halo.app.core.freemarker.tag;
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.support.Pagination;
|
|
||||||
import run.halo.app.model.support.RainbowPage;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.service.PhotoService;
|
import run.halo.app.service.PhotoService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||||
|
@ -29,11 +23,8 @@ public class PhotoTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private final PhotoService photoService;
|
private final PhotoService photoService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
public PhotoTagDirective(Configuration configuration, PhotoService photoService) {
|
||||||
|
|
||||||
public PhotoTagDirective(Configuration configuration, PhotoService photoService, OptionService optionService) {
|
|
||||||
this.photoService = photoService;
|
this.photoService = photoService;
|
||||||
this.optionService = optionService;
|
|
||||||
configuration.setSharedVariable("photoTag", this);
|
configuration.setSharedVariable("photoTag", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,75 +48,6 @@ public class PhotoTagDirective implements TemplateDirectiveModel {
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(photoService.count()));
|
env.setVariable("count", builder.build().wrap(photoService.count()));
|
||||||
break;
|
break;
|
||||||
case "pagination":
|
|
||||||
// Get params
|
|
||||||
int page = Integer.parseInt(params.get("page").toString());
|
|
||||||
int total = Integer.parseInt(params.get("total").toString());
|
|
||||||
int display = Integer.parseInt(params.get("display").toString());
|
|
||||||
String slug = params.get("slug").toString();
|
|
||||||
|
|
||||||
// Create pagination object.
|
|
||||||
Pagination pagination = new Pagination();
|
|
||||||
|
|
||||||
// Generate next page full path and pre page full path.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
} else {
|
|
||||||
nextPageFullPath.append("/");
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append(optionService.getPhotosPrefix());
|
|
||||||
prePageFullPath.append(optionService.getPhotosPrefix());
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(page + 2)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
prePageFullPath.append(optionService.getPathSuffix());
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(page)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
|
||||||
pagination.setPrePageFullPath(prePageFullPath.toString());
|
|
||||||
|
|
||||||
// Generate rainbow page number.
|
|
||||||
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
|
||||||
|
|
||||||
List<RainbowPage> rainbowPages = new ArrayList<>();
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
|
||||||
.append(optionService.getPhotosPrefix());
|
|
||||||
|
|
||||||
fullPath.append("/page/");
|
|
||||||
|
|
||||||
for (int current : rainbow) {
|
|
||||||
RainbowPage rainbowPage = new RainbowPage();
|
|
||||||
rainbowPage.setPage(current);
|
|
||||||
rainbowPage.setFullPath(fullPath.toString() + current + optionService.getPathSuffix());
|
|
||||||
rainbowPage.setIsCurrent(page + 1 == current);
|
|
||||||
rainbowPages.add(rainbowPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setRainbowPages(rainbowPages);
|
|
||||||
pagination.setHasNext(total != page + 1);
|
|
||||||
pagination.setHasPrev(page != 0);
|
|
||||||
env.setVariable("pagination", builder.build().wrap(pagination));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,16 @@
|
||||||
package run.halo.app.core.freemarker.tag;
|
package run.halo.app.core.freemarker.tag;
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.entity.Post;
|
import run.halo.app.model.entity.Post;
|
||||||
import run.halo.app.model.enums.PostStatus;
|
import run.halo.app.model.enums.PostStatus;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.support.Pagination;
|
|
||||||
import run.halo.app.model.support.RainbowPage;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.service.PostCategoryService;
|
import run.halo.app.service.PostCategoryService;
|
||||||
import run.halo.app.service.PostService;
|
import run.halo.app.service.PostService;
|
||||||
import run.halo.app.service.PostTagService;
|
import run.halo.app.service.PostTagService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -30,19 +25,15 @@ public class PostTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private final PostService postService;
|
private final PostService postService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
|
||||||
|
|
||||||
private final PostTagService postTagService;
|
private final PostTagService postTagService;
|
||||||
|
|
||||||
private final PostCategoryService postCategoryService;
|
private final PostCategoryService postCategoryService;
|
||||||
|
|
||||||
public PostTagDirective(Configuration configuration,
|
public PostTagDirective(Configuration configuration,
|
||||||
PostService postService,
|
PostService postService,
|
||||||
OptionService optionService,
|
|
||||||
PostTagService postTagService,
|
PostTagService postTagService,
|
||||||
PostCategoryService postCategoryService) {
|
PostCategoryService postCategoryService) {
|
||||||
this.postService = postService;
|
this.postService = postService;
|
||||||
this.optionService = optionService;
|
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
this.postCategoryService = postCategoryService;
|
this.postCategoryService = postCategoryService;
|
||||||
configuration.setSharedVariable("postTag", this);
|
configuration.setSharedVariable("postTag", this);
|
||||||
|
@ -88,77 +79,6 @@ public class PostTagDirective implements TemplateDirectiveModel {
|
||||||
String tagSlug = params.get("tagSlug").toString();
|
String tagSlug = params.get("tagSlug").toString();
|
||||||
env.setVariable("posts", builder.build().wrap(postService.convertToListVo(postTagService.listPostsBy(tagSlug, PostStatus.PUBLISHED))));
|
env.setVariable("posts", builder.build().wrap(postService.convertToListVo(postTagService.listPostsBy(tagSlug, PostStatus.PUBLISHED))));
|
||||||
break;
|
break;
|
||||||
case "pagination":
|
|
||||||
|
|
||||||
// Get params
|
|
||||||
int page = Integer.parseInt(params.get("page").toString());
|
|
||||||
int total = Integer.parseInt(params.get("total").toString());
|
|
||||||
int display = Integer.parseInt(params.get("display").toString());
|
|
||||||
boolean isArchives = Boolean.parseBoolean(params.get("isArchives").toString());
|
|
||||||
|
|
||||||
// Create pagination object.
|
|
||||||
Pagination pagination = new Pagination();
|
|
||||||
|
|
||||||
// Generate next page full path and pre page full path.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isArchives) {
|
|
||||||
nextPageFullPath.append("/")
|
|
||||||
.append(optionService.getArchivesPrefix());
|
|
||||||
prePageFullPath.append("/")
|
|
||||||
.append(optionService.getArchivesPrefix());
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(page + 2)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(page)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
|
||||||
pagination.setPrePageFullPath(prePageFullPath.toString());
|
|
||||||
|
|
||||||
// Generate rainbow page number.
|
|
||||||
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
|
||||||
|
|
||||||
List<RainbowPage> rainbowPages = new ArrayList<>();
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isArchives) {
|
|
||||||
fullPath.append("/")
|
|
||||||
.append(optionService.getArchivesPrefix());
|
|
||||||
}
|
|
||||||
|
|
||||||
fullPath.append("/page/");
|
|
||||||
|
|
||||||
for (int current : rainbow) {
|
|
||||||
RainbowPage rainbowPage = new RainbowPage();
|
|
||||||
rainbowPage.setPage(current);
|
|
||||||
rainbowPage.setFullPath(fullPath.toString() + current + optionService.getPathSuffix());
|
|
||||||
rainbowPage.setIsCurrent(page + 1 == current);
|
|
||||||
rainbowPages.add(rainbowPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setRainbowPages(rainbowPages);
|
|
||||||
pagination.setHasNext(total != page + 1);
|
|
||||||
pagination.setHasPrev(page != 0);
|
|
||||||
env.setVariable("pagination", builder.build().wrap(pagination));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
package run.halo.app.core.freemarker.tag;
|
package run.halo.app.core.freemarker.tag;
|
||||||
|
|
||||||
import cn.hutool.core.util.PageUtil;
|
|
||||||
import freemarker.core.Environment;
|
import freemarker.core.Environment;
|
||||||
import freemarker.template.*;
|
import freemarker.template.*;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import run.halo.app.model.entity.Tag;
|
import run.halo.app.model.entity.Tag;
|
||||||
import run.halo.app.model.support.HaloConst;
|
import run.halo.app.model.support.HaloConst;
|
||||||
import run.halo.app.model.support.Pagination;
|
|
||||||
import run.halo.app.model.support.RainbowPage;
|
|
||||||
import run.halo.app.service.OptionService;
|
|
||||||
import run.halo.app.service.PostTagService;
|
import run.halo.app.service.PostTagService;
|
||||||
import run.halo.app.service.TagService;
|
import run.halo.app.service.TagService;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -33,15 +28,11 @@ public class TagTagDirective implements TemplateDirectiveModel {
|
||||||
|
|
||||||
private final PostTagService postTagService;
|
private final PostTagService postTagService;
|
||||||
|
|
||||||
private final OptionService optionService;
|
|
||||||
|
|
||||||
public TagTagDirective(Configuration configuration,
|
public TagTagDirective(Configuration configuration,
|
||||||
TagService tagService,
|
TagService tagService,
|
||||||
PostTagService postTagService,
|
PostTagService postTagService) {
|
||||||
OptionService optionService) {
|
|
||||||
this.tagService = tagService;
|
this.tagService = tagService;
|
||||||
this.postTagService = postTagService;
|
this.postTagService = postTagService;
|
||||||
this.optionService = optionService;
|
|
||||||
configuration.setSharedVariable("tagTag", this);
|
configuration.setSharedVariable("tagTag", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,81 +54,6 @@ public class TagTagDirective implements TemplateDirectiveModel {
|
||||||
case "count":
|
case "count":
|
||||||
env.setVariable("count", builder.build().wrap(tagService.count()));
|
env.setVariable("count", builder.build().wrap(tagService.count()));
|
||||||
break;
|
break;
|
||||||
case "pagination":
|
|
||||||
// Get params
|
|
||||||
int page = Integer.parseInt(params.get("page").toString());
|
|
||||||
int total = Integer.parseInt(params.get("total").toString());
|
|
||||||
int display = Integer.parseInt(params.get("display").toString());
|
|
||||||
String slug = params.get("slug").toString();
|
|
||||||
|
|
||||||
// Create pagination object.
|
|
||||||
Pagination pagination = new Pagination();
|
|
||||||
|
|
||||||
// Generate next page full path and pre page full path.
|
|
||||||
StringBuilder nextPageFullPath = new StringBuilder();
|
|
||||||
StringBuilder prePageFullPath = new StringBuilder();
|
|
||||||
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
nextPageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
prePageFullPath.append(optionService.getBlogBaseUrl())
|
|
||||||
.append("/");
|
|
||||||
} else {
|
|
||||||
nextPageFullPath.append("/");
|
|
||||||
prePageFullPath.append("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append(optionService.getTagsPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
prePageFullPath.append(optionService.getTagsPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
|
|
||||||
nextPageFullPath.append("/page/")
|
|
||||||
.append(page + 2)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
|
|
||||||
if (page == 1) {
|
|
||||||
prePageFullPath.append(optionService.getPathSuffix());
|
|
||||||
} else {
|
|
||||||
prePageFullPath.append("/page/")
|
|
||||||
.append(page)
|
|
||||||
.append(optionService.getPathSuffix());
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setNextPageFullPath(nextPageFullPath.toString());
|
|
||||||
pagination.setPrePageFullPath(prePageFullPath.toString());
|
|
||||||
|
|
||||||
// Generate rainbow page number.
|
|
||||||
int[] rainbow = PageUtil.rainbow(page + 1, total, display);
|
|
||||||
|
|
||||||
List<RainbowPage> rainbowPages = new ArrayList<>();
|
|
||||||
StringBuilder fullPath = new StringBuilder();
|
|
||||||
if (optionService.isEnabledAbsolutePath()) {
|
|
||||||
fullPath.append(optionService.getBlogBaseUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
nextPageFullPath.append("/")
|
|
||||||
.append(optionService.getTagsPrefix())
|
|
||||||
.append("/")
|
|
||||||
.append(slug);
|
|
||||||
|
|
||||||
fullPath.append("/page/");
|
|
||||||
|
|
||||||
for (int current : rainbow) {
|
|
||||||
RainbowPage rainbowPage = new RainbowPage();
|
|
||||||
rainbowPage.setPage(current);
|
|
||||||
rainbowPage.setFullPath(fullPath.toString() + current + optionService.getPathSuffix());
|
|
||||||
rainbowPage.setIsCurrent(page + 1 == current);
|
|
||||||
rainbowPages.add(rainbowPage);
|
|
||||||
}
|
|
||||||
|
|
||||||
pagination.setRainbowPages(rainbowPages);
|
|
||||||
pagination.setHasNext(total != page + 1);
|
|
||||||
pagination.setHasPrev(page != 0);
|
|
||||||
env.setVariable("pagination", builder.build().wrap(pagination));
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class Pagination {
|
||||||
|
|
||||||
private String nextPageFullPath;
|
private String nextPageFullPath;
|
||||||
|
|
||||||
private String prePageFullPath;
|
private String prevPageFullPath;
|
||||||
|
|
||||||
private Boolean hasPrev;
|
private Boolean hasPrev;
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,11 @@ import java.util.Optional;
|
||||||
@Builder
|
@Builder
|
||||||
public class AdjacentPostVO {
|
public class AdjacentPostVO {
|
||||||
|
|
||||||
private Post prePost;
|
private Post prevPost;
|
||||||
private Post nextPost;
|
private Post nextPost;
|
||||||
|
|
||||||
public Optional<Post> getOptionalPrePost() {
|
public Optional<Post> getOptionalPrevPost() {
|
||||||
return Optional.ofNullable(this.getPrePost());
|
return Optional.ofNullable(this.getPrevPost());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Post> getOptionalNextPost() {
|
public Optional<Post> getOptionalNextPost() {
|
||||||
|
|
|
@ -257,8 +257,8 @@ public interface PostService extends BasePostService<Post> {
|
||||||
* Gets pre && next post.
|
* Gets pre && next post.
|
||||||
*
|
*
|
||||||
* @param currentPost post must not be null
|
* @param currentPost post must not be null
|
||||||
* @return AdjacentPostVO. it contains prePost and nextPost.
|
* @return AdjacentPostVO. it contains prevPost and nextPost.
|
||||||
* AdjacentPostVO will not be null. But prePost and nextPost may be null.
|
* AdjacentPostVO will not be null. But prevPost and nextPost may be null.
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
AdjacentPostVO getAdjacentPosts(Post currentPost);
|
AdjacentPostVO getAdjacentPosts(Post currentPost);
|
||||||
|
|
|
@ -91,7 +91,7 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
||||||
* @return a list of previous post
|
* @return a list of previous post
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
List<POST> listPrePosts(@NonNull Date date, int size);
|
List<POST> listPrevPosts(@NonNull Date date, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lits next posts.
|
* Lits next posts.
|
||||||
|
@ -110,7 +110,7 @@ public interface BasePostService<POST extends BasePost> extends CrudService<POST
|
||||||
* @return an optional post
|
* @return an optional post
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Optional<POST> getPrePost(@NonNull Date date);
|
Optional<POST> getPrevPost(@NonNull Date date);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets next post.
|
* Gets next post.
|
||||||
|
|
|
@ -114,7 +114,7 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<POST> listPrePosts(Date date, int size) {
|
public List<POST> listPrevPosts(Date date, int size) {
|
||||||
Assert.notNull(date, "Date must not be null");
|
Assert.notNull(date, "Date must not be null");
|
||||||
|
|
||||||
return basePostRepository.findAllByStatusAndCreateTimeAfter(PostStatus.PUBLISHED,
|
return basePostRepository.findAllByStatusAndCreateTimeAfter(PostStatus.PUBLISHED,
|
||||||
|
@ -134,8 +134,8 @@ public abstract class BasePostServiceImpl<POST extends BasePost> extends Abstrac
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<POST> getPrePost(Date date) {
|
public Optional<POST> getPrevPost(Date date) {
|
||||||
List<POST> posts = listPrePosts(date, 1);
|
List<POST> posts = listPrevPosts(date, 1);
|
||||||
|
|
||||||
return CollectionUtils.isEmpty(posts) ? Optional.empty() : Optional.of(posts.get(0));
|
return CollectionUtils.isEmpty(posts) ? Optional.empty() : Optional.of(posts.get(0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -853,7 +853,7 @@ public class PostServiceImpl extends BasePostServiceImpl<Post> implements PostSe
|
||||||
|
|
||||||
// setup pre
|
// setup pre
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
adjacentPostVO.setPrePost(postList.get(index - 1));
|
adjacentPostVO.setPrevPost(postList.get(index - 1));
|
||||||
}
|
}
|
||||||
// setup next
|
// setup next
|
||||||
if (index < postList.size() - 1) {
|
if (index < postList.size() - 1) {
|
||||||
|
|
|
@ -332,7 +332,7 @@ public class StaticPageServiceImpl implements StaticPageService {
|
||||||
ModelMap model = new ModelMap();
|
ModelMap model = new ModelMap();
|
||||||
|
|
||||||
AdjacentPostVO adjacentPostVO = postService.getAdjacentPosts(post);
|
AdjacentPostVO adjacentPostVO = postService.getAdjacentPosts(post);
|
||||||
adjacentPostVO.getOptionalPrePost().ifPresent(prePost -> model.addAttribute("prePost", prePost));
|
adjacentPostVO.getOptionalPrevPost().ifPresent(prevPost -> model.addAttribute("prevPost", prevPost));
|
||||||
adjacentPostVO.getOptionalNextPost().ifPresent(nextPost -> model.addAttribute("nextPost", nextPost));
|
adjacentPostVO.getOptionalNextPost().ifPresent(nextPost -> model.addAttribute("nextPost", nextPost));
|
||||||
|
|
||||||
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
|
List<Category> categories = postCategoryService.listCategoriesBy(post.getId());
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit b1701a85685413c0b3ace8cab21bfe49ffb658bf
|
Subproject commit c0309ef9c8607cddab14ce6005168cb7b19ef066
|
Loading…
Reference in New Issue