added metadata loading
This commit is contained in:
parent
9d80f41a09
commit
772fe46a5b
|
@ -25,10 +25,14 @@ def main():
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
nodes = SourceNode.generate_list(source_dir)
|
nodes = SourceNode.generate_list(source_dir)
|
||||||
|
for node in nodes:
|
||||||
|
node.load_metadata(source_dir)
|
||||||
|
|
||||||
# TEMP
|
# TEMP
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
print(node)
|
print(node)
|
||||||
|
if node.metadata:
|
||||||
|
print(f"Metadata: {node.metadata}")
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
# The paths that are always to be ignored.
|
# The paths that are always to be ignored.
|
||||||
STATIC_IGNORE = [
|
STATIC_IGNORE = [
|
||||||
'.obsidian'
|
'.obsidian'
|
||||||
|
@ -13,6 +15,7 @@ class SourceNode:
|
||||||
self._path = path
|
self._path = path
|
||||||
self._is_dir = is_dir
|
self._is_dir = is_dir
|
||||||
self._is_md = path.match(MARKDOWN_PAT)
|
self._is_md = path.match(MARKDOWN_PAT)
|
||||||
|
self.metadata = None
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"SourceNode({self._path}, {self._is_dir}) [is_md={self._is_md}]"
|
return f"SourceNode({self._path}, {self._is_dir}) [is_md={self._is_md}]"
|
||||||
|
@ -35,3 +38,17 @@ class SourceNode:
|
||||||
if child.is_dir():
|
if child.is_dir():
|
||||||
dirs.append(child)
|
dirs.append(child)
|
||||||
return nodes
|
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))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user