Initial rewrite
This commit is contained in:
parent
a5f64a3ff8
commit
0d183c8335
200 changed files with 12537 additions and 18659 deletions
71
src/lib/site.ts
Normal file
71
src/lib/site.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { getCollection } from 'astro:content';
|
||||
|
||||
export const site = {
|
||||
name: 'Andras Schmelczer',
|
||||
title: 'Andras Schmelczer',
|
||||
description:
|
||||
'Andras Schmelczer writes about software systems, AI deployment, graphics, simulations, and tools.',
|
||||
url: 'https://schmelczer.dev',
|
||||
email: 'andras@schmelczer.dev',
|
||||
github: 'https://github.com/schmelczer',
|
||||
linkedin: 'https://www.linkedin.com/in/andras-schmelczer',
|
||||
cv: '/media/downloads/cv-andras-schmelczer.pdf',
|
||||
};
|
||||
|
||||
export function formatDate(date: Date) {
|
||||
return new Intl.DateTimeFormat('en', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
}).format(date);
|
||||
}
|
||||
|
||||
export function yearOf(date: Date) {
|
||||
return new Intl.DateTimeFormat('en', { year: 'numeric' }).format(date);
|
||||
}
|
||||
|
||||
export function entrySlug(entry: { id: string }) {
|
||||
return entry.id.replace(/\.mdx?$/, '').replace(/\/index$/, '');
|
||||
}
|
||||
|
||||
export function articlePath(entry: { id: string } | string) {
|
||||
const slug = typeof entry === 'string' ? entry : entrySlug(entry);
|
||||
return `/articles/${slug}/`;
|
||||
}
|
||||
|
||||
export function tagSlug(tag: string) {
|
||||
return tag
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, '-')
|
||||
.replace(/^-|-$/g, '');
|
||||
}
|
||||
|
||||
export function tagPath(tag: string) {
|
||||
return `/tags/${tagSlug(tag)}/`;
|
||||
}
|
||||
|
||||
export function formatTag(tag: string) {
|
||||
return tag;
|
||||
}
|
||||
|
||||
export function getAllTags(posts: { data: { tags: string[] } }[]) {
|
||||
return [...new Set(posts.flatMap((post) => post.data.tags))].sort((a, b) =>
|
||||
a.localeCompare(b)
|
||||
);
|
||||
}
|
||||
|
||||
export async function getPublishedPosts() {
|
||||
return (await getCollection('posts'))
|
||||
.filter((post) => !post.data.draft)
|
||||
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());
|
||||
}
|
||||
|
||||
export async function getProjects() {
|
||||
return (await getCollection('projects')).sort(
|
||||
(a, b) => b.data.sortDate.valueOf() - a.data.sortDate.valueOf()
|
||||
);
|
||||
}
|
||||
|
||||
export function absoluteUrl(path: string) {
|
||||
return new URL(path, site.url).toString();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue