Skip to content

Commit 8d53772

Browse files
authored
fix: header layout bug (#8)
1 parent 6ff1b38 commit 8d53772

File tree

11 files changed

+107
-58
lines changed

11 files changed

+107
-58
lines changed

Diff for: src/components/Breadcrumbs.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ breadcrumbList[0] === 'posts' &&
77
breadcrumbList.splice(0, 2, `Posts (page ${breadcrumbList[1] || 1})`);
88
---
99

10-
<nav class="mx-auto mb-1 mt-8 w-full max-w-3xl px-4" aria-label="breadcrumb">
10+
<nav class="mx-auto mb-1 mt-8 w-full max-w-4xl px-4" aria-label="breadcrumb">
1111
<ul class="flex">
1212
<li class="inline">
1313
<a class="capitalize opacity-70" href="/">Home</a>

Diff for: src/components/Card.astro

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
import Date from './Date.astro';
33
import type { CollectionEntry } from 'astro:content';
4-
import dayjs from 'dayjs';
4+
import { formatDate } from '~/utils/formatDate';
55
66
interface Props {
77
href?: string;
@@ -11,7 +11,7 @@ interface Props {
1111
}
1212
const { href, frontmatter, slug, secHeading = true } = Astro.props;
1313
const { title, pubDate, description } = frontmatter;
14-
const date = dayjs(pubDate).format('DD/MM/YYYY');
14+
const date = formatDate(pubDate);
1515
1616
const headerProps = {
1717
style: { viewTransitionName: slug },

Diff for: src/components/Header.astro

+56-17
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const { activeNav } = Astro.props;
1616
href="#main-content">Skip to content</a
1717
>
1818
<div
19-
class="mx-auto flex max-w-3xl flex-col items-center justify-between sm:flex-row"
19+
class="mx-auto flex max-w-4xl flex-col items-center justify-between sm:flex-row"
2020
>
2121
<div
2222
class="relative flex w-full items-start justify-between p-4 sm:items-center sm:py-8"
@@ -38,12 +38,9 @@ const { activeNav } = Astro.props;
3838
)
3939
}
4040
</a>
41-
<nav
42-
id="nav-menu"
43-
class="flex w-full flex-col items-center sm:ml-2 sm:flex-row sm:justify-end sm:space-x-4 sm:py-0"
44-
>
41+
<nav id="nav-menu">
4542
<button
46-
class="self-end p-2 sm:hidden focus-outline"
43+
class="hamburger-menu focus-outline"
4744
aria-label="Open Menu"
4845
aria-expanded="false"
4946
aria-controls="menu-items"
@@ -58,7 +55,7 @@ const { activeNav } = Astro.props;
5855
stroke-width="1.5"
5956
stroke-linecap="round"
6057
stroke-linejoin="round"
61-
class="h-6 w-6 scale-125 fill-skin-base"
58+
class="menu-icon"
6259
>
6360
<line x1="7" y1="12" x2="21" y2="12" class="line"></line>
6461
<line x1="3" y1="6" x2="21" y2="6" class="line"></line>
@@ -67,10 +64,7 @@ const { activeNav } = Astro.props;
6764
<line x1="6" y1="6" x2="18" y2="18" class="close"></line>
6865
</svg>
6966
</button>
70-
<ul
71-
id="menu-items"
72-
class="display-none sm:flex mt-4 grid w-44 grid-cols-2 grid-rows-4 gap-x-2 gap-y-2 sm:ml-0 sm:mt-0 sm:w-auto sm:gap-x-5 sm:gap-y-0"
73-
>
67+
<ul id="menu-items" class="sm:flex hidden">
7468
<li>
7569
<a href="/blog" class={activeNav === 'posts' ? 'active' : ''}>
7670
Posts
@@ -99,14 +93,14 @@ const { activeNav } = Astro.props;
9993
<svg
10094
xmlns="http://www.w3.org/2000/svg"
10195
id="moon-svg"
102-
class="block scale-125 hover:rotate-12 sm:scale-100 dark:hidden"
96+
class="block scale-125 hover:rotate-12 sm:scale-100"
10397
>
10498
<path d="M20.742 13.045a8.088 8.088 0 0 1-2.077.271c-2.135 0-4.14-.83-5.646-2.336a8.025 8.025 0 0 1-2.064-7.723A1 1 0 0 0 9.73 2.034a10.014 10.014 0 0 0-4.489 2.582c-3.898 3.898-3.898 10.243 0 14.143a9.937 9.937 0 0 0 7.072 2.93 9.93 9.93 0 0 0 7.07-2.929 10.007 10.007 0 0 0 2.583-4.491 1.001 1.001 0 0 0-1.224-1.224zm-2.772 4.301a7.947 7.947 0 0 1-5.656 2.343 7.953 7.953 0 0 1-5.658-2.344c-3.118-3.119-3.118-8.195 0-11.314a7.923 7.923 0 0 1 2.06-1.483 10.027 10.027 0 0 0 2.89 7.848 9.972 9.972 0 0 0 7.848 2.891 8.036 8.036 0 0 1-1.484 2.059z" />
10599
</svg>
106100
<svg
107101
xmlns="http://www.w3.org/2000/svg"
108102
id="sun-svg"
109-
class="hidden scale-125 hover:rotate-12 sm:scale-100 dark:block"
103+
class="hidden scale-125 hover:rotate-12 sm:scale-100"
110104
>
111105
<path d="M6.993 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007S14.761 6.993 12 6.993 6.993 9.239 6.993 12zM12 8.993c1.658 0 3.007 1.349 3.007 3.007S13.658 15.007 12 15.007 8.993 13.658 8.993 12 10.342 8.993 12 8.993zM10.998 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2h-3zm17 0h3v2h-3zM4.219 18.363l2.12-2.122 1.415 1.414-2.12 2.122zM16.24 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.342 7.759 4.22 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z" />
112106
</svg>
@@ -122,6 +116,31 @@ const { activeNav } = Astro.props;
122116
</header>
123117

124118
<style>
119+
#skip-to-content {
120+
@apply absolute -top-full left-16 z-50 bg-skin-accent px-3 py-2 text-skin-inverted transition-all focus:top-4;
121+
}
122+
.nav-container {
123+
@apply mx-auto flex max-w-4xl flex-col items-center justify-between sm:flex-row;
124+
}
125+
.top-nav-wrap {
126+
@apply relative flex w-full items-start justify-between p-4 sm:items-center sm:py-8;
127+
}
128+
.logo {
129+
@apply absolute py-1 text-xl font-semibold sm:static sm:text-2xl;
130+
}
131+
.hamburger-menu {
132+
@apply self-end p-2 sm:hidden;
133+
}
134+
.hamburger-menu svg {
135+
@apply h-6 w-6 scale-125 fill-skin-base;
136+
}
137+
138+
nav {
139+
@apply flex w-full flex-col items-center sm:ml-2 sm:flex-row sm:justify-end sm:space-x-4 sm:py-0;
140+
}
141+
nav ul {
142+
@apply sm:flex mt-4 w-44 grid-cols-2 grid-rows-4 gap-x-2 gap-y-2 sm:ml-0 sm:mt-0 sm:w-auto sm:gap-x-5 sm:gap-y-0;
143+
}
125144
nav ul li {
126145
@apply col-span-2 flex items-center justify-center;
127146
}
@@ -131,19 +150,30 @@ const { activeNav } = Astro.props;
131150
nav ul li:nth-last-child(2) a {
132151
@apply w-auto;
133152
}
134-
nav ul li:nth-last-child(1),
135-
nav ul li:nth-last-child(2) {
153+
/* TODO: readd this when search functionality is added */
154+
/* nav ul li:nth-last-child(1) {
136155
@apply col-span-1;
137-
}
156+
} */
138157
nav a.active {
139158
@apply underline decoration-wavy decoration-2 underline-offset-4;
140159
}
141160
nav a.active svg {
142161
@apply fill-skin-accent;
143162
}
163+
164+
nav button {
165+
@apply p-1;
166+
}
144167
nav button svg {
145168
@apply h-6 w-6 fill-skin-base hover:fill-skin-accent;
146169
}
170+
#theme-btn {
171+
@apply p-3 sm:p-1;
172+
}
173+
#theme-btn svg {
174+
@apply scale-125 hover:rotate-12 sm:scale-100;
175+
}
176+
147177
.menu-icon line {
148178
@apply transition-opacity duration-75 ease-in-out;
149179
}
@@ -156,6 +186,14 @@ const { activeNav } = Astro.props;
156186
.menu-icon.is-active .close {
157187
@apply opacity-100;
158188
}
189+
#sun-svg,
190+
html[data-theme='dark'] #moon-svg {
191+
display: none;
192+
}
193+
#moon-svg,
194+
html[data-theme='dark'] #sun-svg {
195+
display: block;
196+
}
159197
</style>
160198

161199
<script>
@@ -173,7 +211,8 @@ const { activeNav } = Astro.props;
173211
'aria-label',
174212
menuExpanded ? 'Open Menu' : 'Close Menu',
175213
);
176-
menuItems?.classList.toggle('display-none');
214+
menuItems?.classList.remove(menuExpanded ? 'grid' : 'hidden');
215+
menuItems?.classList.add(menuExpanded ? 'hidden' : 'grid');
177216
});
178217
}
179218

Diff for: src/components/Hr.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export interface Props {
77
const { noPadding = false, ariaHidden = true } = Astro.props;
88
---
99

10-
<div class={`max-w-3xl mx-auto ${noPadding ? "px-0" : "px-4"}`}>
10+
<div class={`max-w-4xl mx-auto ${noPadding ? 'px-0' : 'px-4'}`}>
1111
<hr class="border-skin-line" aria-hidden={ariaHidden} />
1212
</div>

Diff for: src/layouts/Main.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const { props } = Astro;
3737

3838
<style>
3939
#main-content {
40-
@apply mx-auto w-full max-w-3xl px-4 pb-12;
40+
@apply mx-auto w-full max-w-4xl px-8 sm:px-4 pb-12;
4141
}
4242
#main-content h1 {
4343
@apply text-2xl font-semibold sm:text-3xl;

Diff for: src/layouts/PostDetails.astro

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import Date from '~/components/Date.astro';
66
import Footer from '~/components/Footer.astro';
77
import { site } from '~/utils/config';
88
import Tag from '~/components/Tag.astro';
9-
import dayjs from 'dayjs';
109
import ReadingTime from '~/components/ReadingTime.astro';
10+
import { formatDate } from '~/utils/formatDate';
1111
// import Author from '~/components/Author.astro';
1212
1313
export interface Props {
@@ -17,16 +17,16 @@ export interface Props {
1717
const { post } = Astro.props;
1818
1919
const { title, description, pubDate, tags, updatedAt } = post.data;
20-
const date = dayjs(pubDate).format('DD/MM/YYYY');
21-
const updatedDate = dayjs(updatedAt).format('DD/MM/YYYY');
20+
const date = formatDate(pubDate);
21+
const updatedDate = formatDate(updatedAt!);
2222
2323
const { Content, remarkPluginFrontmatter } = await post.render();
2424
const time = remarkPluginFrontmatter.minutesRead;
2525
---
2626

2727
<Layout title={title} author={site.author} description={description}>
2828
<Header />
29-
<div class="mx-auto flex w-full max-w-3xl justify-start px-2">
29+
<div class="mx-auto flex w-full max-w-4xl justify-start px-2">
3030
<button
3131
class="focus-outline mb-2 mt-8 flex hover:opacity-75"
3232
onclick="history.back()"
@@ -38,7 +38,7 @@ const time = remarkPluginFrontmatter.minutesRead;
3838
</svg><span>Go back</span>
3939
</button>
4040
</div>
41-
<main id="main-content" class="mx-auto w-full max-w-3xl px-4 pb-12">
41+
<main id="main-content" class="mx-auto w-full max-w-4xl px-4 pb-12">
4242
<h1
4343
transition:name={post.slug}
4444
class="text-2xl font-semibold text-skin-accent"
@@ -51,7 +51,7 @@ const time = remarkPluginFrontmatter.minutesRead;
5151
<ul class="my-8">
5252
{tags!.map((tag) => <Tag name={tag} />)}
5353
</ul>
54-
<article id="article" role="article" class="prose mx-auto mt-8 max-w-3xl">
54+
<article id="article" role="article" class="prose mx-auto mt-8 max-w-4xl">
5555
<Content />
5656
{
5757
updatedAt ? (

Diff for: src/layouts/Posts.astro

+29-25
Original file line numberDiff line numberDiff line change
@@ -26,39 +26,43 @@ const next = pageNum < totalPages ? '' : 'disabled';
2626
<ul>
2727
{
2828
posts.map(({ data, slug }) => (
29-
<Card href={`/blog/${slug}`} frontmatter={data} {slug}/>
29+
<Card href={`/blog/${slug}`} frontmatter={data} {slug} />
3030
))
3131
}
3232
</ul>
3333
</Main>
3434

3535
{
36-
totalPages > 1 && (
36+
totalPages > 1 ? (
3737
<nav class="pagination-wrapper" aria-label="Pagination">
38-
<Link
39-
disabled={prev === 'disabled'}
40-
href={`/blog${pageNum - 1 !== 1 ? '/' + (pageNum - 1) : ''}`}
41-
className={`mr-4 select-none ${prev}`}
42-
ariaLabel="Previous"
43-
>
44-
<svg xmlns="http://www.w3.org/2000/svg" class={`${prev}-svg`}>
45-
<path d="M12.707 17.293 8.414 13H18v-2H8.414l4.293-4.293-1.414-1.414L4.586 12l6.707 6.707z" />
46-
</svg>
47-
Prev
48-
</Link>
49-
<Link
50-
disabled={next === 'disabled'}
51-
href={`/blog/${pageNum + 1}`}
52-
className={`ml-4 select-none ${next}`}
53-
ariaLabel="Next"
54-
>
55-
Next
56-
<svg xmlns="http://www.w3.org/2000/svg" class={`${next}-svg`}>
57-
<path d="m11.293 17.293 1.414 1.414L19.414 12l-6.707-6.707-1.414 1.414L15.586 11H6v2h9.586z" />
58-
</svg>
59-
</Link>
38+
{pageNum === 1 ? null : (
39+
<Link
40+
disabled={prev === 'disabled'}
41+
href={`/blog${pageNum - 1 !== 1 ? '/' + (pageNum - 1) : ''}`}
42+
className={`mr-4 select-none ${prev}`}
43+
ariaLabel="Previous"
44+
>
45+
<svg xmlns="http://www.w3.org/2000/svg" class={`${prev}-svg`}>
46+
<path d="M12.707 17.293 8.414 13H18v-2H8.414l4.293-4.293-1.414-1.414L4.586 12l6.707 6.707z" />
47+
</svg>
48+
Prev
49+
</Link>
50+
)}
51+
{pageNum === totalPages ? null : (
52+
<Link
53+
disabled={next === 'disabled'}
54+
href={`/blog/${pageNum + 1}`}
55+
className={`ml-4 select-none ${next}`}
56+
ariaLabel="Next"
57+
>
58+
Next
59+
<svg xmlns="http://www.w3.org/2000/svg" class={`${next}-svg`}>
60+
<path d="m11.293 17.293 1.414 1.414L19.414 12l-6.707-6.707-1.414 1.414L15.586 11H6v2h9.586z" />
61+
</svg>
62+
</Link>
63+
)}
6064
</nav>
61-
)
65+
) : null
6266
}
6367
<Footer noMarginTop={totalPages > 1} />
6468
</Layout>

Diff for: src/pages/about.astro

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Layout from '~/layouts/Layout.astro';
66

77
<Layout title="About - DerTimonius">
88
<Header activeNav="about" />
9-
<main class="mx-auto w-full max-w-3xl px-4 py-12">
9+
<main class="mx-auto w-full max-w-4xl px-4 py-12">
1010
<h1 class="text-2xl font-semibold sm:text-3xl">About</h1>
1111
<p class="mb-6 mt-2 italic">Timon Jurschitsch</p>
1212
<p class="my-2">

Diff for: src/styles/style.css

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
@layer base {
66
:root,
77
html[data-theme='light'] {
8-
--color-fill: 251, 254, 251;
8+
--color-fill: 240, 240, 240;
99
--color-text-base: 40, 39, 40;
10-
--color-accent: 0, 108, 172;
10+
--color-accent: 0, 66, 154;
1111
--color-card: 230, 230, 230;
1212
--color-card-muted: 205, 205, 205;
1313
--color-border: 236, 233, 233;
1414
}
1515
html[data-theme='dark'] {
16-
--color-fill: 33, 39, 55;
16+
--color-fill: 23, 29, 45;
1717
--color-text-base: 234, 237, 243;
1818
--color-accent: 255, 107, 1;
1919
--color-card: 52, 63, 96;
@@ -26,7 +26,7 @@
2626
}
2727
section,
2828
footer {
29-
@apply mx-auto max-w-3xl px-4;
29+
@apply mx-auto max-w-4xl px-4;
3030
}
3131
a {
3232
@apply outline-2 outline-offset-1 outline-skin-fill

Diff for: src/utils/formatDate.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import dayjs from 'dayjs';
2+
3+
export function formatDate(date: Date | string): string {
4+
return dayjs(date).format('MMMM DD, YYYY');
5+
}

Diff for: tailwind.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function withOpacity(variableName) {
1010
/** @type {import('tailwindcss').Config} */
1111
module.exports = {
1212
content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
13+
darkMode: 'class',
1314
theme: {
1415
// Remove the following screen breakpoint or add other breakpoints
1516
// if one breakpoint is not enough for you

0 commit comments

Comments
 (0)