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))