Skip to content

Commit

Permalink
Fix usage of VERCEL_PROJECT_PRODUCTION_URL
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbleasel committed Dec 31, 2024
1 parent 834c6fe commit 137af13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions apps/web/app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import Link from 'next/link';
import { notFound } from 'next/navigation';
import Balancer from 'react-wrap-balancer';

const protocol = env.VERCEL_PROJECT_PRODUCTION_URL?.startsWith('https')
? 'https'
: 'http';
const url = new URL(`${protocol}://${env.VERCEL_PROJECT_PRODUCTION_URL}`);

type BlogPostProperties = {
readonly params: Promise<{
slug: string;
Expand Down Expand Up @@ -69,10 +74,7 @@ const BlogPost = async ({ params }: BlogPostProperties) => {
description: page.description,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': new URL(
`/blog/${slug}`,
env.VERCEL_PROJECT_PRODUCTION_URL
).toString(),
'@id': new URL(`/blog/${slug}`, url).toString(),
},
headline: page._title,
image: page.image.url,
Expand Down
7 changes: 6 additions & 1 deletion apps/web/app/robots.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { env } from '@/env';
import type { MetadataRoute } from 'next';

const protocol = env.VERCEL_PROJECT_PRODUCTION_URL?.startsWith('https')
? 'https'
: 'http';
const url = new URL(`${protocol}://${env.VERCEL_PROJECT_PRODUCTION_URL}`);

export default function robots(): MetadataRoute.Robots {
return {
rules: {
userAgent: '*',
allow: '/',
},
sitemap: new URL('/sitemap.xml', env.VERCEL_PROJECT_PRODUCTION_URL).href,
sitemap: new URL('/sitemap.xml', url.href).href,
};
}
14 changes: 8 additions & 6 deletions apps/web/app/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,28 @@ const pages = appFolders
.filter((folder) => !folder.name.startsWith('_'))
.filter((folder) => !folder.name.startsWith('('))
.map((folder) => folder.name);

const blogs = (await blog.getPosts()).map((post) => post._slug);

const legals = (await legal.getPosts()).map((post) => post._slug);
const protocol = env.VERCEL_PROJECT_PRODUCTION_URL?.startsWith('https')
? 'https'
: 'http';
const url = new URL(`${protocol}://${env.VERCEL_PROJECT_PRODUCTION_URL}`);

const sitemap = async (): Promise<MetadataRoute.Sitemap> => [
{
url: new URL('/', env.VERCEL_PROJECT_PRODUCTION_URL).href,
url: new URL('/', url).href,
lastModified: new Date(),
},
...pages.map((page) => ({
url: new URL(page, env.VERCEL_PROJECT_PRODUCTION_URL).href,
url: new URL(page, url).href,
lastModified: new Date(),
})),
...blogs.map((blog) => ({
url: new URL(`blog/${blog}`, env.VERCEL_PROJECT_PRODUCTION_URL).href,
url: new URL(`blog/${blog}`, url).href,
lastModified: new Date(),
})),
...legals.map((legal) => ({
url: new URL(`legal/${legal}`, env.VERCEL_PROJECT_PRODUCTION_URL).href,
url: new URL(`legal/${legal}`, url).href,
lastModified: new Date(),
})),
];
Expand Down

0 comments on commit 137af13

Please sign in to comment.