-
Notifications
You must be signed in to change notification settings - Fork 8
/
redirects.ts
98 lines (89 loc) · 2.36 KB
/
redirects.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { getClient } from '../../lib/sanity.server'
import { redirects, externalRedirects, RedirectsType, ExternalRedirectsType } from '../../lib/queries/redirects'
export const getRedirectUrl = async (slug: string, locale: string): Promise<RedirectsType> => {
return getClient(false).fetch(redirects, { slug: slug, slugWithLocale: `/${locale}${slug}` })
}
export const getExternalRedirectUrl = async (slug: string, locale: string): Promise<ExternalRedirectsType> => {
return getClient(false).fetch(externalRedirects, { slug: slug, slugWithLocale: `/${locale}${slug}` })
}
export const getWWWRedirect = (host: string, pathname: string): string | undefined => {
if (!host.includes("www")) {
return `https://www.${host}${pathname}`;
}
return undefined;
};
export const getDnsRedirect = (host: string, pathname: string) => {
const dns = host.replace('http://', '').replace('https://', '').replace('www.', '')
if (dns === 'statoil.com') {
return `https://www.equinor.com${pathname}`
}
if (dns === 'equinor.kr') {
return `https://www.equinor.co.kr${pathname}`
}
const redirect =
dnsRedirects.find((redirect) => redirect.from === dns + pathname) ||
dnsRedirects.find((redirect) => redirect.from === dns)
return redirect && `https://www.equinor.com${redirect.to}`
}
const dnsRedirects = [
{
from: 'equinor.co.uk/mariner',
to: '/en/energy/mariner',
},
{
from: 'equinor.co.uk',
to: '/en/where-we-are/united-kingdom',
},
{
from: 'equinorpensjon.no',
to: '/no/om-oss/equinor-pensjon',
},
{
from: 'statoilpensjon.no',
to: '/no/om-oss/equinor-pensjon',
},
{
from: 'equinor.co.tz',
to: '/en/where-we-are/tanzania',
},
{
from: 'statoil.co.tz',
to: '/en/where-we-are/tanzania',
},
{
from: 'equinor.no',
to: '/no',
},
{
from: 'equinorventures.com',
to: '/en/energy/ventures',
},
{
from: 'h2hsaltend.co.uk',
to: '/en/energy/h2h-saltend',
},
{
from: 'equinor.ca',
to: '/en/where-we-are/canada',
},
{
from: 'techstars.equinor.com',
to: '/en/energy/techstars',
},
{
from: 'equinor.com.au',
to: '/en/where-we-are/australia',
},
{
from: 'digitalfieldworker.equinor.com',
to: '/energy/digitalfieldworker',
},
{
from: 'eu2nsea.com',
to: '/energy/eu2nsea',
},
{
from: 'eu2nsea.eu',
to: '/energy/eu2nsea',
},
]