From 228217e4075eed9ca4aed1ff64be00093c28676d Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Wed, 10 Apr 2024 18:24:58 +0700 Subject: improve meta, spaces to tabs, blog to markdown --- scripts/blog.js | 167 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 85 insertions(+), 82 deletions(-) (limited to 'scripts/blog.js') diff --git a/scripts/blog.js b/scripts/blog.js index cef9a28..8f36fdb 100644 --- a/scripts/blog.js +++ b/scripts/blog.js @@ -2,112 +2,115 @@ var evaluatedTags = ""; const clamp = (val, min, max) => Math.min(Math.max(val, min), max) function postList(n = 0) { - fetch("/data/posts.json") - .then((response) => response.json()) - .then((data) => { - n = clamp(n, 0, data.posts.length); - if (n < 1) { - n = data.posts.length; - } - - // i ❤ for loops - for (var i = n - 1; i >= 0; i--) { - console.log("dkfjlaafjsdk" + i) - postCard(data.posts[i]); - } - }); + fetch("/data/posts.json") + .then((response) => response.json()) + .then((data) => { + n = clamp(n, 0, data.posts.length); + if (n < 1) { + n = data.posts.length; + } + + // i ❤ for loops + for (var i = n - 1; i >= 0; i--) { + console.log("dkfjlaafjsdk" + i) + postCard(data.posts[i]); + } + }); } function postCard(post) { - var blogContainer = document.getElementById("blog-container"); - - var title = post.title; - var date = post.date; - var author = post.author; - var tags = post.tags; - var thumbnail = post.thumbnail; - var id = post.id; - - evaluatedTags = ""; - tags.forEach(createTags) - - var template = ` -
- -
-
- ${evaluatedTags} -
- ${title} -

${date}

-
-
- ` - - blogContainer.innerHTML += template; + var blogContainer = document.getElementById("blog-container"); + + var title = post.title; + var date = post.date; + var author = post.author; + var tags = post.tags; + var thumbnail = post.thumbnail; + var id = post.id; + + evaluatedTags = ""; + tags.forEach(createTags) + + var template = ` +
+ +
+
+ ${evaluatedTags} +
+ ${title} +

${date}

+
+
+ ` + + blogContainer.innerHTML += template; } function createTags(tag) { - evaluatedTags += `${tag}` + evaluatedTags += `${tag}` } function getUrlVars() { - var vars = [], hash; - var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); - for (var i = 0; i < hashes.length; i++) { - hash = hashes[i].split('='); - vars.push(hash[0]); - vars[hash[0]] = hash[1]; - } - return vars; + var vars = [], hash; + var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); + for (var i = 0; i < hashes.length; i++) { + hash = hashes[i].split('='); + vars.push(hash[0]); + vars[hash[0]] = hash[1]; + } + return vars; } // DEPENDENCIES // * /scripts/scroll.js function loadPost(n) { - const md = markdownit({ - 'html': true - }) - - fetch("/data/posts.json") - .then((response) => response.json()) - .then((data) => { - var post = data.posts[n]; - - var banner = document.getElementById("banner"); - var title = document.getElementById("title"); - var date = document.getElementById("date"); - var author = document.getElementById("author"); - var tags = document.getElementById("tag-container"); - var content = document.getElementById("content"); - - banner.src = post.banner; - title.innerHTML = post.title; - date.innerHTML = post.date; - author.innerHTML = post.author; - post.tags.forEach(createTags); - tags.innerHTML = evaluatedTags; - - fetch(post.path) - .then((response) => response.text()) + const md = markdownit({ + 'html': true + }) + + fetch("/data/posts.json") + .then((response) => response.json()) .then((data) => { - data = data.replaceAll("-+-+-+", ` + var post = data.posts[n]; + + var banner = document.getElementById("banner"); + var title = document.getElementById("title"); + var date = document.getElementById("date"); + var author = document.getElementById("author"); + var tags = document.getElementById("tag-container"); + var content = document.getElementById("content"); + + banner.src = post.banner; + title.innerHTML = post.title; + date.innerHTML = post.date; + author.innerHTML = post.author; + post.tags.forEach(createTags); + tags.innerHTML = evaluatedTags; + + document.title = `Blog / ${post.title} • altaf-creator`; + + fetch(post.path) + .then((response) => response.text()) + .then((data) => { + data = data.replaceAll("-+-+-+", `
`) - data = data.replaceAll("+-+-+-", ` + data = data.replaceAll("+-+-+-", `
`) - console.log(data); + console.log(data); - var result = md.render(data); - content.innerHTML = result; - }).then(() => addNodes()); - }); + var result = md.render(data); + result = result.replaceAll(" addNodes()); + }); } -- cgit v1.2.3