| 5 | } |
| 6 | |
| 7 | export const fetchPost = async slug => { |
| 8 | const posts = await readIndex() |
| 9 | const currentIndex = posts.findIndex(post => post.id === slug) |
| 10 | |
| 11 | if (currentIndex === -1) { |
| 12 | return null |
| 13 | } |
| 14 | |
| 15 | const post = await import(`../public/content/${slug}.json`) |
| 16 | const { content, level, title } = post |
| 17 | |
| 18 | const prev = currentIndex > 0 ? posts[currentIndex - 1] : null |
| 19 | const next = currentIndex < posts.length - 1 ? posts[currentIndex + 1] : null |
| 20 | |
| 21 | return { content, level, title, prev, next } |
| 22 | } |
| 23 | |
| 24 | export const listPosts = async () => { |
| 25 | const posts = await readIndex() |
no test coverage detected