-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
239 lines (223 loc) · 10.1 KB
/
index.html
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!-- HTML-->
<title>InfiniX - Realm of Gamers</title>
<meta charset="utf-8">
<link href="/tailwind-infinix-website/static/css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/tailwind-infinix-website/static/js/ghspa.js"></script>
<script>
const copyClass = (sourceElement, targetElement) => {
// Get classes from the source element
const classes = sourceElement.classList;
// Add each class to the target element
classes.forEach((className) => {
targetElement.classList.add(className);
});
};
const isRegistered = (name) => {
return document.createElement(name).constructor !== HTMLElement;
};
if (!isRegistered("blog-entry"))
window.customElements.define(
"blog-entry",
class extends HTMLElement {
connectedCallback() {
console.log("custom element loaded");
let template = this.querySelector("#template");
fetch("https://chrsrns-database.domcloud.dev/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `query {
articles {
data {
attributes {
Title
publishedAt
HeaderImg {
data {
attributes {
url
}
}
}
BlogID
}
}
}
}`,
}),
})
.then((res) => res.json())
.then((res) => {
console.log("res: ", res);
console.log("template: ", template);
let loadingSpinner = this.querySelector("loading-spinner");
loadingSpinner.remove();
for (let article of res.data.articles.data) {
let content = `
<div class="rounded-lg">
<article class="group">
<a href="/tailwind-infinix-website/blog/${article.attributes.BlogID}">
<img
alt=""
src="https://chrsrns-database.domcloud.dev${article.attributes.HeaderImg.data.attributes.url}"
class="w-full rounded-lg object-cover shadow-xl transition group-hover:grayscale-[50%]"
/>
</a>
<div class="p-4">
<a href="/tailwind-infinix-website/blog/${article.attributes.BlogID}">
<h3 class="text-lg font-medium text-gray-900">
${article.attributes.Title}
</h3>
</a>
</div>
<div class="px-4 pb-4">
<a href="/tailwind-infinix-website/blog/${article.attributes.BlogID}">
<button class="bg-yellow-500 hover:bg-yellow-700 text-gray-900 font-medium py-2 px-4 rounded">
Visit Page
</button>
</a>
</div>
</article>
</div>
`;
let clone = template.cloneNode(false);
clone.removeAttribute("id");
clone.classList.remove("hidden");
clone.innerHTML = content;
this.appendChild(clone);
}
template.remove();
});
}
},
);
if (!isRegistered("blog-post")) {
window.customElements.define(
"blog-post",
class extends HTMLElement {
connectedCallback() {
const blogHeader = this.querySelector("#blog-header");
const blogHeaderText = this.querySelector("#header-text");
const blogContents = this.querySelector("#blog-contents");
const blogUID = window.location.pathname
.split("/")
.filter((n) => n)[2];
console.log(blogHeader);
console.log(blogHeaderText);
console.log(blogContents);
console.log("UID: ", blogUID);
fetch("https://chrsrns-database.domcloud.dev/graphql", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
query: `
query {
articles (filters: {BlogID: {eq: "${blogUID}" }}) {
data {
attributes {
Title
publishedAt
HeaderImg {
data {
attributes {
url
}
}
}
Content
}
}
}
}
`,
}),
})
.then((res) => res.json())
.then((res) => {
console.log("res: ", res);
const content = res.data.articles.data[0].attributes.Content;
const title = res.data.articles.data[0].attributes.Title;
const headerURL =
res.data.articles.data[0].attributes.HeaderImg.data
.attributes.url;
blogHeaderText.innerHTML = title;
blogHeader.style.backgroundImage = `url(https://chrsrns-database.domcloud.dev${headerURL})`;
let concatContent = "";
for (let contentItem of content) {
switch (contentItem.type) {
case "heading":
{
if (contentItem.level >= 6) contentItem.level = 5;
const newHeading = document.createElement(
`h${contentItem.level + 1}`,
);
const tmplHeading = this.querySelector(
`#blog-h${contentItem.level + 1}`,
);
newHeading.innerHTML = contentItem.children[0].text;
copyClass(tmplHeading, newHeading);
console.log("template heading: ", tmplHeading);
console.log("new heading: ", newHeading);
blogContents.appendChild(newHeading);
}
break;
case "paragraph":
{
const newParagraph = document.createElement(`p`);
const tmplParagraph = this.querySelector(`#blog-p`);
newParagraph.innerHTML = contentItem.children[0].text;
copyClass(tmplParagraph, newParagraph);
console.log("template p: ", tmplParagraph);
console.log("new p: ", newParagraph);
blogContents.appendChild(newParagraph);
}
break;
}
if (contentItem.type === "paragraph")
concatContent += `<p>${contentItem.children[0].text}</p>`;
}
console.log("content: ", content);
});
}
},
);
}
</script>
<div class="flex flex-col h-screen">
<!-- HTML-->
<nav style="background-color: rgba(251, 140, 0, 1)" class="w-full shadow-lg text-sm py-3 z-50">
<center>
<div class="flex flex-row m-auto items-center justify-center">
<div class="basis-2/5 flex flex-row-reverse gap-6 px-6">
<div><a href="/tailwind-infinix-website/library" class="navlink">
<div class="transition ease-in-out delay-150 hover:-translate-y-1 hover:scale-110 hover:bg-secondary duration-300 text-lg bg-primary align-middle inline-block box-border text-center my-0 px-2 rounded-md shadow-lg p-2">
Library
</div>
</a></div>
</div>
<div style="width: 12rem" class="flex-none relative h-full">
<a href="/tailwind-infinix-website/" class="navlink absolute inset-x-0 -top-12">
<div class="group transition ease-in-out delay-150 bg-[length:200%_200%] bg-gradient-to-bl from-yellow-400 via-white to-yellow-400 from-45% via-50% to-55% hover:scale-110 animate-btngradientflow duration-300 text-lg bg-primary align-middle inline-block box-border text-center my-0 rounded-md shadow-lg rounded-b-full">
<div class="px-2 pt-6 pb-2 transition-all ease-in-out delay-150 duration-300 bg-primary rounded-md rounded-b-full group-hover:bg-opacity-0">
<img id="navLogo" src="/tailwind-infinix-website/static/media/Logo_Original.png" width="100%">
</div>
</div>
</a>
</div>
<div class="basis-2/5 flex flex-row gap-6 px-6">
<div><a href="/tailwind-infinix-website/about" class="navlink">
<div class="transition ease-in-out delay-150 hover:-translate-y-1 hover:scale-110 hover:bg-secondary duration-300 text-lg bg-primary align-middle inline-block box-border text-center my-0 px-2 rounded-md shadow-lg p-2">
About
</div>
</a></div>
</div>
</div>
</center>
</nav>
<div id="content" class="overflow-scroll flex-grow"></div>
<script src="/tailwind-infinix-website/static/js/router.js"></script>
</div>