()
| 12 | const path = __non_webpack_require__("path"); |
| 13 | |
| 14 | export async function getInitialBlogPosts(): Promise<{ posts: Post[] }> { |
| 15 | const blogPosts = fs |
| 16 | .readdirSync(path.resolve("./blog/")) |
| 17 | .filter(e => e.endsWith(".md")) |
| 18 | .sort() |
| 19 | .reverse(); |
| 20 | |
| 21 | return { |
| 22 | posts: blogPosts.map(name => { |
| 23 | const content = fs.readFileSync(path.resolve("./blog/", name), "utf8"); |
| 24 | const excerpt = content.split("\n")[2]; |
| 25 | return { |
| 26 | title: getBlogPostTitleFromFileContent(content), |
| 27 | body: content, |
| 28 | slug: name.replace(/\.md$/, ""), |
| 29 | excerpt: excerpt.length > 260 ? excerpt.slice(0, 260) + "..." : excerpt, |
| 30 | }; |
| 31 | }), |
| 32 | }; |
| 33 | } |
no test coverage detected