-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.ts
77 lines (71 loc) · 2.3 KB
/
utils.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
import { Metadata } from "./interfaces"
export function urlReplacer(string:string){
return string
.toLocaleLowerCase()
.replaceAll(" ", "_")
.replaceAll("?", "")
.replaceAll("ü", "u")
.replaceAll("ö", "o")
.replaceAll("ä", "a")
}
export function stringReplacer(string:string){
const removeLinks = new RegExp("(<a|</a)\.*?>", "g")
const removeEmphasis = new RegExp("(<em|</em)\.*?>", "g")
return string
.replaceAll("ü", "ü")
.replaceAll("ä", "ä")
.replaceAll("ö", "ö")
.replaceAll("Ü", "Ü")
.replaceAll("Ä", "Ä")
.replaceAll("Ö", "Ö")
.replaceAll("–", "-")
.replaceAll("…", "...")
.replaceAll("&", "&")
.replaceAll("<p>", "")
.replaceAll("</p>", "")
.replaceAll("<blockquote>", "\"")
.replaceAll("</blockquote>", "\"")
.replaceAll("<br>", "\n\r")
.replaceAll("<ul>", "")
.replaceAll("</ul>", "")
.replaceAll("<li>", "| ")
.replaceAll("</li>", " |")
.replaceAll(" ", " ")
.replaceAll(removeLinks, "")
.replaceAll(removeEmphasis, "")
}
export async function pageMetadata(pageName:string){
const getMetadata: Response = await fetch(
`https://cms.mrweber.ch/api/content/item/taglines?filter=%7Bpage%3A%22${pageName}%22%7D&populate=1`,
{
headers: {
'api-key': `${process.env.COCKPIT}`,
},
}
)
const metadata:Metadata = await getMetadata.json()
return {
title: metadata.title,
description: metadata.description,
openGraph: {
title: metadata.title,
description: metadata.description,
images: [
{
url: metadata.image ? `https://cms.mrweber.ch/storage/uploads/${metadata.image.path}` : "./sd_mrweber3.jpg",
}
],
locale: 'de_CH',
type: 'website',
},
icons: {
icon: '/sd_mrweber3.png',
shortcut: '/sd_mrweber3.png',
apple: '/sd_mrweber3.png',
other: {
rel: 'apple-touch-icon-precomposed',
url: '/sd_mrweber3.png',
},
},
}
}