Added redirects

This commit is contained in:
Michael 2024-10-16 07:30:39 +00:00
parent bf91b37f81
commit 4a776d6a4b
8 changed files with 65 additions and 4 deletions

View File

@ -14,11 +14,12 @@ interface Props {
title: string;
description: string;
image?: string;
redirect?: string;
}
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const { title, description, image = "/nano.png" } = Astro.props;
const { title, description, image = "/nano.png", redirect } = Astro.props;
---
<!-- Global Metadata -->
@ -57,6 +58,13 @@ const { title, description, image = "/nano.png" } = Astro.props;
<meta property="twitter:description" content={description} />
<meta property="twitter:image" content={new URL(image, Astro.url)} />
{redirect ? (
<meta
http-equiv="refresh"
content={ `0; url=${ redirect }` }
/>
) : null}
<ViewTransitions />
<script>

View File

@ -32,4 +32,12 @@ const projects = defineCollection({
}),
});
export const collections = { blog, work, projects };
const redirects = defineCollection({
type: "content",
schema: z.object({
title: z.string(),
redirect: z.string(),
}),
});
export const collections = { blog, work, projects, redirects };

View File

@ -0,0 +1,4 @@
---
title: "Facebook"
redirect: "https://www.facebook.com/michael.rausch123/"
---

View File

@ -0,0 +1,4 @@
---
title: "Github"
redirect: "https://github.com/michaelrausch"
---

View File

@ -0,0 +1,4 @@
---
title: "Instagram"
redirect: "https://www.instagram.com/michaelnz_"
---

View File

@ -7,15 +7,16 @@ import { SITE } from "@consts";
type Props = {
title: string;
description: string;
redirect?: string;
};
const { title, description } = Astro.props;
const { title, description, redirect } = Astro.props;
---
<!doctype html>
<html lang="en">
<head>
<Head title={`${title} | ${SITE.NAME}`} description={description} />
<Head title={`${title} | ${SITE.NAME}`} description={description} redirect={redirect}/>
</head>
<body>
<Header />

View File

@ -0,0 +1,23 @@
---
import { type CollectionEntry, getCollection } from "astro:content";
import PageLayout from "@layouts/PageLayout.astro";
export async function getStaticPaths() {
const redirects = (await getCollection("redirects"))
return redirects.map((redirect) => ({
params: { slug: redirect.slug },
props: redirect,
}));
}
type Props = CollectionEntry<"redirects">;
const redirect = Astro.props;
const { Content } = await redirect.render();
---
<PageLayout title={redirect.data.title} description={redirect.data.title} redirect={redirect.data.redirect}>
<div class="text-center mt-10">
<p class="text-xl">Redirecting to {redirect.data.title}...</p>
</div>
</PageLayout>

9
src/pages/go/index.astro Normal file
View File

@ -0,0 +1,9 @@
---
import PageLayout from "@layouts/PageLayout.astro";
const redirect = "/"
---
<PageLayout title="Redirect..." description="Redirect" redirect={redirect}>
</PageLayout>