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-08-10 03:56:12 +00:00
|
|
|
|
2023-08-10 21:48:08 +00:00
|
|
|
const pkg = require("../../package.json");
|
|
|
|
|
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', {});
|
|
|
|
Prism.languages.insertBefore('custom', 'tag', {
|
|
|
|
'mark': {
|
|
|
|
pattern: /<\/?mark(?:\s+\w+(?:=(?:"[^"]*"|'[^']*'|[^\s'">=]+))?\s*|\s*)\/?>/,
|
|
|
|
greedy: true
|
|
|
|
}
|
|
|
|
});
|
2023-08-11 01:08:48 +00:00
|
|
|
|
2023-08-10 21:48:08 +00:00
|
|
|
let isCtrl = false;
|
|
|
|
document.addEventListener('keyup', (e) => {
|
|
|
|
if (e.ctrlKey) isCtrl = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
document.addEventListener('keydown', (e) => {
|
|
|
|
if (e.ctrlKey) isCtrl = true;
|
|
|
|
if (isCtrl && e.key === "u") {
|
|
|
|
window.open(pkg.repository.url, "_blank");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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-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-11 16:15:39 +00:00
|
|
|
for (let i = 0; i < count; i += 5) {
|
2023-08-10 03:56:12 +00:00
|
|
|
const posts = await API.getBlogPosts(i, 5);
|
|
|
|
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
|
|
|
})();
|