diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/pyssg/page.py | 20 |
2 files changed, 16 insertions, 6 deletions
@@ -21,7 +21,7 @@ Inspired (initially) by Roman Zolotarev's [`ssg5`](https://rgz.ee/bin/ssg5) and - [x] Use [`configparser`](https://docs.python.org/3/library/configparser.html) instead of custom config handler. - [ ] Migrate to YAML instead of INI, as it is way more flexible. - [x] Avoid the program to freak out when there are directories created in advance. -- [ ] Provide more meaningful error messages when you are missing mandatory tags in your `.md` files. +- [x] Provide more meaningful error messages when you are missing mandatory metadata in your `*.md` files. - [ ] More complex directory structure to support multiple subdomains and different types of pages. - [ ] Add option/change to using an SQL database instead of the custom solution. diff --git a/src/pyssg/page.py b/src/pyssg/page.py index dd3881c..82a0431 100644 --- a/src/pyssg/page.py +++ b/src/pyssg/page.py @@ -1,3 +1,4 @@ +import os import sys from datetime import datetime, timezone import logging @@ -61,15 +62,24 @@ class Page: return self.ctimestamp < other.ctimestamp + def __get_mandatory_meta(self, meta: str) -> str: + try: + log.debug('parsing required metadata "%s"', meta) + return self.meta[meta][0] + except KeyError: + log.error('failed to parse mandatory metadata "%s" from file "%s"', + meta, os.path.join(self.config.get('path', 'src'), self.name)) + sys.exit(1) + + # parses meta from self.meta, for og, it prioritizes, # the actual og meta def parse_metadata(self): log.debug('parsing metadata for file "%s"', self.name) - log.debug('parsing required metadata') - self.title = self.meta['title'][0] - self.author = self.meta['author'][0] - self.summary = self.meta['summary'][0] - self.lang = self.meta['lang'][0] + self.title = self.__get_mandatory_meta('title') + self.author = self.__get_mandatory_meta('author') + self.summary = self.__get_mandatory_meta('summary') + self.lang = self.__get_mandatory_meta('lang') log.debug('parsing timestamp') self.cdatetime = datetime.fromtimestamp(self.ctimestamp, |