MCPcopy Index your code
hub / github.com/TejasQ/tejaskumar.com / getInitialBlogPosts

Function getInitialBlogPosts

util/getInitialBlogPosts.ts:14–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12const path = __non_webpack_require__("path");
13
14export 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}

Callers 3

getStaticPropsFunction · 0.90
getStaticPropsFunction · 0.90
rss.tsFile · 0.90

Calls 1

Tested by

no test coverage detected