Skip to content

Commit

Permalink
refactor: Switch to sites without trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
macx committed Mar 31, 2024
1 parent efa291c commit 064569a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import rehypeSlug from 'rehype-slug'
// https://astro.build/config
export default defineConfig({
site: 'https://hawk-gt1191.de',
trailingSlash: 'ignore',
trailingSlash: 'never',
build: {
format: 'directory'
},
redirects: {
'/komponenten': {
status: 301,
Expand Down
14 changes: 10 additions & 4 deletions src/components/Metadata.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
---
import AstroFont from '@gamesome/astro-font/AstroFont.astro'
function removeTrailingSlash(str: string) {
return str.replace(/\/+$/, '')
}
interface Props {
title: string
description: string
Expand All @@ -13,18 +17,20 @@ interface Props {
const { title, description, type = 'website', pubDate, redirect } = Astro.props
const canonicalURL = new URL(Astro.url.pathname, Astro.site)
const canonicalUrl = removeTrailingSlash(
new URL(Astro.url.pathname, Astro.site).toString()
)
const openGraphImage = Astro.url.pathname.startsWith('/tutorials')
? new URL(`${canonicalURL}og.png`, Astro.url)
? new URL(`${canonicalUrl}/og.png`, Astro.url)
: new URL('images/website-cover.png', Astro.url)
---

<!-- Global Metad -->
<meta charset='UTF-8' />
<meta name='color-scheme' content='dark light' />
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<link rel='canonical' href={canonicalURL} />
<link rel='canonical' href={canonicalUrl} />
{redirect ? <meta http-equiv='refresh' content='0;url=/404' /> : null}

<!-- Primary Meta -->
Expand Down Expand Up @@ -56,7 +62,7 @@ const openGraphImage = Astro.url.pathname.startsWith('/tutorials')
<!-- Open Graph / Facebook -->
<meta property='og:title' content={title} />
<meta property='og:description' content={description} />
<meta property='og:url' content={canonicalURL} />
<meta property='og:url' content={canonicalUrl} />
<meta property='og:type' content={type} />
{
openGraphImage && (
Expand Down

0 comments on commit 064569a

Please sign in to comment.