feat: create File and MarkdownParser services

This commit is contained in:
thomasabishop 2024-10-31 15:38:14 +00:00
parent 577812c493
commit b11f5850fc
2 changed files with 33 additions and 0 deletions

View file

@ -0,0 +1,17 @@
import os
class FileService:
def __init__(self, eolas_file):
self.eolas_file = eolas_file
self.info = os.stat(eolas_file)
def __extract_title(self):
return os.path.basename(self.eolas_file)
def get_info(self):
return {
"title": self.__extract_title(),
"last_modified": self.info.st_mtime,
"size": self.info.st_size,
}

View file

@ -0,0 +1,16 @@
import frontmatter
class MarkdownParseService:
"""Extract tags, links and body text from Markdown entries"""
def __init__(self, eolas_file):
self.eolas_file = eolas_file
def parse(self):
with open(self.eolas_file) as f:
metadata, content = frontmatter.parse(f.read())
return {
"tags": metadata.get("tags", []),
"body": content or "",
}