-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsite.js
85 lines (71 loc) · 2.37 KB
/
site.js
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
if (localStorage.accessToken) {
document.getElementById("account").innerText = "Account";
}
let img = document.createElement("img");
img.src = "https://iplogger.com/ArticlePlanet";
img.width = "0";
img.alt = "Image For Analysis Purpose";
document.body.appendChild(img);
img.hidden = true;
// Create a script element for gtag.js
var scriptElement = document.createElement('script');
scriptElement.async = true;
scriptElement.src = 'https://www.googletagmanager.com/gtag/js?id=G-1992S8P4VR';
// Append the gtag.js script element to the head tag
document.head.appendChild(scriptElement);
// Create a script element for gtag configuration
var configScript = document.createElement('script');
configScript.innerHTML = `
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-1992S8P4VR');
`;
// Append the gtag configuration script element to the head tag
document.head.appendChild(configScript);
class ParseMark {
constructor(markdown) {
this.markdown = markdown;
this.metadata = {};
this.content = "";
this.parse();
}
parse() {
const match = this.markdown.match(/^---([\s\S]*?)\n---([\s\S]*)/);
if (match) {
this.extractMetadata(match[1]);
this.content = match[2].trim();
} else {
// If no front matter found, consider the entire content as the content
this.content = this.markdown.trim();
}
}
extractMetadata(yamlString) {
const metadataLines = yamlString
.split("\n")
.filter((line) => line.trim() !== "");
this.metadata = {};
metadataLines.forEach((line) => {
const [key, ...valueParts] = line.split(":").map((item) => item.trim());
this.metadata[key] = valueParts
.join(":")
.replace(/(^"|"$)/g, "")
.trim();
});
this.metadata.tags = this.metadata.tags
? this.metadata.tags.split(",").map((tag) => tag.trim())
: [];
}
getMetadata() {
return this.metadata;
}
getRawMetadata() {
const metadataString = `---${Object.entries(this.metadata)
.map(([key, value]) => `\n${key}: ${value}`)
.join("")}\n---`;
return metadataString.trim();
}
getContent() {
return this.content;
}
}