-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageTitle.tsx
More file actions
68 lines (55 loc) · 1.56 KB
/
PageTitle.tsx
File metadata and controls
68 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { Helmet } from "react-helmet-async";
const DEFAULT_TITLE = "UpLine";
const TITLE_SEPARATOR = " - ";
/**
* Component to set the page title and meta tags using Helmet
*/
interface PageTitleProps {
title?: string;
prefix?: string;
description?: string;
}
export function PageTitle({ title, prefix, description }: PageTitleProps) {
const fullTitle = buildTitle(title, prefix);
return (
<Helmet>
<title>{fullTitle}</title>
{description && <meta name="description" content={description} />}
<meta property="og:title" content={fullTitle} />
{description && <meta property="og:description" content={description} />}
<meta name="twitter:title" content={fullTitle} />
{description && <meta name="twitter:description" content={description} />}
</Helmet>
);
}
/**
* Get environment prefix based on current hostname
*/
function getEnvironmentPrefix(): string | undefined {
if (typeof window === "undefined") return undefined;
const hostname = window.location.hostname;
if (hostname === "localhost" || hostname === "127.0.0.1") {
return "DEV";
}
if (!hostname.includes("getupline.com")) {
return "STAG";
}
return undefined;
}
/**
* Utility function to build title from parts
*/
function buildTitle(title?: string, prefix?: string): string {
const parts = [DEFAULT_TITLE];
if (title) {
parts.unshift(title);
}
if (prefix) {
parts.unshift(prefix);
}
const envPrefix = getEnvironmentPrefix();
if (envPrefix) {
parts.unshift(envPrefix);
}
return parts.join(TITLE_SEPARATOR);
}