Files
blog/src/components/Post/Pagination.astro
2026-08-15 20:55:56 +08:00

50 lines
1002 B
Plaintext

---
interface Props {
page: number
totalPage: number
}
const {page, totalPage} = Astro.props
---
<!--分页器-->
{totalPage > 1 &&
<nav class="pagination" aria-label="分页">
{Array.from({length: totalPage}).map((_, index) => {
if (page === index + 1) {
return <span class="link current">{index + 1}</span>
}
return <a class="link" href={`/page/${index + 1}`}>{index + 1}</a>
})}
{page < totalPage ? <a href={`/page/${page + 1}`} class="link">下一页</a> :
<span class="link disabled">下一页</span>}
</nav>}
<style>
/* ========== 分页 ========== */
.pagination {
width: 100%;
text-align: right;
white-space: nowrap;
margin-top: 32px;
font-size: 13px;
}
.link {
display: inline-block;
margin: 0 12px;
line-height: 1;
color: var(--text-secondary);
}
.current{
color: var(--text-primary);
font-weight: bold;
}
.link.disabled {
color: var(--text-disabled);
cursor: not-allowed;
}
</style>