-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added warning for multiple same anchors #50
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
beilm
commented
Jul 4, 2024
- Changed url_map to dict[str, list[str]] to allow multiple entries per identifier
- Changed get_item_url to return always the first url found and add a warning because of multiple entries
Hi @beilm, thanks a lot for the PR! LGTM! Just wanted to change a bit the warning and try/except flow, but GitHub rejected me 🤔 % git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 6 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 576 bytes | 288.00 KiB/s, done.
Total 5 (delta 3), reused 0 (delta 0), pack-reused 0 (from 0)
remote: Resolving deltas: 100% (3/3), completed with 3 local objects.
To github.com:beilm/autorefs.git
! [remote rejected] beilm/main -> beilm/main (permission denied)
error: failed to push some refs to 'github.com:beilm/autorefs.git' Here's the diff if you'd like to apply it: % git diff
diff --git a/src/mkdocs_autorefs/plugin.py b/src/mkdocs_autorefs/plugin.py
index c6c22a8..e7428ff 100644
--- a/src/mkdocs_autorefs/plugin.py
+++ b/src/mkdocs_autorefs/plugin.py
@@ -90,11 +90,7 @@ class AutorefsPlugin(BasePlugin):
fallback: Callable[[str], Sequence[str]] | None = None,
) -> str:
try:
- if len(self._url_map[identifier]) > 1:
- log.warning(
- f"Multiple urls found for '{identifier}': {self._url_map[identifier]}. Please specify a custom unique identifier.",
- )
- return self._url_map[identifier][0]
+ urls = self._url_map[identifier]
except KeyError:
if identifier in self._abs_url_map:
return self._abs_url_map[identifier]
@@ -106,6 +102,13 @@ class AutorefsPlugin(BasePlugin):
self._url_map[identifier] = [url]
return url
raise
+ else:
+ if len(urls) > 1:
+ log.warning(
+ f"Multiple URLs found for '{identifier}': {urls}. "
+ "Please use unique identifiers, or unique Markdown anchors (see our docs).",
+ )
+ return urls[0]
def get_item_url(
self, |
pawamoy
reviewed
Jul 5, 2024
pawamoy
approved these changes
Jul 5, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK LGTM, thanks a lot! Will try to release soon.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.