Skip to content

Commit 8a34864

Browse files
committed
add SITE_URL_CANONICAL config property, point all deployments to single canonical url
1 parent 1811b65 commit 8a34864

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/components/BaseHead.astro

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { filterUndefined } from '@/utils/objects';
1313
1414
import type { Metadata } from '@/types/common';
1515
16-
const { AUTHOR_NAME, PLAUSIBLE_SCRIPT_URL, PLAUSIBLE_DOMAIN } = CONFIG_CLIENT;
16+
const { SITE_URL_CANONICAL, AUTHOR_NAME, PLAUSIBLE_SCRIPT_URL, PLAUSIBLE_DOMAIN } = CONFIG_CLIENT;
1717
1818
export interface BaseHeadProps {
1919
metadata: Metadata;
@@ -23,9 +23,12 @@ export interface BaseHeadProps {
2323
const { metadata } = Astro.props as BaseHeadProps;
2424
2525
// site: SITE_URL var + '/'
26-
// url: full page url, cannonical url, per page
26+
// url: current page url, per page
2727
const { url } = Astro; // objects
28-
const { host } = url; // host - nemanjamitic.com
28+
const { host, pathname, search } = url; // host - nemanjamitic.com
29+
30+
// replace host - all deployments point to single canonical deployment url
31+
const canonicalUrl = new URL(`${pathname}${search}`, SITE_URL_CANONICAL);
2932
3033
const handledMetadata = handleTitle(metadata);
3134
@@ -47,7 +50,7 @@ const ogImageUrl = new URL(image, url);
4750

4851
{/* Links */}
4952
{/* Root-Relative URL (Starts with /): */}
50-
<link rel="canonical" href={url} />
53+
<link rel="canonical" href={canonicalUrl} />
5154
<link
5255
rel="apple-touch-icon"
5356
sizes="180x180"

src/config/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import type { ConfigClientType } from '@/types/config';
88
const configClientData: ConfigClientType = {
99
/** all urls without '/' */
1010
SITE_URL,
11+
/** same for all environments, defined here, not env var */
12+
SITE_URL_CANONICAL: 'https://nemanjamitic.com',
1113
SITE_TITLE: 'Nemanja Mitic',
1214
SITE_DESCRIPTION: 'I am Nemanja, a full stack developer',
1315
PLAUSIBLE_SCRIPT_URL,
@@ -19,7 +21,7 @@ const configClientData: ConfigClientType = {
1921
DEFAULT_MODE: 'light',
2022
DEFAULT_THEME: 'default-light',
2123
AUTHOR_NAME: 'Nemanja Mitic',
22-
AUTHOR_EMAIL: '[email protected]',
24+
AUTHOR_EMAIL: '[email protected]', // todo: use email
2325
AUTHOR_GITHUB: 'https://github.com/nemanjam',
2426
AUTHOR_LINKEDIN: 'https://www.linkedin.com/in/nemanja-mitic',
2527
AUTHOR_TWITTER: 'https://x.com/nemanja_codes',

src/schemas/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const configClientSchema = processEnvSchema
4242
.pick({ SITE_URL: true, PLAUSIBLE_SCRIPT_URL: true, PLAUSIBLE_DOMAIN: true })
4343
.merge(
4444
z.object({
45+
SITE_URL_CANONICAL: z.string().min(1),
4546
SITE_TITLE: z.string().min(1),
4647
SITE_DESCRIPTION: z.string().min(1),
4748
PAGE_SIZE_POST_CARD: z.number(),

0 commit comments

Comments
 (0)