diff options
author | Suleyman Farajli <suleyman@farajli.net> | 2025-06-24 18:37:57 +0400 |
---|---|---|
committer | Suleyman Farajli <suleyman@farajli.net> | 2025-06-24 18:37:57 +0400 |
commit | dd71f019de0314f7b3f2ae1e0aa920e49e9f2759 (patch) | |
tree | 5b8513c4f2e7959eb45de75d93f331506b1cbd43 /scripts/parse_frontmatter.py | |
parent | 014901951cc44a70ff3d4aaa4246592b08699d69 (diff) |
refactor: everything chageddev
Diffstat (limited to 'scripts/parse_frontmatter.py')
-rw-r--r-- | scripts/parse_frontmatter.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/scripts/parse_frontmatter.py b/scripts/parse_frontmatter.py new file mode 100644 index 0000000..2d5c60e --- /dev/null +++ b/scripts/parse_frontmatter.py @@ -0,0 +1,19 @@ +import yaml + +def parse_frontmatter(filepath): + with open(filepath, 'r', encoding='utf-8') as f: + lines = f.readlines() + + if not lines or lines[0].strip() != '---': + return {} + + frontmatter_lines = [] + for line in lines[1:]: + if line.strip() == '---': + break + frontmatter_lines.append(line) + + frontmatter_str = ''.join(frontmatter_lines) + frontmatter = yaml.safe_load(frontmatter_str) or {} + + return frontmatter |