Skip to content

Commit

Permalink
Merge pull request #258 from teahouse15/master
Browse files Browse the repository at this point in the history
修复主页或后台没有文章时500的漏洞
  • Loading branch information
teahouse15 authored Sep 13, 2024
2 parents 7e6f17b + 47ade46 commit 40fd6d4
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 43 deletions.
3 changes: 1 addition & 2 deletions src/main/java/org/b3log/solo/service/DataModelService.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void fillIndexArticles(final RequestContext context, final Map<String, Ob
setArticlesExProperties(context, articles, preference);

final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
if (0 != pageNums.size()) {
if (!pageNums.isEmpty()) {
dataModel.put(Pagination.PAGINATION_FIRST_PAGE_NUM, pageNums.get(0));
dataModel.put(Pagination.PAGINATION_LAST_PAGE_NUM, pageNums.get(pageNums.size() - 1));
}
Expand Down Expand Up @@ -784,7 +784,6 @@ public void fillCharts(final RequestContext context, final Map<String, Object> d
if (archiveDates3.size() > 20) {
archiveDates3 = archiveDates3.subList(0, 20);
}

dataModel.put("latestArchives", archiveDates3);
} catch (Exception ignored) {
}
Expand Down
32 changes: 20 additions & 12 deletions src/main/webapp/admin/admin-index.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,11 @@
<script type="text/javascript">
var data1 = {
labels: [
<#list latestArchives?reverse as archiveDate>
"${archiveDate.archiveDateYear}/${archiveDate.archiveDateMonth}",
</#list>
<#if latestArchives?exists && (latestArchives?size > 0)>
<#list latestArchives?reverse as archiveDate>
"${archiveDate.archiveDateYear}/${archiveDate.archiveDateMonth}",
</#list>
</#if>
],
datasets: [{
label: '文章数量',
Expand All @@ -203,9 +205,11 @@
pointBackgroundColor: "#36A2EB",
pointBorderColor: "#fff",
data: [
<#list latestArchives?reverse as archiveDate>
${archiveDate.archiveDatePublishedArticleCount},
</#list>
<#if latestArchives?exists && (latestArchives?size > 0)>
<#list latestArchives?reverse as archiveDate>
${archiveDate.archiveDatePublishedArticleCount},
</#list>
</#if>
],
}]
};
Expand All @@ -214,9 +218,11 @@
datasets: [
{
data: [
<#list tagsTop5 as tag>
${tag.tagPublishedRefCount},
</#list>
<#if tagsTop5?exists && (tagsTop5?size > 0)>
<#list tagsTop5 as tag>
${tag.tagPublishedRefCount},
</#list>
</#if>
],
backgroundColor: [
'rgb(254,67,101)',
Expand All @@ -229,9 +235,11 @@
],
labels: [
<#list tagsTop5 as tag>
"${tag.tagTitle}",
</#list>
<#if tagsTop5?exists && (tagsTop5?size > 0)>
<#list tagsTop5 as tag>
"${tag.tagTitle}",
</#list>
</#if>
]
};
</script>
Expand Down
6 changes: 3 additions & 3 deletions src/main/webapp/admin/admin-main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
labels: [
<#list categories as category>
<#if category.categoryPublishedArticleCount != 0>
"${category.categoryTitle}",
</#if>
<#if category.categoryPublishedArticleCount != 0>
"${category.categoryTitle}",
</#if>
</#list>
]
};
Expand Down
54 changes: 28 additions & 26 deletions src/main/webapp/skins/bolo-fantastic/article-list.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -117,34 +117,36 @@


<div class="card card-transparent">

<nav class="pagination is-centered" role="navigation" aria-label="pagination">
<#if paginationCurrentPageNum !=paginationFirstPageNum>

<div class="pagination-previous">
<a class="is-flex-grow has-text-black-ter"
href="${servePath}${path}?p=${paginationPreviousPageNum}">上一页</a>
</div>
</#if>
<#if paginationCurrentPageNum !=paginationLastPageNum>
<div class="pagination-next">
<a class="is-flex-grow has-text-black-ter"
href="${servePath}${path}?p=${paginationNextPageNum}">下一页</a>
</div>
</#if>
<#-- 没有文章时500 -->
<#if paginationCurrentPageNum?has_content && paginationFirstPageNum?has_content>
<nav class="pagination is-centered" role="navigation" aria-label="pagination">
<#if paginationCurrentPageNum !=paginationFirstPageNum>

<div class="pagination-previous">
<a class="is-flex-grow has-text-black-ter"
href="${servePath}${path}?p=${paginationPreviousPageNum}">上一页</a>
</div>
</#if>
<#if paginationCurrentPageNum !=paginationLastPageNum>
<div class="pagination-next">
<a class="is-flex-grow has-text-black-ter"
href="${servePath}${path}?p=${paginationNextPageNum}">下一页</a>
</div>
</#if>


<ul class="pagination-list is-hidden-mobile">
<#list paginationPageNums as paginationPageNum>
<#if paginationPageNum==paginationCurrentPageNum>
<li><span class="pagination-link is-current">${paginationPageNum}</span></li>
<#else>
<li><a class="pagination-link"
href="${servePath}${path}?p=${paginationPageNum}">${paginationPageNum}</a></li>
</#if>
</#list>
</ul>
<ul class="pagination-list is-hidden-mobile">
<#list paginationPageNums as paginationPageNum>
<#if paginationPageNum==paginationCurrentPageNum>
<li><span class="pagination-link is-current">${paginationPageNum}</span></li>
<#else>
<li><a class="pagination-link"
href="${servePath}${path}?p=${paginationPageNum}">${paginationPageNum}</a></li>
</#if>
</#list>
</ul>

</nav>
</nav>
</#if>
</div>
</div>

0 comments on commit 40fd6d4

Please sign in to comment.