1 import { getCollection, type CollectionEntry } from 'astro:content'
2
3 /**
4 * Get all posts, filtering out posts whose filenames start with _ and static pages
5 */
6 export async function getFilteredPosts() {
7 const posts = await getCollection('posts')
8 const staticPages = ['privacy-policy', 'terms-of-use']
9 const unpublishedPages = ['why-learn-persian', 'terms-of-use']
10 return posts.filter(
11 (post) =>
12 !post.id.startsWith('_') &&
13 !staticPages.includes(post.id) &&
14 !unpublishedPages.includes(post.id)
15 )
16 }
17
18 /**
19 * Get all posts sorted by publication date, filtering out posts whose filenames start with _
20 */
21 export async function getSortedFilteredPosts() {
22 const posts = await getFilteredPosts()
23 return posts.sort(
24 (a: CollectionEntry<'posts'>, b: CollectionEntry<'posts'>) =>
25 b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
26 )
27 }