summaryrefslogtreecommitdiff
path: root/scripts/parse_frontmatter.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/parse_frontmatter.py')
-rw-r--r--scripts/parse_frontmatter.py19
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