feat: add Dream Home Template project and improve SEO

feat: improve recent posts to show random posts

refactor: improve image sizes for project details page

chore(package.json): upgrade dependencies
This commit is contained in:
cojocaru-david
2025-05-29 15:24:12 +03:00
parent e22d9296e9
commit 5e0055ab69
7 changed files with 674 additions and 1042 deletions

View File

@@ -7,11 +7,32 @@ export async function getAllPosts(): Promise<CollectionEntry<'blog'>[]> {
.sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf())
}
function getDayKey(date: string | Date): string {
const d = new Date(date)
return d.toISOString().split('T')[0]
}
export async function getRecentPosts(
count: number,
): Promise<CollectionEntry<'blog'>[]> {
const posts = await getAllPosts()
return posts.slice(0, count)
const postsByDay = posts.reduce<Record<string, CollectionEntry<'blog'>[]>>((acc, post) => {
const key = getDayKey(post.data.date)
if (!acc[key]) {
acc[key] = []
}
acc[key].push(post)
return acc
}, {})
const randomPostsPerDay = Object.values(postsByDay).map(postsForDay => {
const randomIndex = Math.floor(Math.random() * postsForDay.length)
return postsForDay[randomIndex]
})
const shuffled = randomPostsPerDay.sort(() => Math.random() - 0.5)
return shuffled.slice(0, count)
}
export async function getAdjacentPosts(currentId: string): Promise<{