From 772fe46a5b976be78e36096f121e40e5e0036fe8 Mon Sep 17 00:00:00 2001 From: Amy Gale Ruth Bowersox Date: Tue, 27 Feb 2024 21:29:42 -0700 Subject: [PATCH] added metadata loading --- src/dragonglass/dragonglass.py | 4 ++++ src/dragonglass/tree.py | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/dragonglass/dragonglass.py b/src/dragonglass/dragonglass.py index aeb2dd7..bcb69b1 100644 --- a/src/dragonglass/dragonglass.py +++ b/src/dragonglass/dragonglass.py @@ -25,10 +25,14 @@ def main(): return 1 nodes = SourceNode.generate_list(source_dir) + for node in nodes: + node.load_metadata(source_dir) # TEMP for node in nodes: print(node) + if node.metadata: + print(f"Metadata: {node.metadata}") return 0 diff --git a/src/dragonglass/tree.py b/src/dragonglass/tree.py index 34c064f..e753750 100644 --- a/src/dragonglass/tree.py +++ b/src/dragonglass/tree.py @@ -1,5 +1,7 @@ #!/usr/bin/env python +import yaml + # The paths that are always to be ignored. STATIC_IGNORE = [ '.obsidian' @@ -13,6 +15,7 @@ class SourceNode: self._path = path self._is_dir = is_dir self._is_md = path.match(MARKDOWN_PAT) + self.metadata = None def __str__(self): return f"SourceNode({self._path}, {self._is_dir}) [is_md={self._is_md}]" @@ -35,3 +38,17 @@ class SourceNode: if child.is_dir(): dirs.append(child) return nodes + + def load_metadata(self, source_dir): + if self._is_md: + with open(source_dir / self._path, "r", encoding="utf-8") as f: + print(">>>opened") + l = f.readline() + if l == '---\n': + print(">>>startmd") + metalines = [] + l = f.readline() + while l != '---\n': + metalines.append(l) + l = f.readline() + self.metadata = yaml.full_load(''.join(metalines))