diff --git a/client/public/lib/remote.mjs b/client/public/lib/remote.mjs deleted file mode 100644 index a445c79..0000000 --- a/client/public/lib/remote.mjs +++ /dev/null @@ -1,24 +0,0 @@ -export async function getPosts(id) { - const BASE_URL = 'https://raymon.dev' - const BASE_ENDPOINT = '/api/posts' - const URL = BASE_URL + BASE_ENDPOINT + (id ? `/${id}` : '?sort=-1') - - let posts = [] - - return await fetch(URL) - .then(res => res.json()) - .then(res => { - if (id !== undefined) { - if (res === undefined) { - throw Error("Response body empty") - } - return [res] - } - else { - return res - } - }) - .catch(err => { - console.log(`Error: ${err}`) - }) -} diff --git a/client/public/posts.html b/client/public/posts.html index f44fd78..2944fd5 100644 --- a/client/public/posts.html +++ b/client/public/posts.html @@ -8,9 +8,6 @@ Raymon Zutekouw - - - -
diff --git a/client/public/posts.mjs b/client/public/posts.mjs deleted file mode 100644 index e6fb25d..0000000 --- a/client/public/posts.mjs +++ /dev/null @@ -1,61 +0,0 @@ -import { getPosts } from "./lib/remote.mjs" - -function toMonthYearString(str) { - const date = new Date(str) - return `${date.toLocaleString('default', { month: 'long' })} ${date.getFullYear()}` -} -async function showPost(id) { - const post_list = await getPosts(id) - const post = post_list[0] - const title = document.createElement("h1") - title.textContent = post.title - - const postsDOM = document.getElementById("posts") - postsDOM.appendChild(title) - - post.content.split('\n').forEach(paragraph => { - const p = document.createElement("p") - p.innerHTML = paragraph - postsDOM.appendChild(p) - }); -} - -async function updatePosts() { - const posts = await getPosts() - - const months = posts.map(post => toMonthYearString(post.date)) - const uniques = Array.from(new Set(posts.map(post => toMonthYearString(post.date)))) - const month_lists = uniques.map(month => - posts.filter( - post => toMonthYearString(post.date) === month - ) - ) - const postsDOM = document.getElementById("posts") - uniques.forEach((month, i) => { - const month_DOM = document.createElement("h1") - month_DOM.textContent = month - - month_lists[i].forEach((post, i) => { - const post_DOM = document.createElement("h2") - post_DOM.textContent = `${post.date.substring(0, 10)} - ` - - const post_link = document.createElement("a") - post_link.href = 'posts?post=' + post._id - post_link.textContent = post.title - post_DOM.appendChild(post_link) - - month_DOM.appendChild(post_DOM) - }) - - postsDOM.appendChild(month_DOM) - }) -} - -// Check if a specific post is requested -let url = new URL(document.location.href); -url.searchParams.sort(); -let post_id = url.searchParams.values().next().value; - -const reg = /([0-9]|[a-f]){24}/ -if (post_id && reg.test(post_id)) showPost(post_id) -else updatePosts()