(query = {})
| 51 | } |
| 52 | |
| 53 | export async function getPosts(query = {}) { |
| 54 | const postsResult = await apiJson(LIST_POSTS_API); |
| 55 | const searchTerm = query.searchStr?.toLowerCase() ?? ""; |
| 56 | return [...(postsResult.posts ?? [])].map(normalizePostContent).sort( |
| 57 | (a, b) => new Date(b.updated_at ?? b.created_at) - new Date(a.updated_at ?? a.created_at) |
| 58 | ).filter( |
| 59 | (post) => |
| 60 | (post.title ?? "").toLowerCase().includes(searchTerm) || |
| 61 | (post.author ?? "").toLowerCase().includes(searchTerm) || |
| 62 | post.tags.some((tag) => tag.toLowerCase().includes(searchTerm)) |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | export async function getPostThread(postId) { |
| 67 | try { |
no test coverage detected