完成首页的文章分页功能

This commit is contained in:
XPoet 2020-03-15 15:45:38 +08:00
parent 8f08a8d586
commit 807ee33403
5 changed files with 109 additions and 1 deletions

View File

@ -49,4 +49,24 @@
</ul>
<% } %>
<!-- 分页器 -->
<div class="paginator">
<!--<ul class="paginator-btn-box">
<li class="paginator-btn prev-page">
<a class="btn" role="navigation" href=""><%- __('prev') %></a>
</li>
<li class="paginator-btn next-page">
<a class="btn" role="navigation" href=""><%- __('next') %></a>
</li>
</ul>-->
<%- paginator({
prev_text: __('prev'),
next_text: __('next'),
escape: false
}) %>
</div>
</div>

View File

@ -40,4 +40,63 @@ a:hover, a:active {
color: #4786D6;
}
//
a.btn {
color: #868686;
font-weight: 400;
}
.btn {
display: inline-block;
position: relative;
outline: 0;
color: rgba(0, 0, 0, 0.44);
background: rgba(0, 0, 0, 0);
font-size: 14px;
text-align: center;
text-decoration: none;
cursor: pointer;
border: 1px solid rgba(0, 0, 0, 0.15);
white-space: nowrap;
font-weight: 400;
font-style: normal;
border-radius: 999em;
}
.btn:hover {
display: inline-block;
position: relative;
outline: 0;
color: #464545;
background: rgba(0, 0, 0, 0);
font-size: 14px;
text-align: center;
text-decoration: none;
cursor: pointer;
border: 1px solid #464545;
white-space: nowrap;
font-weight: 400;
font-style: normal;
border-radius: 999em;
}
[role="back"] {
padding: 0.5em 1.25em;
line-height: 1.666em;
}
[role="home"] {
padding: 0.5em 1.25em;
line-height: 1.666em;
}
[role="navigation"] {
padding: 0.5em 1.25em;
line-height: 1.666em;
}
[role="tags"] {
padding: 6px 12px;
}

View File

@ -1,4 +1,5 @@
.article-post {
background: #fff
padding 30px
@ -109,6 +110,25 @@
}
}
.paginator {
padding-bottom 40px
.page-number {
display none !important
}
a.prev {
float left
}
a.next {
float right
}
}
}

View File

@ -1,2 +1,8 @@
console.log(new Date());
console.log('this is main.js');
(() => {
// 选择分页器元素里面的 a 标签,但不包含 .page-number给指定元素追加类 btn 和 设置属性 role=navigation
document.querySelectorAll('.article-post .paginator a:not(.page-number)').forEach(e => {
e.classList.add('btn');
e.setAttribute('role', 'navigation');
});
})();

3
source/js/utils.js Normal file
View File

@ -0,0 +1,3 @@
export const addClass = (element, className) => {
element.classList.add(className)
};