mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-16 00:49:40 +08:00
48 lines
2.0 KiB
HTML
48 lines
2.0 KiB
HTML
<div xmlns:th="https://www.thymeleaf.org"
|
|
th:fragment="widget (sidebar)"
|
|
th:class="'card widget ' + ${sidebar.hide}"
|
|
th:with="categories = ${categoryFinder.list(1,1)},
|
|
isEmpty = ${#lists.isEmpty(categories)}">
|
|
<div class="card-title">
|
|
<i th:class="${#strings.defaultString(sidebar.icon, 'ri-apps-line') + ' card-title-label'}"></i><span
|
|
th:text="${#strings.defaultString(sidebar.title, '分类')}"></span>
|
|
<a th:if="${theme.config.sidebar.categories_more}" class="card-more" th:href="@{/categories}">更多<i
|
|
class="ri-arrow-right-double-line"></i></a>
|
|
</div>
|
|
<div th:if="${isEmpty}" class="card-empty">暂无分类</div>
|
|
<div th:unless="${isEmpty}" class="card-content">
|
|
<ul class="menu-list" id="categories-menu-list">
|
|
</ul>
|
|
</div>
|
|
|
|
<script th:inline="javascript">
|
|
let categories = [[${categoryFinder.listAsTree()}]]
|
|
let limitCount = [[${#strings.isEmpty(theme.config.sidebar.categories_num)? 10 : T(java.lang.Integer).parseInt(theme.config.sidebar.categories_num)}]]
|
|
let count = 0
|
|
|
|
function showCategories(categories) {
|
|
let con = ''
|
|
for (let category of categories) {
|
|
count++
|
|
if (count > limitCount) {
|
|
return con
|
|
}
|
|
con += ' <li>\n' +
|
|
' <a class="level is-marginless" href="' + category.status.permalink + '">\n' +
|
|
' <span class="level-item">'+category.spec.displayName+'</span>\n' +
|
|
' <span class="level-item tag">'+(category.status.postCount === null ? 0 : category.status.postCount)+'</span>\n' +
|
|
' </a>\n'
|
|
|
|
if (category.children.length > 0) {
|
|
con += ' <ul>\n'
|
|
con += showCategories(category.children)
|
|
con += ' </ul>\n'
|
|
}
|
|
con += ' </li> \n'
|
|
}
|
|
return con
|
|
}
|
|
$('#categories-menu-list').html(showCategories(categories));
|
|
</script>
|
|
</div>
|