import io
import yaml


def parse_frontmatter(path):
    """Parses frontmatter from a file and returns a dictionary object

    Parameters
    ----------
    path: str | os.PathLike

    Returns
    -------
    yaml: dict
        dictionary representation of yaml found in frontmatter
    """
    buffer = io.StringIO()
    with open(path) as f:
        f.readline()  # skip frontmatter header of "---"
        for line in f:
            if line.strip() == "---":
                break
            buffer.write(line)

    buffer.seek(0)
    return yaml.safe_load(buffer)