Skip to content

Commit 7a14517

Browse files
committed
Move paginated posts under /writeups/ and update nav
Delete root pagination route and add src/pages/writeups/[...page].astro. Update Pagination to generate /writeups/ URLs and adjust markup. Add Writeup link preset, change LinkPreset enum values and i18n key. Reorder nav links (About, Team, Writeup, Archive) and tweak Profile link rendering and single-link layout. Minor formatting cleanup.
1 parent 247dc68 commit 7a14517

10 files changed

Lines changed: 168 additions & 94 deletions

File tree

src/components/control/Pagination.astro

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { Icon } from "astro-icon/components";
44
import { url } from "../../utils/url-utils";
55
66
interface Props {
7-
page: Page;
8-
class?: string;
9-
style?: string;
7+
page: Page;
8+
class?: string;
9+
style?: string;
1010
}
1111
1212
const { page, style } = Astro.props;
@@ -23,17 +23,17 @@ let count = 1;
2323
let l = page.currentPage;
2424
let r = page.currentPage;
2525
while (0 < l - 1 && r + 1 <= page.lastPage && count + 2 <= VISIBLE) {
26-
count += 2;
27-
l--;
28-
r++;
26+
count += 2;
27+
l--;
28+
r++;
2929
}
3030
while (0 < l - 1 && count < VISIBLE) {
31-
count++;
32-
l--;
31+
count++;
32+
l--;
3333
}
3434
while (r + 1 <= page.lastPage && count < VISIBLE) {
35-
count++;
36-
r++;
35+
count++;
36+
r++;
3737
}
3838
3939
let pages: number[] = [];
@@ -46,39 +46,69 @@ if (r === page.lastPage - 2) pages.push(page.lastPage - 1);
4646
if (r < page.lastPage) pages.push(page.lastPage);
4747
4848
const getPageUrl = (p: number) => {
49-
if (p === 1) return "/";
50-
return `/${p}/`;
49+
if (p === 1) return "/writeups/";
50+
return `/writeups/${p}/`;
5151
};
5252
---
5353

54-
<div class:list={[className, "flex flex-row gap-3 justify-center"]} style={style}>
55-
<a href={page.url.prev || ""} aria-label={page.url.prev ? "Previous Page" : null}
56-
class:list={["btn-card overflow-hidden rounded-lg text-[var(--primary)] w-11 h-11",
57-
{"disabled": page.url.prev == undefined}
58-
]}
54+
<div
55+
class:list={[className, "flex flex-row gap-3 justify-center"]}
56+
style={style}
57+
>
58+
<a
59+
href={page.url.prev || ""}
60+
aria-label={page.url.prev ? "Previous Page" : null}
61+
class:list={[
62+
"btn-card overflow-hidden rounded-lg text-[var(--primary)] w-11 h-11",
63+
{ disabled: page.url.prev == undefined },
64+
]}
5965
>
60-
<Icon name="material-symbols:chevron-left-rounded" class="text-[1.75rem]"></Icon>
66+
<Icon
67+
name="material-symbols:chevron-left-rounded"
68+
class="text-[1.75rem]"
69+
/>
6170
</a>
62-
<div class="bg-[var(--card-bg)] flex flex-row rounded-lg items-center text-neutral-700 dark:text-neutral-300 font-bold">
63-
{pages.map((p) => {
64-
if (p == HIDDEN)
65-
return <Icon name="material-symbols:more-horiz" class="mx-1"/>;
66-
if (p == page.currentPage)
67-
return <div class="h-11 w-11 rounded-lg bg-[var(--primary)] flex items-center justify-center
71+
<div
72+
class="bg-[var(--card-bg)] flex flex-row rounded-lg items-center text-neutral-700 dark:text-neutral-300 font-bold"
73+
>
74+
{
75+
pages.map((p) => {
76+
if (p == HIDDEN)
77+
return (
78+
<Icon name="material-symbols:more-horiz" class="mx-1" />
79+
);
80+
if (p == page.currentPage)
81+
return (
82+
<div
83+
class="h-11 w-11 rounded-lg bg-[var(--primary)] flex items-center justify-center
6884
font-bold text-white dark:text-black/70"
69-
>
70-
{p}
71-
</div>
72-
return <a href={url(getPageUrl(p))} aria-label={`Page ${p}`}
73-
class="btn-card w-11 h-11 rounded-lg overflow-hidden active:scale-[0.85]"
74-
>{p}</a>
75-
})}
85+
>
86+
{p}
87+
</div>
88+
);
89+
return (
90+
<a
91+
href={url(getPageUrl(p))}
92+
aria-label={`Page ${p}`}
93+
class="btn-card w-11 h-11 rounded-lg overflow-hidden active:scale-[0.85]"
94+
>
95+
{p}
96+
</a>
97+
);
98+
})
99+
}
76100
</div>
77-
<a href={page.url.next || ""} aria-label={page.url.next ? "Next Page" : null}
78-
class:list={["btn-card overflow-hidden rounded-lg text-[var(--primary)] w-11 h-11",
79-
{"disabled": page.url.next == undefined}
80-
]}
101+
<a
102+
href={page.url.next || ""}
103+
aria-label={page.url.next ? "Next Page" : null}
104+
class:list={[
105+
"btn-card overflow-hidden rounded-lg text-[var(--primary)] w-11 h-11",
106+
{ disabled: page.url.next == undefined },
107+
]}
81108
>
82-
<Icon name="material-symbols:chevron-right-rounded" class="text-[1.75rem]"></Icon>
109+
<Icon
110+
name="material-symbols:chevron-right-rounded"
111+
class="text-[1.75rem]"
112+
/>
83113
</a>
84-
</div>
114+
</div>

src/components/widget/Profile.astro

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,74 @@ import ImageWrapper from "../misc/ImageWrapper.astro";
66
77
const config = profileConfig;
88
---
9+
910
<div class="card-base p-3">
10-
<a aria-label="Go to About Page" href={url('/about/')}
11-
class="group block relative mx-auto mt-1 lg:mx-0 lg:mt-0 mb-3
12-
max-w-[12rem] lg:max-w-none overflow-hidden rounded-xl active:scale-95">
13-
<div class="absolute transition pointer-events-none group-hover:bg-black/30 group-active:bg-black/50
14-
w-full h-full z-50 flex items-center justify-center">
15-
<Icon name="fa6-regular:address-card"
16-
class="transition opacity-0 scale-90 group-hover:scale-100 group-hover:opacity-100 text-white text-5xl">
17-
</Icon>
11+
<a
12+
aria-label="Go to About Page"
13+
href={url("/")}
14+
class="group block relative mx-auto mt-1 lg:mx-0 lg:mt-0 mb-3
15+
max-w-[12rem] lg:max-w-none overflow-hidden rounded-xl active:scale-95"
16+
>
17+
<div
18+
class="absolute transition pointer-events-none group-hover:bg-black/30 group-active:bg-black/50
19+
w-full h-full z-50 flex items-center justify-center"
20+
>
21+
<Icon
22+
name="fa6-regular:address-card"
23+
class="transition opacity-0 scale-90 group-hover:scale-100 group-hover:opacity-100 text-white text-5xl"
24+
/>
1825
</div>
19-
<ImageWrapper src={config.avatar || ""} alt="Profile Image of the Author" class="mx-auto lg:w-full h-full lg:mt-0 "></ImageWrapper>
26+
<ImageWrapper
27+
src={config.avatar || ""}
28+
alt="Profile Image of the Author"
29+
class="mx-auto lg:w-full h-full lg:mt-0"
30+
/>
2031
</a>
2132
<div class="px-2">
22-
<div class="font-bold text-xl text-center mb-1 dark:text-neutral-50 transition">{config.name}</div>
23-
<div class="h-1 w-5 bg-[var(--primary)] mx-auto rounded-full mb-2 transition"></div>
24-
<div class="text-center text-neutral-400 mb-2.5 transition">{config.bio}</div>
33+
<div
34+
class="font-bold text-xl text-center mb-1 dark:text-neutral-50 transition"
35+
>
36+
{config.name}
37+
</div>
38+
<div
39+
class="h-1 w-5 bg-[var(--primary)] mx-auto rounded-full mb-2 transition"
40+
>
41+
</div>
42+
<div class="text-center text-neutral-400 mb-2.5 transition">
43+
{config.bio}
44+
</div>
2545
<div class="flex flex-wrap gap-2 justify-center mb-1">
26-
{config.links.length > 1 && config.links.map(item =>
27-
<a rel="me" aria-label={item.name} href={item.url} target="_blank" class="btn-regular rounded-lg h-10 w-10 active:scale-90">
28-
<Icon name={item.icon} class="text-[1.5rem]"></Icon>
46+
{
47+
config.links.length > 1 &&
48+
config.links.map((item) => (
49+
<a
50+
rel="me"
51+
aria-label={item.name}
52+
href={item.url}
53+
target="_blank"
54+
class="btn-regular rounded-lg h-10 w-10 active:scale-90"
55+
>
56+
<Icon name={item.icon} class="text-[1.5rem]" />
57+
</a>
58+
))
59+
}
60+
{
61+
config.links.length == 1 && (
62+
<a
63+
rel="me"
64+
aria-label={config.links[0].name}
65+
href={config.links[0].url}
66+
target="_blank"
67+
class="btn-regular rounded-lg h-10 gap-2 px-3 font-bold active:scale-95"
68+
>
69+
<Icon
70+
name={config.links[0].icon}
71+
class="text-[1.5rem]"
72+
/>
73+
{config.links[0].name}
2974
</a>
30-
)}
31-
{config.links.length == 1 && <a rel="me" aria-label={config.links[0].name} href={config.links[0].url} target="_blank"
32-
class="btn-regular rounded-lg h-10 gap-2 px-3 font-bold active:scale-95">
33-
<Icon name={config.links[0].icon} class="text-[1.5rem]"></Icon>
34-
{config.links[0].name}
35-
</a>}
75+
)
76+
}
3677
</div>
3778
</div>
3879
</div>
39-

src/config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export const siteConfig: SiteConfig = {
4040

4141
export const navBarConfig: NavBarConfig = {
4242
links: [
43-
LinkPreset.Home,
44-
LinkPreset.Archive,
45-
LinkPreset.About,
43+
LinkPreset.About,
4644
LinkPreset.Team,
45+
LinkPreset.Writeup,
46+
LinkPreset.Archive,
4747
{
4848
name: "GitHub",
4949
url: "https://github.com/ByteTheCookies", // Internal links should not include the base path, as it is automatically added

src/constants/link-presets.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { i18n } from "@i18n/translation";
33
import { LinkPreset, type NavBarLink } from "@/types/config";
44

55
export const LinkPresets: { [key in LinkPreset]: NavBarLink } = {
6-
[LinkPreset.Home]: {
7-
name: i18n(I18nKey.home),
6+
[LinkPreset.About]: {
7+
name: i18n(I18nKey.about),
88
url: "/",
99
},
10-
[LinkPreset.About]: {
11-
name: i18n(I18nKey.about),
12-
url: "/about/",
10+
[LinkPreset.Writeup]: {
11+
name: i18n(I18nKey.writeups),
12+
url: "/writeups/",
1313
},
1414
[LinkPreset.Archive]: {
1515
name: i18n(I18nKey.archive),

src/i18n/i18nKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
enum I18nKey {
2-
home = "home",
2+
writeups = "writeups",
33
about = "about",
44
archive = "archive",
55
team = "team",

src/i18n/languages/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Key from "../i18nKey";
22
import type { Translation } from "../translation";
33

44
export const en: Translation = {
5-
[Key.home]: "Home",
5+
[Key.writeups]: "Writeups",
66
[Key.about]: "About",
77
[Key.archive]: "Archive",
88
[Key.team]: "Team",

src/pages/[...page].astro

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/pages/writeups/[...page].astro

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
import type { GetStaticPaths } from "astro";
3+
import Pagination from "../../components/control/Pagination.astro";
4+
import PostPage from "../../components/PostPage.astro";
5+
import { PAGE_SIZE } from "../../constants/constants";
6+
import MainGridLayout from "../../layouts/MainGridLayout.astro";
7+
import { getSortedPosts } from "../../utils/content-utils";
8+
9+
export const getStaticPaths = (async ({ paginate }) => {
10+
const allBlogPosts = await getSortedPosts();
11+
return paginate(allBlogPosts, { pageSize: PAGE_SIZE });
12+
}) satisfies GetStaticPaths;
13+
// https://github.com/withastro/astro/issues/6507#issuecomment-1489916992
14+
15+
const { page } = Astro.props;
16+
17+
const len = page.data.length;
18+
---
19+
20+
<MainGridLayout>
21+
<PostPage page={page} />
22+
<Pagination
23+
class="mx-auto onload-animation"
24+
page={page}
25+
style={`animation-delay: calc(var(--content-delay) + ${len * 50}ms)`}
26+
/>
27+
</MainGridLayout>

src/types/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ export type Favicon = {
4545
};
4646

4747
export enum LinkPreset {
48-
Home = 0,
48+
About = 0,
4949
Archive = 1,
50-
About = 2,
50+
Writeup = 2,
5151
Team = 3,
5252
}
5353

0 commit comments

Comments
 (0)