BlogEngine: Rewrite stapline for the blog
This commit is contained in:
parent
d06a0fb350
commit
c9dd7145f0
2 changed files with 47 additions and 35 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PageData } from "./$types";
|
import type { PageData } from "./$types.js";
|
||||||
import Navbar from "$lib/components/Navbar.svelte";
|
import Navbar from "$lib/components/Navbar.svelte";
|
||||||
import { intlFormat } from "date-fns";
|
import { intlFormat } from "date-fns";
|
||||||
|
|
||||||
|
|
@ -11,7 +11,8 @@
|
||||||
numberOfPosts,
|
numberOfPosts,
|
||||||
daysSinceLastPublish,
|
daysSinceLastPublish,
|
||||||
daysSinceFirstPost,
|
daysSinceFirstPost,
|
||||||
averageDaysBetweenPosts
|
averageDaysBetweenPosts,
|
||||||
|
numberOfBlogPostsThisYear
|
||||||
} = data);
|
} = data);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
@ -46,18 +47,23 @@
|
||||||
<section class="thomaswilson-strapline section">
|
<section class="thomaswilson-strapline section">
|
||||||
<h1>Blog</h1>
|
<h1>Blog</h1>
|
||||||
<p>
|
<p>
|
||||||
I write about software and I how I should have built it, books I've read,
|
It has been been
|
||||||
and sometimes other things.
|
<span
|
||||||
</p>
|
|
||||||
<p>
|
|
||||||
It's been <span
|
|
||||||
class="days-since"
|
class="days-since"
|
||||||
class:days-since-success={daysSinceLastPublish === 0}
|
class:days-since-success={daysSinceLastPublish === 0}
|
||||||
>
|
>
|
||||||
{daysSinceLastPublish}
|
{daysSinceLastPublish}
|
||||||
</span>
|
</span>
|
||||||
{daysSinceLastPublish === 1 ? "day" : "days"} since I last published something.
|
{daysSinceLastPublish === 1 ? "day" : "days"} since I last published something.
|
||||||
On average I publish something every {averageDaysBetweenPosts} days ({numberOfPosts}
|
</p>
|
||||||
|
<p>
|
||||||
|
I write about fun software I've built alone, Real Software™ I built in
|
||||||
|
teams, books I read, things I am sewing, and other things.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
I have written {numberOfBlogPostsThisYear}
|
||||||
|
{numberOfBlogPostsThisYear === 1 ? "piece" : "pieces"} so far this year. On
|
||||||
|
average I publish something every {averageDaysBetweenPosts} days ({numberOfPosts}
|
||||||
posts in {daysSinceFirstPost} days).
|
posts in {daysSinceFirstPost} days).
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
import type { LoadEvent, Load, Page } from '@sveltejs/kit';
|
import type { LoadEvent } from '@sveltejs/kit';
|
||||||
import { differenceInCalendarDays, intlFormat } from 'date-fns';
|
import { differenceInCalendarDays, getYear } from 'date-fns';
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
type BlogPost = {
|
interface BlogPostListItem {
|
||||||
filename: string;
|
|
||||||
preview: string[];
|
|
||||||
title: string;
|
title: string;
|
||||||
|
author: string;
|
||||||
|
book_review: boolean;
|
||||||
|
content: string;
|
||||||
|
date: string;
|
||||||
|
preview: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
date: Date;
|
}
|
||||||
book_review?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export async function load({ fetch }: LoadEvent) {
|
export async function load({ fetch }: LoadEvent) {
|
||||||
const posts = await fetch('/api/blog.json')
|
const posts: BlogPostListItem[] = await fetch('/api/blog.json')
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
.then((res) => res.posts);
|
.then((res) => res.posts);
|
||||||
|
|
||||||
|
const currentYear = getYear(new Date());
|
||||||
const mostRecentPost = posts[0];
|
const mostRecentPost = posts[0];
|
||||||
|
|
||||||
const daysSinceLastPublish = differenceInCalendarDays(new Date(), new Date(mostRecentPost.date));
|
const daysSinceLastPublish = differenceInCalendarDays(new Date(), new Date(mostRecentPost.date));
|
||||||
|
|
@ -24,6 +26,9 @@ export async function load({ fetch }: LoadEvent) {
|
||||||
const firstPost = posts[numberOfPosts - 1];
|
const firstPost = posts[numberOfPosts - 1];
|
||||||
const daysSinceFirstPost = differenceInCalendarDays(new Date(), new Date(firstPost.date));
|
const daysSinceFirstPost = differenceInCalendarDays(new Date(), new Date(firstPost.date));
|
||||||
const averageDaysBetweenPosts = Number(daysSinceFirstPost / numberOfPosts).toFixed(2);
|
const averageDaysBetweenPosts = Number(daysSinceFirstPost / numberOfPosts).toFixed(2);
|
||||||
|
const numberOfBlogPostsThisYear: number = posts.filter(
|
||||||
|
(post) => getYear(new Date(post.date)) === currentYear
|
||||||
|
).length;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
posts,
|
posts,
|
||||||
|
|
@ -31,6 +36,7 @@ export async function load({ fetch }: LoadEvent) {
|
||||||
averageDaysBetweenPosts,
|
averageDaysBetweenPosts,
|
||||||
daysSinceFirstPost,
|
daysSinceFirstPost,
|
||||||
daysSinceLastPublish,
|
daysSinceLastPublish,
|
||||||
numberOfPosts
|
numberOfPosts,
|
||||||
|
numberOfBlogPostsThisYear,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue