Skip to content

Commit

Permalink
🎉 Add page navigation buttons -> 2.5.0-rc
Browse files Browse the repository at this point in the history
  • Loading branch information
EveSunMaple committed Jul 31, 2024
1 parent fc47858 commit add2692
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 333 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,15 @@

- 修复了昼夜切换按钮实际操作区域与显示区域不一致的问题
- 修复了昼夜切换按钮不同步的问题,现在两个按钮与其实际主题统一

## [2.5.0-rc] - 2024-8-1

### Features

- 常驻了上下页的按钮,这下大家就知道我的博客其实是有做分页的了
- 添加了分页的按钮,终于不用一页一页地跳了

### Refactored

- 单页页面改成了十篇文章
- 去掉了 layout 的 title
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "frosti-test",
"type": "module",
"version": "2.5.0-beta.3",
"version": "2.5.0-rc",
"scripts": {
"dev": "astro dev",
"start": "astro dev",
Expand All @@ -10,13 +10,13 @@
"astro": "astro"
},
"dependencies": {
"@astrojs/check": "^0.8.2",
"@astrojs/check": "^0.8.3",
"@astrojs/mdx": "^2.3.1",
"@astrojs/rss": "^4.0.7",
"@astrojs/sitemap": "^3.1.6",
"@astrojs/tailwind": "^5.1.0",
"@playform/compress": "^0.0.13",
"astro": "^4.12.2",
"astro": "^4.12.3",
"astro-icon": "^1.1.0",
"astro-pagefind": "^1.6.0",
"dayjs": "^1.11.12",
Expand All @@ -27,7 +27,7 @@
"rehype-katex": "^7.0.0",
"remark-math": "^6.0.0",
"sass": "^1.77.8",
"shiki": "^1.11.2",
"shiki": "^1.12.0",
"twikoo": "^1.6.38",
"typescript": "^5.5.4"
},
Expand Down
544 changes: 256 additions & 288 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
const { title, image, includeSidebar = true } = Astro.props;
---

<html lang="zh-cn" class="bg-base-300" title="main-page">
<html lang="zh-cn" class="bg-base-300">
<title class="sr-only">{`${SITE_TAB} - ${title}`}</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
153 changes: 116 additions & 37 deletions src/pages/blog/[...page].astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,37 @@ import { infoTest } from "../../consts";
export async function getStaticPaths({ paginate }: { paginate: any }) {
const posts = await getCollection("blog");
posts.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
return paginate(posts, { pageSize: 5 });
return paginate(posts, { pageSize: 10 });
}
const { page }: { page: Page } = Astro.props;
function generatePageLinks(totalPages: number): {
active: string[];
hidden: string[];
} {
const pages = {
active: [] as string[],
hidden: [] as string[],
};
if (totalPages > 3) {
pages.active.push("1");
pages.active.push("...");
pages.active.push(totalPages.toString());
for (let i = 2; i <= totalPages - 1; i++) {
pages.hidden.push(i.toString());
}
} else {
for (let i = 1; i <= totalPages; i++) {
pages.active.push(i.toString());
}
}
return pages;
}
const totalPages = Math.ceil(page.total / page.size);
const pageLinks = generatePageLinks(totalPages);
---

<BaseLayout title="blog">
Expand Down Expand Up @@ -41,41 +68,93 @@ const { page }: { page: Page } = Astro.props;
}
</div>
<div class="flex justify-between mb-8">
{
page.url.prev ? (
<a href={page.url.prev} class="btn bg-base-100 shadow-xl">
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z" />
</svg>{" "}
{infoTest.prevPage}
</a>
) : (
<div />
)
}
{
page.url.next ? (
<a href={page.url.next} class="btn bg-base-100 shadow-xl">
{infoTest.nextPage}{" "}
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z" />
</svg>
</a>
) : (
<div />
)
}
<a
href={page.url.prev ? page.url.prev : ``}
class={page.url.prev
? `btn bg-base-100 shadow-xl`
: `btn btn-disabled bg-base-100 shadow-xl`}
>
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M15.41,16.58L10.83,12L15.41,7.41L14,6L8,12L14,18L15.41,16.58Z"
></path>
</svg>
{infoTest.prevPage}
</a>
<div class="join">
{
totalPages > 4 ? (
<>
{pageLinks.active.map((link) =>
link === "..." ? (
<div class="dropdown dropdown-top join-item rounded-none">
<div
tabindex="0"
role="button"
class="btn rounded-none w-[55px]"
>
...
</div>
<ul
tabindex="0"
class="menu dropdown-content bg-base-100 rounded-box z-[100] p-2 shadow-xl"
>
{pageLinks.hidden.map((hidden) => (
<li>
<a
href={hidden === "1" ? `/blog` : `/blog/${hidden}`}
class={`menu-item ${hidden === page.current ? "btn-active" : ""}`}
>
{hidden}
</a>
</li>
))}
</ul>
</div>
) : (
<a
href={link === "1" ? `/blog` : `/blog/${link}`}
class={`join-item btn ${link === page.current ? "btn-active" : ""}`}
>
{link}
</a>
)
)}
</>
) : (
pageLinks.active.map((link) => (
<a
href={link === "1" ? `/blog` : `/blog/${link}`}
class={`join-item btn ${link === page.current ? "btn-active" : ""}`}
>
{link}
</a>
))
)
}
</div>
<a
href={page.url.next ? page.url.next : ``}
class={page.url.next
? `btn bg-base-100 shadow-xl`
: `btn btn-disabled bg-base-100 shadow-xl`}
>
{infoTest.nextPage}
<svg
class="h-6 w-6 fill-current md:h-8 md:w-8"
xmlns="http://www.w3.org/2000/svg"
width="24"
height="24"
viewBox="0 0 24 24"
>
<path d="M8.59,16.58L13.17,12L8.59,7.41L10,6L16,12L10,18L8.59,16.58Z"
></path>
</svg>
</a>
</div>
</BaseLayout>
2 changes: 1 addition & 1 deletion src/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import LinkCard from "../components/page/LinkCard.astro";

</BaseCard>

<BaseCard title="home" image="/home.webp">
<BaseCard title="Home" image="/home.webp">
# 🧊 Frosti Introduction

---
Expand Down
8 changes: 8 additions & 0 deletions src/styles/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,12 @@ hr {
.highlight .code-lang {
font-family: 'Cascadia';
user-select: none;
}

details summary {
list-style: none;
outline: none;
align-items: center;
justify-content: center;
cursor: pointer;
}
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export interface Page {
next?: string;
};
data: Post[];
total: number;
size: number;
current: string;
}

export interface CardInfo {
Expand Down

1 comment on commit add2692

@Tikas
Copy link

@Tikas Tikas commented on add2692 Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你的 pnpm-lock.yaml 删除,提醒了我,得把所有的 lock 删除!

Please sign in to comment.