diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2022-04-18 22:39:11 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2022-04-18 22:39:11 -0600 |
commit | 9bfb9dd2e8fa187a36c4ef98a491b9c2944bbd11 (patch) | |
tree | 80dbee9bbf9e1c3c2c194c9a0a57275196f9ff6a /src | |
parent | e8ce49590ed5a73f72e45c8ae2e021ddcf3dbf12 (diff) |
add meaningful error messages when missing mandatory metadatav0.6.1
Diffstat (limited to 'src')
-rw-r--r-- | src/pyssg/page.py | 20 |
1 files changed, 15 insertions, 5 deletions
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, |