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

    Function parseMarkdownFile

    • Parses a markdown file with YAML frontmatter.

      Extracts frontmatter delimited by --- markers at the beginning of the file and parses it as YAML. The remaining content is returned as plain text. Returns a Result type with either success (parsed data) or failure (error details).

      This function converts string dates in the format 'yyyy-dd-dd' to Date data types.

      Parameters

      • filename: string

        Absolute or relative path to the markdown file

      Returns Promise<ParseResult>

      Promise resolving to ParseResult with success/failure information

      Parse a markdown file

      const result = await parseMarkdownFile('./posts/article.md');

      if (result.success) {
      console.log('Title:', result.data.frontMatter.title);
      console.log('Content length:', result.data.content.length);
      } else {
      console.error(`Parse failed: ${result.filename}`);
      console.error(`Error: ${result.error}`);
      }

      Handle parsing errors

      const result = await parseMarkdownFile('invalid.md');
      if (!result.success) {
      console.error(`Failed to parse ${result.filename}: ${result.error}`);
      }