2023-08-10 21:47:28 +00:00
|
|
|
import API from "./API";
|
2023-08-10 13:19:11 +00:00
|
|
|
import UI from "./UI";
|
2023-08-10 21:47:28 +00:00
|
|
|
import Input from "./Input";
|
2023-08-11 16:15:21 +00:00
|
|
|
import Author from "./Author";
|
2023-09-24 16:03:06 +00:00
|
|
|
import BlogPost from "./BlogPost";
|
2023-08-10 03:56:12 +00:00
|
|
|
|
2023-08-10 13:36:51 +00:00
|
|
|
declare const Handlebars: any;
|
2023-08-10 22:28:23 +00:00
|
|
|
declare const Prism: any;
|
2023-08-04 11:55:16 +00:00
|
|
|
|
|
|
|
(() => {
|
2023-08-10 22:28:23 +00:00
|
|
|
Prism.languages.extend('markup', {});
|
2023-08-13 23:58:32 +00:00
|
|
|
Prism.languages.hex = {
|
|
|
|
'number': {
|
2023-08-16 14:17:05 +00:00
|
|
|
pattern: /(?:[a-fA-F0-9]{3}){1,2}\b/i,
|
2023-08-13 23:58:32 +00:00
|
|
|
lookbehind: true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Prism.languages.binary = {
|
|
|
|
'number': {
|
|
|
|
pattern: /[10]+/i,
|
|
|
|
lookbehind: true
|
|
|
|
}
|
|
|
|
};
|
2023-08-10 22:28:23 +00:00
|
|
|
Prism.languages.insertBefore('custom', 'tag', {
|
|
|
|
'mark': {
|
|
|
|
pattern: /<\/?mark(?:\s+\w+(?:=(?:"[^"]*"|'[^']*'|[^\s'">=]+))?\s*|\s*)\/?>/,
|
|
|
|
greedy: true
|
|
|
|
}
|
|
|
|
});
|
2023-08-11 01:08:48 +00:00
|
|
|
|
2023-09-24 16:03:06 +00:00
|
|
|
function getQueryVariable(variable: string): string {
|
|
|
|
const query = window.location.search.substring(1);
|
|
|
|
const vars = query.split("&");
|
|
|
|
for (const element of vars) {
|
|
|
|
const pair = element.split("=");
|
|
|
|
if (pair[0] == variable) {
|
|
|
|
return pair[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-08-10 21:47:28 +00:00
|
|
|
Input.registerShortcut(Input.KONAMI_CODE, () => {
|
|
|
|
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
|
|
|
|
});
|
|
|
|
|
2023-08-13 16:33:54 +00:00
|
|
|
const blogPost = UI.blogPost;
|
|
|
|
if (blogPost) {
|
|
|
|
const id = blogPost.dataset.blogId;
|
|
|
|
API.getBlogPost(id).then((post) => {
|
|
|
|
blogPost.innerHTML = post.content;
|
|
|
|
UI.updateUI(blogPost);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-10 13:19:11 +00:00
|
|
|
const blogPostContainer = UI.blogPostContainer;
|
2023-08-10 03:56:12 +00:00
|
|
|
if (blogPostContainer) {
|
2023-08-11 16:15:21 +00:00
|
|
|
const authors = [];
|
2023-08-10 13:36:51 +00:00
|
|
|
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);
|
2023-08-10 03:56:12 +00:00
|
|
|
API.getBlogPostCount().then(async (count) => {
|
2023-08-13 14:24:24 +00:00
|
|
|
for (let i = 0; i <= count / 10; i++) {
|
2023-09-24 16:03:06 +00:00
|
|
|
let posts: BlogPost[];
|
|
|
|
|
|
|
|
const tag = getQueryVariable("tag");
|
|
|
|
if (tag !== null) {
|
|
|
|
posts = await API.getBlogPostsByTag(tag, i);
|
|
|
|
} else {
|
|
|
|
posts = await API.getBlogPosts(i);
|
|
|
|
}
|
|
|
|
|
2023-08-10 03:56:12 +00:00
|
|
|
for (const post of posts) {
|
2023-08-11 16:15:21 +00:00
|
|
|
let author: Author;
|
|
|
|
if (authors[post.authorId]) {
|
|
|
|
author = authors[post.authorId];
|
|
|
|
} else {
|
|
|
|
author = await API.getAuthor(post.authorId);
|
|
|
|
authors[post.authorId] = author;
|
|
|
|
}
|
|
|
|
|
2023-08-10 15:18:24 +00:00
|
|
|
const card = UI.createBlogPostCard(template, post, author);
|
2023-08-10 03:56:12 +00:00
|
|
|
blogPostContainer.appendChild(card);
|
2023-08-10 14:31:51 +00:00
|
|
|
UI.updateUI(card);
|
2023-08-10 03:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-10 03:57:17 +00:00
|
|
|
|
2023-08-10 15:14:30 +00:00
|
|
|
document.body.appendChild(UI.createDisqusCounterScript());
|
|
|
|
|
2023-08-10 13:32:56 +00:00
|
|
|
const spinner = document.querySelector("#blog-loading-spinner");
|
2023-08-10 03:56:12 +00:00
|
|
|
if (spinner) {
|
|
|
|
spinner.classList.add("removed");
|
2023-08-11 01:08:48 +00:00
|
|
|
setTimeout(() => spinner.remove(), 1000);
|
2023-08-10 03:56:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-08-10 14:15:06 +00:00
|
|
|
UI.updateUI();
|
2023-08-04 11:55:16 +00:00
|
|
|
})();
|