Skip to content

Commit

Permalink
Merge pull request #290 from kamilkrzyskow/fix/folder-with-tests
Browse files Browse the repository at this point in the history
Fix/folder with tests
  • Loading branch information
ultrabug committed Feb 13, 2024
2 parents d172407 + 4de2104 commit 48851e4
Show file tree
Hide file tree
Showing 6 changed files with 386 additions and 23 deletions.
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ markdown_extensions:
- pymdownx.tabbed:
alternate_style: true
- pymdownx.emoji:
emoji_index: !!python/name:materialx.emoji.twemoji
emoji_generator: !!python/name:materialx.emoji.to_svg
emoji_index: !!python/name:material.extensions.emoji.twemoji
emoji_generator: !!python/name:material.extensions.emoji.to_svg

nav:
- Home: index.md
Expand Down
40 changes: 24 additions & 16 deletions mkdocs_static_i18n/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,39 @@ def get_file_from_path(self, path: str) -> Optional[File]:
expected_src_uri = PurePath(path)
if expected_src_uri == PurePath("."):
expected_src_uri = PurePath("index.md")
expected_src_uris = []

expected_src_uris: list[PurePath] = []

# non localized paths detection (root)
if is_relative_to(expected_src_uri, self.plugin.current_language):
expected_src_uris.append(expected_src_uri.relative_to(self.plugin.current_language))
# default language path detection
# First add current_code/path
# Second add default_code/path (fallback)
# Last add path without prefix
resolved_path = expected_src_uri.relative_to(self.plugin.current_language)
expected_src_uris.append(expected_src_uri)
if self.plugin.config.fallback_to_default is True:
expected_src_uris.append(
PurePath(self.plugin.default_language) / expected_src_uris[-1]
)
expected_src_uris.append(PurePath(self.plugin.default_language) / resolved_path)
expected_src_uris.append(resolved_path)
elif is_relative_to(expected_src_uri, self.plugin.default_language):
expected_src_uris.append(expected_src_uri.relative_to(self.plugin.default_language))
# First add default_code/path
# Second add current_code/path (fallback)
# Last add path without prefix
resolved_path = expected_src_uri.relative_to(self.plugin.default_language)
expected_src_uris.append(expected_src_uri)
if self.plugin.config.fallback_to_default is True:
expected_src_uris.append(
PurePath(self.plugin.current_language)
/ expected_src_uri.relative_to(self.plugin.default_language)
)
expected_src_uris.append(PurePath(self.plugin.current_language) / resolved_path)
expected_src_uris.append(resolved_path)
# localized paths detection
else:
# First add current_code/path
# Second add default_code/path (fallback)
# Last add path without modification
expected_src_uris.append(PurePath(self.plugin.current_language) / expected_src_uri)
# default language path detection
if self.plugin.config.fallback_to_default is True:
expected_src_uris.append(PurePath(self.plugin.default_language) / expected_src_uri)
expected_src_uris.append(expected_src_uri)
if self.plugin.config.fallback_to_default is True:
expected_src_uris.append(PurePath(self.plugin.default_language) / expected_src_uri)
expected_src_uris.append(expected_src_uri)

for src_uri in reversed(expected_src_uris):
for src_uri in expected_src_uris:
file = self.src_uris.get(src_uri.as_posix())
if file:
return file
Expand Down
5 changes: 5 additions & 0 deletions mkdocs_static_i18n/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class NavHelper:
f"/{self.current_language}/{homepage_suffix}",
]

# MkDocs resolves default/index.html, which isn't toplevel,
# however the resolved path in the plugin is index.html
if not config.use_directory_urls:
NavHelper.expected_homepage_urls.append("index.html")

i18n_nav = self.reconfigure_navigation(nav, config, files, NavHelper)
i18n_nav.homepage = NavHelper.homepage

Expand Down
2 changes: 2 additions & 0 deletions tests/docs_folder_structure_two_languages/fr/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ site
└── topic2
└── index.html
```

[Test fallback to default](english_default/index.md)
Loading

0 comments on commit 48851e4

Please sign in to comment.