import yaml


def get_front_matter(contents: list[str]) -> dict:
    """
    Get the front matter from a Hugo recipe as a Python dictionary.
    It needs to be in YAML format to be parsable.
    """
    currently_fm = False
    front_matter = []
    for line in contents:
        if line == "---\n":
            currently_fm = not currently_fm
            continue

        if currently_fm:
            front_matter.append(line)

    try:
        parsed = yaml.safe_load("\n".join(front_matter))
    except Exception as e:
        parsed = {}

    return parsed