Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
TOsmanov committed Jul 22, 2024
1 parent 22542cf commit 518e8d7
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions foliant/preprocessors/includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,16 @@ def _process_include(

return included_content

def _prepare_path_for_includes_map(self, path: Path) -> str:
donor_path = None
if path.as_posix().startswith(os.getcwd()):
_path = path.relative_to(os.getcwd())
if _path.as_posix().startswith(self.working_dir.as_posix()):
donor_path = f"{self.src_dir}/{_path.relative_to(self.working_dir).as_posix()}"
else:
donor_path = _path.as_posix()
return donor_path

def process_includes(
self,
markdown_file_path: Path,
Expand Down Expand Up @@ -965,7 +975,6 @@ def process_includes(
included_file_path = repo_path / body.group('path')

donor_md_path = included_file_path.as_posix()

self.logger.debug(f'Set the repo URL of the included file to {recipient_md_path}: {donor_md_path} (1)')

if included_file_path.name.startswith('^'):
Expand Down Expand Up @@ -1018,8 +1027,8 @@ def process_includes(
nohead=options.get('nohead')
)

donor_md_path = f"{self.src_dir}/{included_file_path.relative_to(os.getcwd()).relative_to(self.working_dir).as_posix()}"

donor_md_path = f"{self.src_dir}/{self._prepare_path_for_includes_map(included_file_path)}"
self.logger.debug(f'Set the path of the included file to {recipient_md_path}: {donor_md_path} (2)')

else: # if body is missing
Expand Down Expand Up @@ -1059,7 +1068,6 @@ def process_includes(
)

donor_md_path = include_link + options.get('path')

self.logger.debug(f'Set the link of the included file to {recipient_md_path}: {donor_md_path} (3)')

elif options.get('url'):
Expand Down Expand Up @@ -1089,7 +1097,6 @@ def process_includes(
)

donor_md_path = options['url']

self.logger.debug(f'Set the URL of the included file to {recipient_md_path}: {donor_md_path} (4)')

elif options.get('src'):
Expand All @@ -1098,13 +1105,7 @@ def process_includes(
included_file_path = self._get_included_file_path(options.get('src'), markdown_file_path)
self.logger.debug(f'Resolved path to the included file: {included_file_path}')

if included_file_path.as_posix().startswith(os.getcwd()):
_path = included_file_path.relative_to(os.getcwd())
if _path.as_posix().startswith(self.working_dir.as_posix()):
donor_md_path = f"{self.src_dir}/{_path.relative_to(self.working_dir).as_posix()}"
else:
donor_md_path = _path.as_posix()

donor_md_path = self._prepare_path_for_includes_map(included_file_path)
self.logger.debug(f'Set the path of the included file to {recipient_md_path}: {donor_md_path} (5)')

if options.get('project_root'):
Expand Down

0 comments on commit 518e8d7

Please sign in to comment.