the horrors

This commit is contained in:
Laker Turner 2025-03-17 12:49:54 +00:00
parent 0d9be3d002
commit 4245370f61
No known key found for this signature in database
48 changed files with 2513 additions and 265 deletions

41
src/lib/blog.ts Normal file
View file

@ -0,0 +1,41 @@
import siteConfig from "~/site.config";
import type { CollectionEntry } from "astro:content";
type PostWithDate = {
data: {
date: Date;
};
};
const sortByDateDescending = <T extends PostWithDate>(posts: T[]): T[] => {
return posts.sort((a, b) =>
isDateBefore(a.data.date, b.data.date) ? 1 : -1
);
};
const filterPublishedPosts = <T extends { data: { draft?: boolean } }>(
posts: T[]
): T[] => {
if (import.meta.env.PROD) {
return posts.filter((post) => !post.data.draft);
}
return siteConfig.devMode.showDraftPages
? posts
: posts.filter((post) => !post.data.draft);
};
export const getPublishedAndSortedPosts = (
allPosts: CollectionEntry<"blog">[]
): CollectionEntry<"blog">[] => {
return sortByDateDescending(filterPublishedPosts(allPosts));
};
export const getPublishedAndSortedNotes = (
allPosts: CollectionEntry<"notes">[]
): CollectionEntry<"notes">[] => {
return sortByDateDescending(allPosts);
};
// helper function to check if date1 is before date2
export const isDateBefore = (date1: Date, date2: Date): boolean =>
date1.getTime() < date2.getTime();

33
src/lib/fun.ts Normal file
View file

@ -0,0 +1,33 @@
// all the code for making fun stuff happen
const flavourText = [
"LOVE YOURSELF",
"Hack the planet!",
"all your base are belong to us!",
"must construct additional pylons",
"Everybody's dead, Dave.",
"Stay strange and be ace -- Yard Act",
"I'm a rocketman!",
"It's a fixer-upper!",
"💜",
"Sibelius crashed",
"All toasters toast toast",
"Trans rights are human rights!",
":wq",
];
export function getFlavourText() {
return flavourText[Math.floor(Math.random() * flavourText.length)];
}
export function isBirthday() {
const today = new Date();
const birthday = new Date(today.getFullYear(), 3, 13);
const check =
today.getMonth() === birthday.getMonth() &&
today.getDate() === birthday.getDate();
console.log(check);
return check;
}

17
src/lib/metadata.ts Normal file
View file

@ -0,0 +1,17 @@
import conf from "~/site.config";
// todo: add blog detection
export const titleConstructor = (title: string) => {
if (!title) return conf.siteName;
return `${title} | ${conf.siteName}`;
};
export const descriptionConstructor = (description: string) => {
if (!description) return conf.description;
return `${description}`;
};
export const noteTitleConstructor = (title: string, date: Date) => {
if (title) return title;
return `A note from ${date.toLocaleDateString()}`;
};

0
src/lib/util.ts Normal file
View file