@rogerpence/rp-utils
    Preparing search index...

    Function getMarkdownObjects

    • Retrieves and parses all markdown files from a specified directory.

      Reads all .md files in the given folder, parses their frontmatter and content, and separates successfully parsed files from failed ones. The frontmatter in successful files is untyped (Record<string, any>) until validated with a schema.

      Parameters

      • folder: string

        Path to the directory containing markdown files

      Returns Promise<MarkdownParseResult>

      Promise resolving to an object with successful and failed parse results

      Parse all markdown files in a directory

      const { successful, failed } = await getMarkdownObjects('./posts');
      console.log(`Parsed ${successful.length} files, ${failed.length} failed`);

      successful.forEach(file => {
      console.log(`File: ${file.dirent.name}`);
      console.log(`Frontmatter:`, file.markdownObject.frontMatter);
      });

      if (failed.length > 0) {
      failed.forEach(f => console.error(`${f.filename}: ${f.error}`));
      }