diff options
author | David Luevano Alvarado <david@luevano.xyz> | 2023-05-01 07:47:11 -0600 |
---|---|---|
committer | David Luevano Alvarado <david@luevano.xyz> | 2023-05-01 07:47:11 -0600 |
commit | 127130ab909dac8886f45ec856f1d1bce3c7bcc0 (patch) | |
tree | d5390204af3ee142c236c7397e7543acb3f5c160 /src | |
parent | 5b0cac515745102c1e3555da13b98c40baa2bd92 (diff) |
fix small bug on page metadata parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/pyssg/md_parser.py | 19 | ||||
-rw-r--r-- | src/pyssg/page.py | 10 |
2 files changed, 21 insertions, 8 deletions
diff --git a/src/pyssg/md_parser.py b/src/pyssg/md_parser.py index 3b62985..d652da9 100644 --- a/src/pyssg/md_parser.py +++ b/src/pyssg/md_parser.py @@ -1,6 +1,7 @@ import os from operator import itemgetter from logging import Logger, getLogger +from typing import Any from markdown import Markdown from yafg import YafgExtension @@ -14,8 +15,8 @@ log: Logger = getLogger(__name__) # TODO: add configuration testing for extensions config (pymdvar for ex) -def get_md_obj(variables: dict[str, str] = dict(), - enable_env: bool = False) -> Markdown: +def get_md_obj(variables: dict[str, str], + enable_env: bool) -> Markdown: exts: list = ['extra', 'meta', 'sane_lists', @@ -55,7 +56,19 @@ class MDParser: self.config: dict = config self.dir_config: dict = dir_config self.db: Database = db - self.md: Markdown = get_md_obj() + # TODO: actually add extensions support, for now only pymdvar is configured + self.pymdvar_vars: dict[str, str] = dict() + self.pymdvar_enable_env: bool = False + if 'exts' in config and 'pymdvar' in config['exts']: + pymdvar: dict[str, Any] = config['exts']['pymdvar'] + if 'variables' in pymdvar and type(pymdvar['variables']) == dict: + self.pymdvar_vars = pymdvar['variables'] + if 'enable_env' in pymdvar and type(pymdvar['enable_env']) == bool: + self.pymdvar_enable_env = pymdvar['enable_env'] + log.warning('pymdvar_variables: %s', self.pymdvar_vars) + log.warning('pymdvar_enable_env: %s', self.pymdvar_enable_env) + + self.md: Markdown = get_md_obj(self.pymdvar_vars, self.pymdvar_enable_env) self.all_files: list[Page] = [] self.all_tags: list[tuple[str, str]] = [] diff --git a/src/pyssg/page.py b/src/pyssg/page.py index 40eb41a..93eedee 100644 --- a/src/pyssg/page.py +++ b/src/pyssg/page.py @@ -50,7 +50,7 @@ class Page: return self.ctimestamp < other.ctimestamp def __get_meta(self, var: str, - or_else: str | list[str] = '') -> str | list[str] | Any: + or_else: str | list[str] = ['']) -> str | list[str] | Any: if var in self.meta: log.debug('getting metadata "%s"', var) return self.meta[var] @@ -84,10 +84,10 @@ class Page: # parses meta from self.meta def parse_metadata(self): log.debug('parsing metadata for file "%s"', self.name) - self.title = str(self.__get_meta('title')) - self.author = list(self.__get_meta('author', [''])) - self.summary = str(self.__get_meta('summary')) - self.lang = str(self.__get_meta('lang', 'en')) + self.title = str(self.__get_meta('title')[0]) + self.author = list(self.__get_meta('author')) + self.summary = str(self.__get_meta('summary')[0]) + self.lang = str(self.__get_meta('lang', ['en'])[0]) log.debug('parsing timestamp') self.cdatetime = self.from_timestamp(self.ctimestamp) |