aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Numerlor <[email protected]>2021-08-12 19:38:30 +0200
committerGravatar Numerlor <[email protected]>2021-08-12 19:38:30 +0200
commit6b5431017c0c49deb689390ceccfe344662b8d30 (patch)
tree2afd763c94910c1d9ceaaac927ef4dfae0d61923
parentMake return condition clearer (diff)
Store paths on Tags instead of only accepting the file contents
-rw-r--r--bot/exts/info/tags.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/bot/exts/info/tags.py b/bot/exts/info/tags.py
index beabade58..ddd372fe7 100644
--- a/bot/exts/info/tags.py
+++ b/bot/exts/info/tags.py
@@ -81,8 +81,9 @@ class TagIdentifier(NamedTuple):
class Tag:
"""Provide an interface to a tag from resources with `file_content`."""
- def __init__(self, file_content: str):
- post = frontmatter.loads(file_content)
+ def __init__(self, content_path: Path):
+ post = frontmatter.loads(content_path.read_text("utf8"))
+ self.file_path = content_path
self.content = post.content
self.metadata = post.metadata
self._restricted_to: set[int] = set(self.metadata.get("restricted_to", ()))
@@ -147,7 +148,7 @@ class Tags(Cog):
tag_name = file.stem
tag_group = parent_dir.name if parent_dir.name else None
- self._tags[TagIdentifier(tag_group, tag_name)] = Tag(file.read_text("utf-8"))
+ self._tags[TagIdentifier(tag_group, tag_name)] = Tag(file)
def _get_suggestions(self, tag_identifier: TagIdentifier) -> list[tuple[TagIdentifier, Tag]]:
"""Return a list of suggested tags for `tag_identifier`."""