From 7ee02b03d17d5b59fafa375174bc25861c19c104 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Fri, 22 Apr 2022 15:34:27 -0600 Subject: [PATCH] Include "/" in empty paths When articles were in the base directory, the string replacement: `str(full_path).replace(str(base_path) + '/'` would not match, causing the whole absolute path to be included which would break the link. This should now work if the article is in the base directory or in any subfolder. --- pelican/plugins/obsidian/obsidian.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pelican/plugins/obsidian/obsidian.py b/pelican/plugins/obsidian/obsidian.py index aeb8dd7..bf45c37 100644 --- a/pelican/plugins/obsidian/obsidian.py +++ b/pelican/plugins/obsidian/obsidian.py @@ -49,7 +49,7 @@ class ObsidianMarkdownReader(MarkdownReader): filename, linkname = get_file_and_linkname(match) path = ARTICLE_PATHS.get(filename) if path: - link_structure = '[{linkname}]({{filename}}/{path}/{filename}.md)'.format( + link_structure = '[{linkname}]({{filename}}{path}{filename}.md)'.format( linkname=linkname, path=path, filename=filename ) else: @@ -60,7 +60,7 @@ class ObsidianMarkdownReader(MarkdownReader): filename, linkname = get_file_and_linkname(match) path = FILE_PATHS.get(filename) if path: - link_structure = '![{linkname}]({{static}}/{path}/{filename})'.format( + link_structure = '![{linkname}]({{static}}{path}{filename})'.format( linkname=linkname, path=path, filename=filename ) else: @@ -101,7 +101,7 @@ def populate_files_and_articles(article_generator): for article in articles: full_path, filename_w_ext = os.path.split(article) filename, ext = os.path.splitext(filename_w_ext) - path = str(full_path).replace(str(base_path) + '/', '') + path = str(full_path).replace(str(base_path), '') + '/' ARTICLE_PATHS[filename] = path globs = [base_path.glob('**/*.{}'.format(ext)) for ext in ['png', 'jpg', 'svg', 'apkg', 'gif']] @@ -109,7 +109,7 @@ def populate_files_and_articles(article_generator): for _file in files: full_path, filename_w_ext = os.path.split(_file) - path = str(full_path).replace(str(base_path) + '/', '') + path = str(full_path).replace(str(base_path), '') + '/' FILE_PATHS[filename_w_ext] = path