added message when no post

This commit is contained in:
J-onasJones 2024-06-16 20:27:04 +02:00
parent c2ba40c8aa
commit 94b9f6637d

View file

@ -12,12 +12,20 @@
let error = false;
let loading = true;
let noPostMessage = '';
onMount(async () => {
try {
const response = await fetch('https://cdn.jonasjones.dev/blog/index.json');
posts = await response.json();
if (posts.length === 0) {
loading = false;
noPostMessage = 'No posts found :/';
return;
} else {
// for each post, conver the date string to a Date object
posts.forEach(post => {
post.date = new Date(post.date);
@ -28,6 +36,7 @@
// sort the posts by date
filteredPosts.sort((a, b) => b.date - a.date);
loading = false;
}
} catch (error) {
console.error(error);
error = true;
@ -42,6 +51,7 @@
{#if error}
<NotFound />
{:else}
<h2 style="text-align: center;">{noPostMessage}</h2>
<div class="postList">
{#each filteredPosts as post}
<div class="postDiv">