Formatting

This commit is contained in:
squidfunk 2023-08-23 16:02:43 +02:00
parent 1b2ba4bcef
commit 6839f1cd97
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
4 changed files with 14 additions and 10 deletions

View File

@ -411,16 +411,18 @@ class BlogPlugin(BasePlugin[BlogConfig]):
path = self.config.authors_file.format(blog = self.config.blog_dir) path = self.config.authors_file.format(blog = self.config.blog_dir)
path = os.path.normpath(path) path = os.path.normpath(path)
# If the authors file does not exist, return an empty dictionary # Resolve path relative to docs directory
docs = os.path.relpath(config.docs_dir) docs = os.path.relpath(config.docs_dir)
file = os.path.join(docs, path) file = os.path.join(docs, path)
# If the authors file does not exist, return here
config: Authors = Authors()
if not os.path.isfile(file): if not os.path.isfile(file):
authors: dict[str, Author] = {} return config.authors
return authors
# Open file and parse as YAML # Open file and parse as YAML
with open(file, encoding = "utf-8") as f: with open(file, encoding = "utf-8") as f:
config: Authors = Authors(os.path.abspath(file)) config.config_file_path = os.path.abspath(file)
try: try:
config.load_dict(yaml.load(f, SafeLoader) or {}) config.load_dict(yaml.load(f, SafeLoader) or {})

View File

@ -52,7 +52,7 @@ class Post(Page):
def __init__(self, file: File, config: MkDocsConfig): def __init__(self, file: File, config: MkDocsConfig):
super().__init__(None, file, config) super().__init__(None, file, config)
# Resolve path relative to docs directory for error reporting # Resolve path relative to docs directory
docs = os.path.relpath(config.docs_dir) docs = os.path.relpath(config.docs_dir)
path = os.path.relpath(file.abs_src_path, docs) path = os.path.relpath(file.abs_src_path, docs)

View File

@ -411,16 +411,18 @@ class BlogPlugin(BasePlugin[BlogConfig]):
path = self.config.authors_file.format(blog = self.config.blog_dir) path = self.config.authors_file.format(blog = self.config.blog_dir)
path = os.path.normpath(path) path = os.path.normpath(path)
# If the authors file does not exist, return an empty dictionary # Resolve path relative to docs directory
docs = os.path.relpath(config.docs_dir) docs = os.path.relpath(config.docs_dir)
file = os.path.join(docs, path) file = os.path.join(docs, path)
# If the authors file does not exist, return here
config: Authors = Authors()
if not os.path.isfile(file): if not os.path.isfile(file):
authors: dict[str, Author] = {} return config.authors
return authors
# Open file and parse as YAML # Open file and parse as YAML
with open(file, encoding = "utf-8") as f: with open(file, encoding = "utf-8") as f:
config: Authors = Authors(os.path.abspath(file)) config.config_file_path = os.path.abspath(file)
try: try:
config.load_dict(yaml.load(f, SafeLoader) or {}) config.load_dict(yaml.load(f, SafeLoader) or {})

View File

@ -52,7 +52,7 @@ class Post(Page):
def __init__(self, file: File, config: MkDocsConfig): def __init__(self, file: File, config: MkDocsConfig):
super().__init__(None, file, config) super().__init__(None, file, config)
# Resolve path relative to docs directory for error reporting # Resolve path relative to docs directory
docs = os.path.relpath(config.docs_dir) docs = os.path.relpath(config.docs_dir)
path = os.path.relpath(file.abs_src_path, docs) path = os.path.relpath(file.abs_src_path, docs)