Skip to content

Commit dd30089

Browse files
committed
Pass page.url to relativize_links() for consistent build and serve
1 parent beffab6 commit dd30089

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mkdocs_snippets/plugin.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def resolve_snippet(self, markdown: str, page: Page) -> str:
8282

8383
snippet_content = self.snippets[snippet_address][snippet_id]
8484

85-
snippet_content = relativize_links(snippet_content, page.file.src_uri, snippet_id)
85+
snippet_content = relativize_links(snippet_content, page.url, snippet_id)
8686

8787
snippet_content = self.preserve_indentation(snippet_content, markdown)
8888

@@ -119,6 +119,10 @@ def read_snippets_from_file(file_content) -> dict[str, str]:
119119

120120

121121
def relativize_links(snippet_content, current_path, snippet_id) -> str:
122+
current_path = '/' + current_path.strip('/') + '/'
123+
current_path_without_filename = current_path.rsplit("/", 2)[0]
124+
current_path_without_filename = remove_mike_version_from_path(current_path_without_filename)
125+
122126
matches = re.findall(markdown_link_pattern, snippet_content)
123127
for match in matches:
124128
link_text = match[0]
@@ -143,10 +147,6 @@ def relativize_links(snippet_content, current_path, snippet_id) -> str:
143147
link_without_filetype = link_and_filetype[0]
144148
filetype = link_and_filetype[1]
145149

146-
current_path_without_filename = current_path.rsplit("/", 2)[0]
147-
148-
current_path_without_filename = remove_mike_version_from_path(current_path_without_filename)
149-
150150
relative_link = os.path.relpath(f"docs/{link_without_filetype}", f"docs/{current_path_without_filename}")
151151

152152
relative_link += "." + filetype

0 commit comments

Comments
 (0)