Const getPostBySlug
getPostBySlug: (Anonymous function) = memoize(async function (slug: string,options: BlogOptions): Promise<Post> {const folderPath = join(options.postsDirectory, slug);const fullPath = join(folderPath, "index.mdx");const backupPath = join(folderPath, "index.md");let filePath;// Check if path is a folder or a fileif (fs.lstatSync(folderPath).isFile()) {filePath = folderPath;} else if (fs.existsSync(fullPath)) {filePath = fullPath;} else {filePath = backupPath;}const fileContents = fs.readFileSync(filePath, "utf8");const newContents = options.rewriteMediaUrls? rewriteMedias(folderPath,slug,fileContents,options.rewriteMediaUrls.mediaDirectory,options.rewriteMediaUrls.relativeDirectory): fileContents;const { data, content } = matter(newContents);const excerpt = createExcerpt(content, options);const { rendered: excerptRendered, code: excerptCode } =await createHtmlStringFromMarkdown(excerpt || "", options);const { rendered: contentRendered, code: contentCode } =await createHtmlStringFromMarkdown(content || "", options);const item: Post = {slug: slug,date: slug.split("-").slice(0, 3).join("-"),title: data["title"] ?? slug,frontmatter: data,contentRaw: content,contentHTML: contentRendered,contentCode,excerptRaw: excerpt,excerptHTML: excerptRendered,excerptCode,};return item;})
Get a list of all posts.