Skip to content

Commit ed17844

Browse files
committed
refactor: enhance card component and navigation structure; add icons and improve layout on blog page plus more idk
1 parent 8232dee commit ed17844

File tree

13 files changed

+272
-130
lines changed

13 files changed

+272
-130
lines changed

src/components/Card.astro

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
---
22
import { Image } from "astro:assets";
33
4-
const { name, url, description, image, alt = "", background } = Astro.props;
4+
const {
5+
name,
6+
url,
7+
description,
8+
image,
9+
alt = "",
10+
background,
11+
showButton = true,
12+
} = Astro.props;
513
---
614

715
<style>
@@ -13,7 +21,7 @@ const { name, url, description, image, alt = "", background } = Astro.props;
1321
margin: 0;
1422
padding: 0;
1523
border-radius: 1.1rem;
16-
background-color: oklab(0 0 0/5%);
24+
background-color: oklab(0 0 0/3%);
1725
@media (prefers-color-scheme: dark) {
1826
background-color: oklab(1 0 0/5%);
1927
}
@@ -112,16 +120,31 @@ const { name, url, description, image, alt = "", background } = Astro.props;
112120
}
113121
</style>
114122

115-
<div class="card">
116-
<a href={url}>
117-
<Image src={image} alt={alt} />
118-
</a>
119-
<div class="card_text">
120-
<slot />
121-
</div>
122-
<a class="button" href={url}>
123-
<span class="front">
124-
Visit {name}
125-
</span>
126-
</a>
127-
</div>
123+
{
124+
showButton ? (
125+
<div class="card">
126+
{image && (
127+
<a href={url}>
128+
<Image src={image} alt={alt} />
129+
</a>
130+
)}
131+
132+
<div class="card_text">
133+
<slot />
134+
</div>
135+
136+
{url && (
137+
<a class="button" href={url}>
138+
<span class="front">Visit {name}</span>
139+
</a>
140+
)}
141+
</div>
142+
) : (
143+
<a href={url} class="card" style="text-decoration: none;">
144+
{image && <Image src={image} alt={alt} />}
145+
<div class="card_text">
146+
<slot />
147+
</div>
148+
</a>
149+
)
150+
}

src/components/Navigation/Headerbar.astro

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ const { pageTitle } = Astro.props;
3737
.headerbar-title {
3838
display: none;
3939
margin: 0;
40-
font-size: 16px;
41-
font-weight: 590;
40+
font-size: 15px;
41+
font-weight: 500;
4242
text-align: center;
4343
background-color: oklch(from var(--accent-color) 0.98 0.03 h / 90%);
4444
padding: 4px 16px;
4545
border-radius: 18px;
4646
backdrop-filter: blur(2px);
47+
line-height: 119%;
4748

4849
box-shadow:
4950
0 0.3rem 0.3rem rgba(0, 0, 0, 0.1),
Lines changed: 21 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
2+
import { pages } from "./nav.js";
3+
import { icons } from "./icons.js";
34
---
45

56
<style>
67
#tab-bar-large {
78
padding: 0.25rem;
89
width: fit-content;
9-
height: fit-content;
1010
backdrop-filter: blur(2px);
1111
border-radius: 999px;
1212
background-color: oklch(from var(--accent-color) 0.98 0.03 h / 90%);
@@ -33,23 +33,21 @@
3333
gap: 0.25rem;
3434

3535
.nav-item {
36-
background: transparent;
3736
border-radius: 999px;
3837

3938
a {
4039
padding: 0.25rem 1.25rem;
4140
border-radius: inherit;
42-
display: inline-block;
43-
font-weight: 600;
4441
display: flex;
4542
align-items: center;
4643
gap: 0.3rem;
44+
font-weight: 600;
4745
line-height: 150%;
4846
text-decoration: none;
4947
color: var(--text-color);
5048
}
5149

52-
a[href]:hover {
50+
a:hover {
5351
background-color: oklch(0 0 0 / 0.07);
5452
@media (prefers-color-scheme: dark) {
5553
background-color: oklch(1 0 0 / 0.06);
@@ -77,57 +75,33 @@
7775

7876
<script>
7977
const links = document.querySelectorAll(".nav-item a");
80-
const current = location.href;
78+
const current = location.pathname;
8179

82-
links.forEach((linkElement) => {
83-
const link = linkElement.href;
80+
links.forEach((link) => {
81+
const href = new URL(link.href).pathname;
8482

85-
if (link === location.origin + "/") {
86-
if (current === link) {
87-
linkElement.classList.add("active");
88-
}
83+
if (href === "/" && current === "/") {
84+
link.classList.add("active");
8985
return;
9086
}
9187

92-
if (current.startsWith(link)) {
93-
linkElement.classList.add("active");
88+
if (href !== "/" && current.startsWith(href)) {
89+
link.classList.add("active");
9490
}
9591
});
9692
</script>
9793

9894
<div id="tab-bar-large">
9995
<ul class="nav">
100-
<!-- first button -->
101-
<li class="nav-item">
102-
<a href="/">
103-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
104-
<g fill="currentColor">
105-
<path
106-
d="m 12 16 c 1.660156 0 3 -1.339844 3 -3 v -6 c 0 -0.929688 -0.414062 -1.8125 -1.128906 -2.410156 l -4.460938 -3.71875 c -0.816406 -0.679688 -2.003906 -0.679688 -2.820312 0 l -4.460938 3.71875 c -0.714844 0.597656 -1.128906 1.480468 -1.128906 2.410156 v 6 c 0 1.660156 1.339844 3 3 3 z m -9 -3 v -6 c 0 -0.335938 0.148438 -0.65625 0.410156 -0.871094 l 4.460938 -3.71875 c 0.074218 -0.0625 0.183594 -0.0625 0.257812 0 l 4.460938 3.71875 c 0.261718 0.214844 0.410156 0.535156 0.410156 0.871094 v 6 c 0 0.546875 -0.453125 1 -1 1 h -8 c -0.546875 0 -1 -0.453125 -1 -1 z m 0 0"
107-
></path>
108-
<path
109-
d="m 7 8 h 2 c 0.90781 0 1 0.449219 1 1 v 5 c 0 0.90781 -0.449219 1 -1 1 h -2 c -0.90781 0 -1 -0.449219 -1 -1 v -5 c 0 -0.90781 0.449219 -1 1 -1 z m 0 0"
110-
></path>
111-
</g>
112-
</svg>
113-
home</a
114-
>
115-
</li>
116-
<!-- second button -->
117-
<li class="nav-item">
118-
<a href="/blog">
119-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
120-
<g fill="currentColor">
121-
<path
122-
d="m 4.199219 2 c -0.453125 0 -0.84375 0.300781 -0.964844 0.738281 l -3.234375 11.261719 h 2.066406 l 0.808594 -3 l 2.125 -0.003906 l 2.121094 0.003906 l 0.808594 3 h 2.070312 l -3.238281 -11.261719 c -0.117188 -0.4375 -0.511719 -0.738281 -0.960938 -0.738281 z m 0.785156 2 h 0.015625 h 0.011719 c 0.121093 -0.003906 0.238281 0.011719 0.289062 0.207031 l 1.320313 4.792969 h -3.242188 l 1.316406 -4.792969 c 0.054688 -0.195312 0.171876 -0.210937 0.289063 -0.207031 z m 0 0"
123-
></path>
124-
<path
125-
d="m 10 0 v 1 h 2 v 14 h -2 v 1 h 2.5 l 0.5 -0.5 l 0.5 0.5 h 2.5 v -1 h -2 v -14 h 2 v -1 h -2.5 l -0.5 0.5 l -0.5 -0.5 z m 0 0"
126-
></path>
127-
</g>
128-
</svg>
129-
blog</a
130-
>
131-
</li>
96+
{
97+
pages.map((page) => (
98+
<li class="nav-item">
99+
<a href={page.url}>
100+
{icons[page.url] && <Fragment set:html={icons[page.url]} />}
101+
{page.title.toLowerCase()}
102+
</a>
103+
</li>
104+
))
105+
}
132106
</ul>
133107
</div>
Lines changed: 24 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
2+
import { pages } from "./nav.js";
3+
import { icons } from "./icons.js";
34
---
45

56
<style>
@@ -33,33 +34,29 @@
3334
list-style: none;
3435
margin: 0;
3536
padding: 0;
36-
gap: 0rem;
3737

3838
.nav-item {
39-
background: transparent;
4039
border-radius: 999px;
4140
display: flex;
42-
justify-content: stretch;
4341

4442
a {
45-
flex-direction: column;
4643
width: 102px;
4744
padding: 8px;
4845
border-radius: inherit;
49-
display: inline-block;
50-
font-weight: 600;
5146
display: flex;
47+
flex-direction: column;
5248
align-items: center;
5349
justify-content: center;
50+
gap: 0.2rem;
51+
font-weight: 600;
52+
font-size: 13px;
5453
line-height: 100%;
5554
text-decoration: none;
5655
color: var(--text-color);
57-
font-size: 13px;
58-
gap: 0.2rem;
5956
box-sizing: border-box;
6057
}
6158

62-
a[href]:hover {
59+
a:hover {
6360
background-color: oklch(0 0 0 / 0.06);
6461
@media (prefers-color-scheme: dark) {
6562
background-color: oklch(1 0 0 / 0.06);
@@ -87,57 +84,33 @@
8784

8885
<script>
8986
const links = document.querySelectorAll(".nav-item a");
90-
const current = location.href;
87+
const current = location.pathname;
9188

92-
links.forEach((linkElement) => {
93-
const link = linkElement.href;
89+
links.forEach((link) => {
90+
const href = new URL(link.href).pathname;
9491

95-
if (link === location.origin + "/") {
96-
if (current === link) {
97-
linkElement.classList.add("active");
98-
}
92+
if (href === "/" && current === "/") {
93+
link.classList.add("active");
9994
return;
10095
}
10196

102-
if (current.startsWith(link)) {
103-
linkElement.classList.add("active");
97+
if (href !== "/" && current.startsWith(href)) {
98+
link.classList.add("active");
10499
}
105100
});
106101
</script>
107102

108103
<div id="tab-bar-small">
109104
<ul class="nav">
110-
<!-- first button -->
111-
<li class="nav-item">
112-
<a href="/">
113-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
114-
<g fill="currentColor">
115-
<path
116-
d="m 12 16 c 1.660156 0 3 -1.339844 3 -3 v -6 c 0 -0.929688 -0.414062 -1.8125 -1.128906 -2.410156 l -4.460938 -3.71875 c -0.816406 -0.679688 -2.003906 -0.679688 -2.820312 0 l -4.460938 3.71875 c -0.714844 0.597656 -1.128906 1.480468 -1.128906 2.410156 v 6 c 0 1.660156 1.339844 3 3 3 z m -9 -3 v -6 c 0 -0.335938 0.148438 -0.65625 0.410156 -0.871094 l 4.460938 -3.71875 c 0.074218 -0.0625 0.183594 -0.0625 0.257812 0 l 4.460938 3.71875 c 0.261718 0.214844 0.410156 0.535156 0.410156 0.871094 v 6 c 0 0.546875 -0.453125 1 -1 1 h -8 c -0.546875 0 -1 -0.453125 -1 -1 z m 0 0"
117-
></path>
118-
<path
119-
d="m 7 8 h 2 c 0.90781 0 1 0.449219 1 1 v 5 c 0 0.90781 -0.449219 1 -1 1 h -2 c -0.90781 0 -1 -0.449219 -1 -1 v -5 c 0 -0.90781 0.449219 -1 1 -1 z m 0 0"
120-
></path>
121-
</g>
122-
</svg>
123-
home</a
124-
>
125-
</li>
126-
<!-- second button -->
127-
<li class="nav-item">
128-
<a href="/blog">
129-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
130-
<g fill="currentColor">
131-
<path
132-
d="m 4.199219 2 c -0.453125 0 -0.84375 0.300781 -0.964844 0.738281 l -3.234375 11.261719 h 2.066406 l 0.808594 -3 l 2.125 -0.003906 l 2.121094 0.003906 l 0.808594 3 h 2.070312 l -3.238281 -11.261719 c -0.117188 -0.4375 -0.511719 -0.738281 -0.960938 -0.738281 z m 0.785156 2 h 0.015625 h 0.011719 c 0.121093 -0.003906 0.238281 0.011719 0.289062 0.207031 l 1.320313 4.792969 h -3.242188 l 1.316406 -4.792969 c 0.054688 -0.195312 0.171876 -0.210937 0.289063 -0.207031 z m 0 0"
133-
></path>
134-
<path
135-
d="m 10 0 v 1 h 2 v 14 h -2 v 1 h 2.5 l 0.5 -0.5 l 0.5 0.5 h 2.5 v -1 h -2 v -14 h 2 v -1 h -2.5 l -0.5 0.5 l -0.5 -0.5 z m 0 0"
136-
></path>
137-
</g>
138-
</svg>
139-
blog</a
140-
>
141-
</li>
105+
{
106+
pages.map((page) => (
107+
<li class="nav-item">
108+
<a href={page.url}>
109+
{icons[page.url] && <Fragment set:html={icons[page.url]} />}
110+
{page.title.toLowerCase()}
111+
</a>
112+
</li>
113+
))
114+
}
142115
</ul>
143116
</div>

src/components/Navigation/icons.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import paintbrush from "../../styles/paintbrush-symbolic.svg?raw";
2+
3+
export const icons = {
4+
"/": `
5+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
6+
<g fill="currentColor">
7+
<path
8+
d="m 12 16 c 1.660156 0 3 -1.339844 3 -3 v -6 c 0 -0.929688 -0.414062 -1.8125 -1.128906 -2.410156 l -4.460938 -3.71875 c -0.816406 -0.679688 -2.003906 -0.679688 -2.820312 0 l -4.460938 3.71875 c -0.714844 0.597656 -1.128906 1.480468 -1.128906 2.410156 v 6 c 0 1.660156 1.339844 3 3 3 z m -9 -3 v -6 c 0 -0.335938 0.148438 -0.65625 0.410156 -0.871094 l 4.460938 -3.71875 c 0.074218 -0.0625 0.183594 -0.0625 0.257812 0 l 4.460938 3.71875 c 0.261718 0.214844 0.410156 0.535156 0.410156 0.871094 v 6 c 0 0.546875 -0.453125 1 -1 1 h -8 c -0.546875 0 -1 -0.453125 -1 -1 z m 0 0"
9+
></path>
10+
<path
11+
d="m 7 8 h 2 c 0.90781 0 1 0.449219 1 1 v 5 c 0 0.90781 -0.449219 1 -1 1 h -2 c -0.90781 0 -1 -0.449219 -1 -1 v -5 c 0 -0.90781 0.449219 -1 1 -1 z m 0 0"
12+
></path>
13+
</g>
14+
</svg>
15+
`,
16+
"/blog": `
17+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
18+
<g fill="currentColor">
19+
<path
20+
d="m 4.199219 2 c -0.453125 0 -0.84375 0.300781 -0.964844 0.738281 l -3.234375 11.261719 h 2.066406 l 0.808594 -3 l 2.125 -0.003906 l 2.121094 0.003906 l 0.808594 3 h 2.070312 l -3.238281 -11.261719 c -0.117188 -0.4375 -0.511719 -0.738281 -0.960938 -0.738281 z m 0.785156 2 h 0.015625 h 0.011719 c 0.121093 -0.003906 0.238281 0.011719 0.289062 0.207031 l 1.320313 4.792969 h -3.242188 l 1.316406 -4.792969 c 0.054688 -0.195312 0.171876 -0.210937 0.289063 -0.207031 z m 0 0"
21+
></path>
22+
<path
23+
d="m 10 0 v 1 h 2 v 14 h -2 v 1 h 2.5 l 0.5 -0.5 l 0.5 0.5 h 2.5 v -1 h -2 v -14 h 2 v -1 h -2.5 l -0.5 0.5 l -0.5 -0.5 z m 0 0"
24+
></path>
25+
</g>
26+
</svg>
27+
`,
28+
29+
"/portfolio": paintbrush,
30+
};

src/components/Navigation/nav.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const pages = Object.entries(
2+
import.meta.glob("/src/pages/*.astro", { eager: true }),
3+
)
4+
.map(([path, mod]) => {
5+
const file = path
6+
.split("/")
7+
.pop()
8+
.replace(/\.(astro|md|mdx)$/, "");
9+
10+
const url = file === "index" ? "/" : `/${file}`;
11+
12+
const title = file === "index" ? "home" : (mod.frontmatter?.title ?? file);
13+
14+
return {
15+
url,
16+
title,
17+
};
18+
})
19+
.sort((a, b) => a.url.localeCompare(b.url));
20+
21+
export { pages };

0 commit comments

Comments
 (0)