Remove js for posts page
This commit is contained in:
@@ -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}`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -8,9 +8,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Raymon Zutekouw</title>
|
<title>Raymon Zutekouw</title>
|
||||||
|
|
||||||
<link rel="preload" href="./lib/remote.mjs" as="script" crossorigin="anonymous" type="application/javascript">
|
|
||||||
<link rel="preload" href="posts.mjs" as="script" crossorigin="anonymous" type="application/javascript">
|
|
||||||
|
|
||||||
<link defer
|
<link defer
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn.statically.io/gh/dragonprojects/dragondesign/master/main.min.css"
|
href="https://cdn.statically.io/gh/dragonprojects/dragondesign/master/main.min.css"
|
||||||
@@ -20,12 +17,6 @@
|
|||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<noscript>
|
|
||||||
<p>
|
|
||||||
This page isn't as fancy without JavaScript.
|
|
||||||
Some parts will not load, but this will be minimal.
|
|
||||||
</p>
|
|
||||||
</noscript>
|
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<nav>
|
<nav>
|
||||||
<a href="/">Home</a>|
|
<a href="/">Home</a>|
|
||||||
@@ -36,7 +27,6 @@
|
|||||||
<h3>For those using a RSS reader, subscribe here: <a href="/api/posts/rss.xml">rss.xml</a></h3>
|
<h3>For those using a RSS reader, subscribe here: <a href="/api/posts/rss.xml">rss.xml</a></h3>
|
||||||
<!-- Placeholder for posts -->
|
<!-- Placeholder for posts -->
|
||||||
<div id="posts"></div>
|
<div id="posts"></div>
|
||||||
<script async type="module" src="posts.mjs"></script>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -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()
|
|
||||||
Reference in New Issue
Block a user