diff --git a/logya/content.py b/logya/content.py index 4935266..54ed3f3 100644 --- a/logya/content.py +++ b/logya/content.py @@ -40,6 +40,7 @@ def content_type(path: Path) -> Union[None, str]: return 'html' if path.suffix in {'.md', '.markdown'}: return 'markdown' + return None def create_url(path: Path) -> str: diff --git a/logya/core.py b/logya/core.py index 7570560..0aabe80 100644 --- a/logya/core.py +++ b/logya/core.py @@ -25,8 +25,9 @@ def __init__(self, dir_site: str = '.', verbose: bool = False): for coll in self.collections.values(): coll['index'] = {} - # Initialize extensions + # Simplify access to these settings. self.markdown_extensions = self.settings.get('extensions', {}).get('markdown', []) + self.languages = self.settings.get('languages', {}) def build(self): """Read content and initialize template environment.""" @@ -82,7 +83,7 @@ def update_collections(self, doc: dict): url = f'/{coll["path"]}/{slugify(value).lower()}/' # Prepend language code to URL if language is specified in doc and exists in configuration. - if 'language' in doc and doc['language'] in self.settings.get('languages'): + if 'language' in doc and doc['language'] in self.languages: url = f'/{doc["language"]}{url}' if url in self.doc_index: diff --git a/logya/server.py b/logya/server.py index b4faaf0..73efdfd 100644 --- a/logya/server.py +++ b/logya/server.py @@ -13,7 +13,7 @@ class HTTPRequestHandler(http.server.SimpleHTTPRequestHandler): """SimpleHTTPRequestHandler based class to return resources.""" - L = None + L: Logya def __init__(self, *args): super(HTTPRequestHandler, self).__init__(*args, directory=self.L.paths.public.as_posix()) diff --git a/logya/util.py b/logya/util.py index 5e356b1..25b0bc3 100644 --- a/logya/util.py +++ b/logya/util.py @@ -10,7 +10,7 @@ try: from yaml import CDumper as Dumper, CLoader as Loader except ImportError: - from yaml import Dumper, Loader + from yaml import Dumper, Loader # type: ignore # Characters not to be used in URLs, allowing some punctuation. @@ -47,6 +47,7 @@ def get_item(items: list, value: str, attr: str = 'url') -> Union[dict, None]: for item in items: if item.get(attr) == value: return item + return None def load_yaml(text: str) -> dict: