From cd17271fb92d87c8a3d86e29b180d22a4c7b194c Mon Sep 17 00:00:00 2001 From: Jesse Smick Date: Thu, 7 Nov 2024 23:43:40 -0700 Subject: [PATCH] Fix rest of URLs to account for BASE_URL and needing trailing slash --- astro.config.mjs | 3 ++- src/components/Button.tsx | 9 +++------ src/components/Calendar.tsx | 14 ++++++-------- src/components/Link.tsx | 21 +++++++++++++++++++++ src/components/SolutionChecker.tsx | 2 +- src/layouts/Day.astro | 13 +++++++------ src/layouts/Layout.astro | 2 +- src/pages/index.astro | 2 +- 8 files changed, 42 insertions(+), 24 deletions(-) create mode 100644 src/components/Link.tsx diff --git a/astro.config.mjs b/astro.config.mjs index 9e4feba..bfaf14a 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -7,5 +7,6 @@ import tailwind from "@astrojs/tailwind"; export default defineConfig({ integrations: [react(), tailwind()], site: "https://dalurness.github.io", - base: "/winter-code-fest", + base: "/winter-code-fest/", + trailingSlash: "always", }); diff --git a/src/components/Button.tsx b/src/components/Button.tsx index 397ab69..2dafe9a 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -1,6 +1,5 @@ import { twMerge } from "tailwind-merge"; - -const { BASE_URL } = import.meta.env; +import { Link } from "./Link"; export enum Color { dark = "dark", @@ -56,15 +55,13 @@ export function LinkButton({ color = Color.dark, size = Size.medium, pill, - href, className, children, ...nativeProps }: LinkButtonProps) { return ( - {children} - + ); } diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index c1cfb85..3739d50 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -1,7 +1,7 @@ import { getCollection } from "astro:content"; import { twMerge } from "tailwind-merge"; +import { Link } from "./Link"; -const { BASE_URL } = import.meta.env; const days = await getCollection("days"); const titles = days.reduce( @@ -26,9 +26,7 @@ interface Props { className?: string; } -export default GridCalendar; - -function GridCalendar({ current, className }: Props) { +export function Calendar({ current, className }: Props) { return (
- day && ( )} - +
); } @@ -97,7 +95,7 @@ function TableDay({ day, current }: { day: number; current: number }) { return ( { + href: string; +} +export function Link({ href, children, ...nativeProps }: LinkProps) { + if (href.startsWith("/")) { + href = BASE_URL + href.slice(1); + } + + if (!HAS_EXTENSION.test(href) && !href.endsWith("/")) { + href += "/"; + } + + return ( + + {children} + + ); +} diff --git a/src/components/SolutionChecker.tsx b/src/components/SolutionChecker.tsx index 1229aa1..a16e04d 100644 --- a/src/components/SolutionChecker.tsx +++ b/src/components/SolutionChecker.tsx @@ -5,7 +5,7 @@ interface Props { solution: string; } -export default function ({ solution }: Props) { +export function SolutionChecker({ solution }: Props) { const [input, setInput] = useState(""); function checkSolution() { diff --git a/src/layouts/Day.astro b/src/layouts/Day.astro index 34a4d8d..2383c07 100644 --- a/src/layouts/Day.astro +++ b/src/layouts/Day.astro @@ -10,8 +10,9 @@ interface Props { import { MdCalendarMonth, MdEventBusy } from "react-icons/md"; import Layout from "./Layout.astro"; -import SolutionChecker from "../components/SolutionChecker"; -import Calendar from "../components/Calendar"; +import { SolutionChecker } from "../components/SolutionChecker"; +import { Calendar } from "../components/Calendar"; +import { Link } from "../components/Link"; const { BASE_URL } = import.meta.env; const { day, title, solutions } = Astro.props; @@ -22,10 +23,10 @@ const { day, title, solutions } = Astro.props;
- LogoWCFLogoWCF
diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index f1ed094..b9069cb 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -17,7 +17,7 @@ const { title } = Astro.props; {title} diff --git a/src/pages/index.astro b/src/pages/index.astro index fb93453..c148708 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -10,7 +10,7 @@ const { BASE_URL } = import.meta.env; class="px-4 sm:px-12 py-8 bg-yeti-light-3 flex flex-col items-center gap-8 max-w-screen-md md:mx-auto md:mt-12 md:rounded-2xl" >

Winter Code Fest

- WCF Logo + WCF Logo

The coolest coding festival of the year. Grab your laptop, your warmest blanket, and join us for a fun-filled