Skip to content

Commit

Permalink
fix current page styles not applying in production
Browse files Browse the repository at this point in the history
This commit replaces Astro local styles with tailwind equivalents.

Due to `Astro.url.pathname` inconsistencies between development and
production (see withastro/astro#5630), we
strip the trailing slash when doing comparisons against the current
pathname.
  • Loading branch information
mvllow committed Apr 18, 2023
1 parent 5138957 commit db19e19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/layouts/base.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export type Props = {
const { title, description } = Astro.props;
pathname.set(Astro.url.pathname);
// Remove trailing slash if present
// https://github.com/withastro/astro/issues/5630
pathname.set(Astro.url.pathname.replace(/(\/.*?)\/$/, "$1"));
---

<html lang="en">
Expand Down
17 changes: 6 additions & 11 deletions src/layouts/palette.astro
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ const menu = [
<li>
<a
href={href}
aria-current={Astro.url.pathname === href ? "page" : undefined}
aria-current={
Astro.url.pathname.replace(/(\/.*?)\/$/, "$1") === href
? "page"
: undefined
}
class:list={[
{ ["border-r"]: index < menu.length - 1 },
"flex bg-muted/10 px-4 py-2 text-sm font-medium text-subtle transition hover:text-text focus:outline-none focus:ring focus:ring-inset",
"flex bg-muted/10 px-4 py-2 text-sm font-medium text-subtle transition hover:text-text focus:outline-none focus:ring focus:ring-inset aria-[current=page]:bg-surface aria-[current=page]:text-text aria-[current=page]:hover:bg-surface",
]}
>
{name}
Expand All @@ -44,12 +48,3 @@ const menu = [
<slot />
</section>
</Layout>

<style>
[aria-current="page"] {
@apply bg-surface text-text;
}
[aria-current="page"]:hover {
@apply bg-surface;
}
</style>

0 comments on commit db19e19

Please sign in to comment.