From df510781dd36f8361841502a8b8c3c3a7d523c2e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 28 Oct 2024 08:30:50 -0400 Subject: [PATCH] pin announcement blog post --- .../content/blog/2024-10-22-svelte-5-is-alive.md | 1 + apps/svelte.dev/src/lib/server/content.ts | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/svelte.dev/content/blog/2024-10-22-svelte-5-is-alive.md b/apps/svelte.dev/content/blog/2024-10-22-svelte-5-is-alive.md index a0d3af931d..7cc8e1e008 100644 --- a/apps/svelte.dev/content/blog/2024-10-22-svelte-5-is-alive.md +++ b/apps/svelte.dev/content/blog/2024-10-22-svelte-5-is-alive.md @@ -3,6 +3,7 @@ title: Svelte 5 is alive description: Our biggest release yet author: The Svelte team authorURL: https://svelte.dev/ +pinnedUntil: 2024-11-15 --- After almost 18 months of development, comprising thousands of commits from dozens of contributors, Svelte 5 is finally stable. diff --git a/apps/svelte.dev/src/lib/server/content.ts b/apps/svelte.dev/src/lib/server/content.ts index 718731afe0..faa960ec07 100644 --- a/apps/svelte.dev/src/lib/server/content.ts +++ b/apps/svelte.dev/src/lib/server/content.ts @@ -24,6 +24,9 @@ function format_date(date: string) { return `${months[+m - 1]} ${+d} ${y}`; } +const now = new Date(); +const today = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, '0')}-${String(now.getDate()).padStart(2, '0')}`; + export const blog_posts = index.blog.children .map((post) => { const authors: Array<{ name: string; url: string }> = []; @@ -45,10 +48,17 @@ export const blog_posts = index.blog.children ...post, date, date_formatted: format_date(date), - authors + authors, + pinned: post.metadata.pinnedUntil ? post.metadata.pinnedUntil > today : false }; }) - .sort((a, b) => (a.date < b.date ? 1 : -1)); + .sort((a, b) => { + if (!!a.pinned !== !!b.pinned) { + return a.pinned ? -1 : 1; + } + + return a.date < b.date ? 1 : -1; + }); /** * Create docs index, which is basically the same structure as the original index