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

Expose relative URL fixer filter in Jinja2 environment #236

Closed
SuibianP opened this issue Jul 26, 2024 · 6 comments
Closed

Expose relative URL fixer filter in Jinja2 environment #236

SuibianP opened this issue Jul 26, 2024 · 6 comments
Labels
enhancement New feature or request fixed A fix has been submitted

Comments

@SuibianP
Copy link

(Discussed in #199)

MkDocs has the url filter (implemented here and exported here) that resolves relative URLs to the current page. mkdocs-macro has a similar function fix_url which is not exported to the jinja environment.

The direct workaround is adding it to the environment in define_env as mentioned here. Nonetheless, as this functionality is frequently used such as when constructing href attributes, it would be beneficial to export this by default. Preferably the filter could be named url as well to match mkdocs behaviour.

Copy link

Welcome to this project and thank you!' first issue

@fralau fralau added the enhancement New feature or request label Jul 26, 2024
fralau pushed a commit that referenced this issue Jul 28, 2024
- This filter is imported from mkdocs.utils
@fralau fralau added fixed A fix has been submitted please test An updated was pushed. This needs to be tested labels Jul 28, 2024
@fralau
Copy link
Owner

fralau commented Jul 28, 2024

The last version on github now contains that filter, visible thanks to {{ macros_info() }}.

Capture

@SuibianP Could I ask you to test whether it works correctly for you?

@SuibianP
Copy link
Author

@fralau Thanks for the addition! "relative/url/to/base" | normalize_url(page) works for me now.

Would it be better to take env.page instead of None by default, so that there is no need to repeat page for the most common case (relative to current page)? This is also how url_filter is implemented.

@fralau
Copy link
Owner

fralau commented Jul 28, 2024

OK, I had missed that point!

Back to the drawing, board. I implemented the new filter, called relative_url, exactly as implemented in the example of the discussion.
Capture d’écran 2024-07-28 à 16 19 40

fralau pushed a commit that referenced this issue Jul 28, 2024
- New filter is now called `relative_url`.
@fralau
Copy link
Owner

fralau commented Jul 28, 2024

@SuibianP Test again?

@SuibianP
Copy link
Author

@fralau Works for me, thanks a lot!

@fralau fralau removed the please test An updated was pushed. This needs to be tested label Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed A fix has been submitted
Projects
None yet
Development

No branches or pull requests

2 participants