diff --git a/www/src/lib/md.ts b/www/src/lib/md.ts index 573ebb9..9936ce7 100644 --- a/www/src/lib/md.ts +++ b/www/src/lib/md.ts @@ -33,10 +33,11 @@ export function enrichPostsWithDates(posts: Post[]): PostWithDates[] { return posts.map(enrichPostWithDates); } -function sortPosts(posts: PostWithDates[]): PostWithDates[] { +function sortPosts(posts: PostWithDates[], { alphabetically = false } = {}): PostWithDates[] { return posts.slice().sort((a, b) => { if (a.data.pinned && !b.data.pinned) return -1; if (!a.data.pinned && b.data.pinned) return 1; + if (alphabetically) return a.data.title.localeCompare(b.data.title); return b.dates.created.getTime() - a.dates.created.getTime(); }); } @@ -49,7 +50,7 @@ export function resolveRelatedPosts( return slugs.flatMap(s => bySlug.get(s) ?? []); } -export function organizePostsByCategory(posts: PostWithDates[]): { +export function organizePostsByCategory(posts: PostWithDates[], { sortAlphabetically = false } = {}): { grouped: Record; categories: string[]; } { @@ -67,7 +68,7 @@ export function organizePostsByCategory(posts: PostWithDates[]): { }); for (const category of categories) { - grouped[category] = sortPosts(grouped[category]); + grouped[category] = sortPosts(grouped[category], { alphabetically: sortAlphabetically }); } return { grouped, categories }; diff --git a/www/src/pages/draft/[slug].astro b/www/src/pages/private/[slug].astro similarity index 95% rename from www/src/pages/draft/[slug].astro rename to www/src/pages/private/[slug].astro index 1d13e56..b6a40d4 100644 --- a/www/src/pages/draft/[slug].astro +++ b/www/src/pages/private/[slug].astro @@ -34,7 +34,7 @@ const related = post.data.related ? resolveRelatedPosts(post.data.related, allPo {related.length > 0 && (
related -
 formatListItem(p.dates.created, `/draft/${getSlug(p.id)}`, p.data.title)).join('\n')} />
+    
 formatListItem(p.dates.created, `/private/${getSlug(p.id)}`, p.data.title)).join('\n')} />
   
)} diff --git a/www/src/pages/draft/index.astro b/www/src/pages/private/index.astro similarity index 80% rename from www/src/pages/draft/index.astro rename to www/src/pages/private/index.astro index 6f33b80..7a3c721 100644 --- a/www/src/pages/draft/index.astro +++ b/www/src/pages/private/index.astro @@ -13,19 +13,19 @@ if (!session) return Astro.redirect('/api/auth/signin'); const rawPosts = await getCollection('md', ({ data }) => data.draft === true); const posts = enrichPostsWithDates(rawPosts); -const { grouped, categories: sortedCategories } = organizePostsByCategory(posts); +const { grouped, categories: sortedCategories } = organizePostsByCategory(posts, { sortAlphabetically: true }); --- - +

logged in as {session.user?.name} sign out

{sortedCategories.length === 0 ? ( -

no drafts

+

nothing here

) : ( sortedCategories.map(category => (
{category} -
 formatListItem(post.dates.created, `/draft/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
+      
 formatListItem(post.dates.created, `/private/${getSlug(post.id)}`, post.data.title, { pinned: post.data.pinned })).join('\n')} />
     
)) )}