Skip to content
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

Support cross-language magic links #3811

Open
1 task done
gudzpoz opened this issue Jan 17, 2025 · 0 comments · May be fixed by #3812
Open
1 task done

Support cross-language magic links #3811

gudzpoz opened this issue Jan 17, 2025 · 0 comments · May be fixed by #3812

Comments

@gudzpoz
Copy link
Contributor

gudzpoz commented Jan 17, 2025

Requested Feature

  • Support links with a lang query param like: link://slug/my-post?lang=de.
  • Support cross-language filename links like: link://filename/my-post.other_lang.md.

Related Area

(I don't know. I guess it's related to the core nikola.py.)

Do you want to contribute this yourself as a pull request?

Does this feature affect backwards compatibility? If yes, in what way?

No.

  • With Nikola 8.3.1, a link like link://slug/my-post?lang=de causes Nikola to abort because lang (None or not) is already passed as a positional param:
    TypeError: Nikola.path() got multiple values for argument 'lang'
    
    So I guess it is backwards compatible.
  • As for link://filename/my-post.other_lang.md, it produces invalid urls half of the time. And I think fixing it is not a breaking change.

Rationale and full description

Currently, many magic links in Nikola (slugs, filenames, etc.) cannot link across languages. (If I understand correctly, the only one that seems to support this is link:///absolute-path.)

  • Since the _link function in templates has an optional lang param, it would be natural to allow using a lang query param in links, like: link://slug/my-post?lang=de.

    A typical use case for this may be How to use translated slugs/URLs on a multi-language site? #3801 when the user want to link to posts in another language without having to hardcode links.

  • Even if the user tries to link with absolute filenames via link://filename/..., with SHOW_UNTRANSLATED_POSTS = False, Nikola will produce invalid links, because it uses the current language in filename_path when calling p.permalink:

    nikola/nikola/nikola.py

    Lines 1970 to 1976 in 1da7205

    results = [p for p in self.timeline if p.source_path == name]
    if not results:
    utils.LOGGER.warning("Cannot resolve path request for filename: {0}".format(name))
    else:
    if len(results) > 1:
    utils.LOGGER.error("Ambiguous path request for filename: {0}".format(name))
    return [_f for _f in results[0].permalink(lang).split('/') if _f]

@gudzpoz gudzpoz linked a pull request Jan 17, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant