Merge pull request #95 from AirboZH/main

feat: 归档页以及分页
This commit is contained in:
sunheyi 2023-02-10 15:22:49 +08:00 committed by GitHub
commit 68b261dd1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 127 additions and 111 deletions

61
templates/archives.html Normal file
View File

@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="en" th:replace="modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'archive')"
xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="content">
<div class="page" id="body-wrap">
<header class="not-top-img" id="page-header">
<nav th:replace="modules/nav :: nav"></nav>
</header>
<main class="layout" id="content-inner">
<!-- archive -->
<div id="archive">
<div class="article-sort-title">文章 - [[${siteStatsFinder.getStats().post}]]</div>
<div class="article-sort" th:each="archive : ${archives.items}"
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
<div class="article-sort-item year" th:text="${archive.year}"></div>
<div class="article-sort" th:each="month : ${archive.months}">
<!-- 月份没有样式所以不显示 -->
<!-- <div class="article-sort-item" th:text="${month.month}"></div> -->
<div class="article-sort-item" th:each="post : ${month.posts}">
<a class="article-sort-item-img" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}">
<img th:alt="${post.spec.title}"
th:src="${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}">
</a>
<div class="article-sort-item-info">
<div class="article-sort-item-time"><i class="far fa-calendar-alt"></i>
<time class="post-meta-date-created"
th:attr="datetime=${#dates.format(post.spec.publishTime,'yyyy-MM-dd HH:mm:ss')}"
th:text="${#dates.format(post.spec.publishTime,'yyyy-MM-dd')}"
th:title="'创建于' + ${#dates.format(post.spec.publishTime,'yyyy-MM-dd HH:mm:ss')}">
</time>
</div>
<a class="article-sort-item-title" onclick="window.event.cancelBubble=!0"
th:href="@{${post.status.permalink}}" th:text="${post.spec.title}"
th:title="${post.spec.title}"></a>
<div class="article-sort-item-tags">
<a class="article-meta__tags"
th:each="tag : ${post.tags}" th:href="@{${tag.status.permalink}}">
<span class="tags-punctuation">#</span>[[${tag.spec.displayName}]]
</a>
<span class="article-meta__link"></span>
</div>
</div>
</div>
</div>
</div>
<!-- 分页 -->
<div th:replace="modules/widgets/page :: page('/archives',${archives})"></div>
</div>
<!-- sidebar -->
<div th:replace="modules/aside :: aside(${theme.config.sidebar.categoryWidgets})"></div>
</main>
<!-- 底部 -->
<footer th:replace="modules/footer :: footer"></footer>
</div>
</th:block>
</html>

View File

@ -313,16 +313,16 @@ template {
white-space: nowrap; white-space: nowrap;
} }
#aside-content .aside-list > .aside-list-item .content > .comment, /*#aside-content .aside-list > .aside-list-item .content > .comment,*/
#aside-content .aside-list > .aside-list-item .content > .name, /*#aside-content .aside-list > .aside-list-item .content > .name,*/
#aside-content .aside-list > .aside-list-item .content > .title, /*#aside-content .aside-list > .aside-list-item .content > .title,*/
#error-wrap .error-content .error-info .error_subtitle, /*#error-wrap .error-content .error-info .error_subtitle,*/
#post-info .post-title, /*#post-info .post-title,*/
#recent-posts > .recent-post-item > .recent-post-info > .article-title, /*#recent-posts > .recent-post-item > .recent-post-info > .article-title,*/
#recent-posts > .recent-post-item > .recent-post-info > .content, /*#recent-posts > .recent-post-item > .recent-post-info > .content,*/
.article-sort-item-title, /*.article-sort-item-title,*/
.limit-more-line, /*.limit-more-line,*/
.relatedPosts > .relatedPosts-list .content .title, /*.relatedPosts > .relatedPosts-list .content .title,*/
/*figure.gallery-group .gallery-group-name,*/ /*figure.gallery-group .gallery-group-name,*/
/*figure.gallery-group p {*/ /*figure.gallery-group p {*/
/* display: -webkit-box;*/ /* display: -webkit-box;*/

View File

@ -62,10 +62,9 @@
</div> </div>
</div> </div>
<!-- 分页 --> <!-- 分页 -->
<nav id="pagination"> <div th:replace="modules/widgets/page :: page(${'/categories/'+category.spec.slug},${posts})"></div>
<div class="pagination"><span class="page-number current">1</span></div>
</nav>
</div> </div>
<!-- sidebar -->
<div th:replace="modules/aside :: aside(${theme.config.sidebar.categoryWidgets})"></div> <div th:replace="modules/aside :: aside(${theme.config.sidebar.categoryWidgets})"></div>
</main> </main>

View File

@ -30,6 +30,8 @@
rel="stylesheet" rel="stylesheet"
/> />
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.2.0/css/all.min.css" media="all" onload="this.media='all'">
<script> <script>
(win => { (win => {
win.saveToLocal = { win.saveToLocal = {

View File

@ -80,102 +80,11 @@
</time> </time>
</span> </span>
</div> </div>
</div> </div>
</div> </div>
<!-- 分页 -->
<nav id="pagination" th:if="${posts.hasPrevious() || posts.hasNext()}" <div th:replace="modules/widgets/page :: page('',${posts})"></div>
th:with="totalPages = ${posts.totalPages}, pageIndex = ${posts.page}">
<!-- 页面小于 7 -->
<div class="pagination" th:if="${(totalPages le 7) && (totalPages gt 0)}">
<!-- 上一页 -->
<a class="extend prev" rel="prev" th:href="@{${posts.prevUrl}}" th:if="${posts.hasPrevious()}">
<i class="iconfont icon-chevron-left"></i>
<div class="pagination_tips_prev">上页</div>
</a>
<a class="page-number"
th:classappend="${index eq pageIndex} ? 'current'"
th:each="index : ${#numbers.sequence(1, totalPages)}"
th:href="@{'/page/' + ${index}}"
th:text="${index}">
</a>
<!-- 下一页 -->
<a class="extend next" rel="next" th:href="@{${posts.nextUrl}}" th:if="${posts.hasNext()}">
<div class="pagination_tips_next">下页</div>
<i class="iconfont icon-chevron-right"></i>
</a>
</div>
<!-- 页面大于 7 -->
<!-- https://blog.csdn.net/lizc_lizc/article/details/80215147 -->
<div class="pagination" th:if="${totalPages gt 7}">
<!-- 上一页 -->
<a class="extend prev" rel="prev" th:href="@{${posts.prevUrl}}" th:if="${posts.hasPrevious()}">
<i class="iconfont icon-chevron-left"></i>
<div class="pagination_tips_prev">上页</div>
</a>
<!-- 首页 -->
<a class="page-number" href="/">1</a>
<!-- 当前页面小于等于4 -->
<a class="page-number"
th:classappend="${index eq pageIndex} ? 'current'"
th:each="index : ${#numbers.sequence(2,5)}"
th:href="@{'/page/' + ${index}}"
th:if="${pageIndex le 4}"
th:text="${index}">
</a>
<a class="page-number" th:if="${pageIndex le 4}">...</a>
<!-- 最后一页与当前页面之差小于等于3 -->
<a class="page-number" th:if="${totalPages - pageIndex le 3}">...</a>
<a class="page-number"
th:classappend="${index eq pageIndex} ? 'current'"
th:each="index : ${#numbers.sequence(totalPages - 4, totalPages - 1)}"
th:href="@{'/page/' + ${index}}"
th:if="${totalPages - pageIndex le 3}"
th:text="${index}">
</a>
<!-- 最后一页与当前页面之差大于3 且当前页面大于4 -->
<a class="page-number" th:if="${(pageIndex gt 4) && (totalPages - pageIndex gt 3)}">...</a>
<a class="page-number"
th:each="index : ${#numbers.sequence(pageIndex - 1,pageIndex + 1)}"
th:href="@{'/page/' + ${index}}"
th:if="${(pageIndex gt 4) && (totalPages - pageIndex gt 3)}"
th:text="${index}">
</a>
<!-- 需要添加 th:href 跳转地址 -->
<a class="page-number" th:if="${(pageIndex gt 4) && (totalPages - pageIndex gt 3)}">...</a>
<!-- 尾页 -->
<!-- 需要添加 th:href 跳转地址 -->
<a class="page-number"
th:classappend="${index eq pageIndex} ? 'current'"
th:text="${totalPages}">
</a>
<!-- 下一页 -->
<a class="extend next" rel="next" th:href="@{${posts.nextUrl}}" th:if="${posts.hasNext()}">
<div class="pagination_tips_next">下页</div>
<i class="iconfont icon-chevron-right"></i>
</a>
</div>
</nav>
</th:block> </th:block>

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--
分页模块
@param path '/path/page/n' 中的 `/path` 需要保留 `/`
@param pageInfo Halo类型UrlContextListResult<ListedPostVo>
-->
<nav id="pagination" th:fragment="page(path,pageInfo)">
<div class="pagination">
<!-- 页码按钮 -->
<th:block th:if="${pageInfo.page > 3}">
<a class="page-number" th:href="${path+'/page/1'}" th:text="1"></a>
<span class="space" th:if="${pageInfo.page != 4}"></span>
</th:block>
<th:block th:each="index:${#numbers.sequence(pageInfo.page-2,pageInfo.page+2)}">
<span class="page-number current" th:if="${pageInfo.page} == ${index}" th:text="${pageInfo.page}"></span>
<a class="page-number" th:unless="${pageInfo.page == index}" th:if="${index > 0 && index <= pageInfo.totalPages}"
th:href="${path+'/page/'+index}" th:text="${index}"></a>
</th:block>
<th:block th:if="${pageInfo.totalPages - pageInfo.page > 2}">
<span class="space" th:if="${pageInfo.totalPages - pageInfo.page != 3}"></span>
<a class="page-number" th:href="${path+'/page/'+pageInfo.totalPages}" th:text="${pageInfo.totalPages}"></a>
</th:block>
<!-- 翻页按钮 -->
<a class="extend prev" rel="prev" th:if="${pageInfo.hasPrevious}" th:href="${pageInfo.prevUrl}" data-pjax-state="">
<i class="fas fa-chevron-left fa-fw"></i>
<div class="pagination_tips_prev">上页</div>
</a>
<a class="extend next" rel="next" th:if="${pageInfo.hasNext}" th:href="${pageInfo.nextUrl}" data-pjax-state="">
<div class="pagination_tips_next">下页</div>
<i class="fas fa-chevron-right fa-fw"></i>
</a>
</div>
</nav>
</html>

View File

@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" th:replace="modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'tag')" xmlns:th="http://www.thymeleaf.org"> <html lang="en" th:replace="modules/layouts/layout :: layout(content = ~{::content}, htmlType = 'tag')"
xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="content"> <th:block th:fragment="content">
@ -26,7 +27,8 @@
th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'> th:with='postRandomImg=${#strings.contains(theme.config.layout.postRandomImg,"?") ? theme.config.layout.postRandomImg+"," : theme.config.layout.postRandomImg+"?"}'>
<a class="article-sort-item-img" th:href="@{${post.status.permalink}}" <a class="article-sort-item-img" th:href="@{${post.status.permalink}}"
th:title="${post.spec.title}"> th:title="${post.spec.title}">
<img loading="lazy" th:alt="${post.status.excerpt}" th:src="${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}"> <img loading="lazy" th:alt="${post.status.excerpt}"
th:src="${#strings.isEmpty(post.spec.cover) ? postRandomImg+post.spec.title : post.spec.cover}">
</a> </a>
<div class="article-sort-item-info"> <div class="article-sort-item-info">
<div class="article-sort-item-time"><i class="far fa-calendar-alt"></i> <div class="article-sort-item-time"><i class="far fa-calendar-alt"></i>
@ -48,10 +50,10 @@
</div> </div>
</div> </div>
</div> </div>
<nav id="pagination"> <!-- 分页 -->
<div class="pagination"><span class="page-number current">1</span></div> <div th:replace="modules/widgets/page :: page(${'/tags/'+tag.spec.slug},${posts})"></div>
</nav>
</div> </div>
<!-- sidebar -->
<div th:replace="modules/aside :: aside(${theme.config.sidebar.tagWidgets})"></div> <div th:replace="modules/aside :: aside(${theme.config.sidebar.tagWidgets})"></div>
</main> </main>