Skip to content

Commit e346261

Browse files
committed
set canonical url and relative urls
1 parent 6192cf6 commit e346261

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

docs/working-notes/todo3.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ better roadmap
456456
add youtube, twitter in footer
457457
sta se tacno desava kad je site_url netacan a i dalje radi, npr: https://nmc-docker.local.nemanjamitic.com
458458
PostCardSmall increase height maybe
459+
set canonicalURL, <link href={canonicalURL} rel="canonical" />
459460
----
460461
// 4.10
461462
in BaseHead.astro

src/components/BaseHead.astro

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,22 @@ import { ROUTES } from '@/constants/routes';
99
import { CONFIG } from '@/config';
1010
import { handleTitle } from '@/utils/metadata';
1111
import { filterUndefined } from '@/utils/objects';
12-
import { trimHttpProtocol } from '@/utils/strings';
1312
1413
import type { Metadata } from '@/types/common';
1514
16-
const { SITE_URL } = CONFIG;
17-
const domain = trimHttpProtocol(SITE_URL);
15+
const { AUTHOR_NAME } = CONFIG;
1816
1917
export interface BaseHeadProps {
2018
metadata: Metadata;
2119
}
2220
2321
// set defualt metadata in this component
2422
const { metadata } = Astro.props as BaseHeadProps;
25-
const { url: baseUrl } = Astro; // object
23+
24+
// site: SITE_URL var + '/'
25+
// url: full page url, cannonical url, per page
26+
const { url } = Astro; // objects
27+
const { host } = url;
2628
2729
const handledMetadata = handleTitle(metadata);
2830
@@ -31,7 +33,7 @@ const mergedMetadata: Required<Metadata> = { ...DEFAULT_METADATA, ...filteredMet
3133
3234
const { title, description, image } = mergedMetadata;
3335
34-
const ogImageUrl = new URL(image, baseUrl);
36+
const ogImageUrl = new URL(image, url);
3537
---
3638

3739
<head>
@@ -41,60 +43,60 @@ const ogImageUrl = new URL(image, baseUrl);
4143

4244
<meta name="theme-color" content="#c1ddf9" media="(prefers-color-scheme: light)" />
4345
<meta name="theme-color" content="#0f172a" media="(prefers-color-scheme: dark)" />
46+
47+
{/* Links */}
48+
{/* Root-Relative URL (Starts with /): */}
49+
<link rel="canonical" href={url} />
4450
<link
4551
rel="apple-touch-icon"
4652
sizes="180x180"
47-
href={`${SITE_URL}${ROUTES.STATIC.FAVICONS}apple-touch-icon.png`}
53+
href={`${ROUTES.STATIC.FAVICONS}apple-touch-icon.png`}
4854
/>
4955
<link
5056
rel="icon"
5157
type="image/png"
5258
sizes="32x32"
53-
href={`${SITE_URL}${ROUTES.STATIC.FAVICONS}favicon-32x32.png`}
59+
href={`${ROUTES.STATIC.FAVICONS}favicon-32x32.png`}
5460
/>
5561
<link
5662
rel="icon"
5763
type="image/png"
5864
sizes="16x16"
59-
href={`${SITE_URL}${ROUTES.STATIC.FAVICONS}favicon-16x16.png`}
65+
href={`${ROUTES.STATIC.FAVICONS}favicon-16x16.png`}
6066
/>
61-
<link rel="manifest" href={`${SITE_URL}/manifest.json`} />
67+
<link rel="manifest" href="/manifest.json" />
6268

6369
{/* Primary Meta Tags */}
6470
<title>{title}</title>
6571
<meta name="title" content={title} />
6672
<meta name="description" content={description} />
73+
<meta name="author" content={AUTHOR_NAME} />
6774

6875
{/* Feeds */}
6976
<link
7077
rel="alternate"
7178
type="application/rss+xml"
72-
title={`RSS feed for ${domain}`}
73-
href={`${SITE_URL}${ROUTES.API.FEED_RSS}`}
79+
title={`RSS feed for ${host}`}
80+
href={`${ROUTES.API.FEED_RSS}`}
7481
/>
7582
<link
7683
rel="alternate"
7784
type="application/json"
78-
title={`JSON feed for ${domain}`}
79-
href={`${SITE_URL}${ROUTES.API.FEED_JSON}`}
80-
/>
81-
<link
82-
rel="sitemap"
83-
type="application/xml"
84-
title="Sitemap"
85-
href={`${SITE_URL}${ROUTES.STATIC.SITEMAP}`}
85+
title={`JSON feed for ${host}`}
86+
href={`${ROUTES.API.FEED_JSON}`}
8687
/>
88+
<link rel="sitemap" type="application/xml" title="Sitemap" href={`${ROUTES.STATIC.SITEMAP}`} />
8789

8890
{/* Open Graph / Facebook */}
8991
<meta property="og:type" content="website" />
90-
<meta property="og:url" content={baseUrl} />
92+
<meta property="og:url" content={url} />
9193
<meta property="og:title" content={title} />
9294
<meta property="og:description" content={description} />
9395
<meta property="og:image" content={ogImageUrl} />
9496

9597
{/* Twitter */}
9698
<meta property="twitter:card" content="summary" />
97-
<meta property="twitter:url" content={baseUrl} />
99+
<meta property="twitter:url" content={url} />
98100
<meta property="twitter:title" content={title} />
99101
<meta property="twitter:description" content={description} />
100102
<meta property="twitter:image" content={ogImageUrl} />
@@ -106,7 +108,7 @@ const ogImageUrl = new URL(image, baseUrl);
106108
<script src="set-url-here" crossorigin="anonymous"></script>
107109
-->
108110

109-
<ViewTransitions fallback="animate" />
111+
<ViewTransitions fallback="none" />
110112

111113
<!--
112114
<style>

0 commit comments

Comments
 (0)