flatten monorepo, migrate off Vercel
- Remove penfield (split to own repo on Forgejo) - Move www/ contents to root, rename to wynne.rs - Swap @astrojs/vercel for @astrojs/node, upgrade to Astro 6 - Remove auth-astro/GitHub OAuth (TinyAuth at proxy layer) - Remove Vercel deploy webhook - Switch to local SQLite DB (drop Turso) - Update generate-stats.js for new build output paths
This commit is contained in:
parent
f2acf36784
commit
8a9c56c3d5
52 changed files with 45 additions and 7135 deletions
42
src/lib/posts.ts
Normal file
42
src/lib/posts.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import type { CollectionEntry } from 'astro:content';
|
||||
import { DEFAULT_CATEGORY } from './consts';
|
||||
import { sortEntries } from './format';
|
||||
|
||||
export type Post = CollectionEntry<'posts'> & { body?: string };
|
||||
|
||||
export function getSlug(postId: string): string {
|
||||
const parts = postId.split('/');
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
|
||||
export function resolveRelatedPosts<T extends { id: string }>(
|
||||
slugs: string[],
|
||||
allPosts: T[],
|
||||
): T[] {
|
||||
const bySlug = new Map(allPosts.map(p => [getSlug(p.id), p]));
|
||||
return slugs.flatMap(s => bySlug.get(s) ?? []);
|
||||
}
|
||||
|
||||
export function organizePostsByCategory(posts: Post[]): {
|
||||
grouped: Record<string, Post[]>;
|
||||
categories: string[];
|
||||
} {
|
||||
const grouped = posts.reduce((acc, post) => {
|
||||
const category = post.data.category ?? DEFAULT_CATEGORY;
|
||||
if (!acc[category]) acc[category] = [];
|
||||
acc[category].push(post);
|
||||
return acc;
|
||||
}, {} as Record<string, Post[]>);
|
||||
|
||||
const categories = Object.keys(grouped).sort((a, b) => {
|
||||
if (a === DEFAULT_CATEGORY) return -1;
|
||||
if (b === DEFAULT_CATEGORY) return 1;
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
|
||||
for (const category of categories) {
|
||||
grouped[category] = sortEntries(grouped[category], p => p.data);
|
||||
}
|
||||
|
||||
return { grouped, categories };
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue