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

GitHub stars don't work if the repo_url ends with a / #1

Closed
d0ugal opened this issue Feb 10, 2016 · 2 comments
Closed

GitHub stars don't work if the repo_url ends with a / #1

d0ugal opened this issue Feb 10, 2016 · 2 comments
Labels
bug Issue reports a bug

Comments

@d0ugal
Copy link

d0ugal commented Feb 10, 2016

If the repo_url ends with a slash, like it does in the MkDocs mkdocs.yml the GitHub stars don't work.

repo_url: https://github.com/mkdocs/mkdocs/

We could simply just remove this from the mkdocs.yml, but it would be nice if it worked either way. It took me a few minutes to figure out where the problem was.

@squidfunk squidfunk added the bug Issue reports a bug label Feb 10, 2016
@squidfunk
Copy link
Owner

Fixed in master, I will wait some days for potential bugs to push out 0.1.1.

Sadly, the jinja template engine is not very flexible. I wanted to omit adding further variables to the mkdocs.yml, so I extracted it from the repo_name variable. Nevertheless, this approach is fragile and I think about changing it in the future. Would it be possible to extend MkDocs in a way so that you can define custom filters in your themes? Maybe through some special named .py file that gets included automatically, if present. This way I could define a regex filter for more robust parsing, e.g. this one:

# Custom filter method
def regex_replace(s, find, replace):
    """A non-optimal implementation of a regex filter"""
    return re.sub(find, replace, s)

jinja_environment.filters['regex_replace'] = regex_replace

from http://stackoverflow.com/questions/12791216/how-do-i-use-regular-expressions-in-jinja2

I don't want to do it in Javascript, because then it depends on the client, so i fixed it like this:

{% if repo_name == 'GitHub' %}
  {% set repo_id = repo_url | replace('https://github.com/', '') %}
  {% if repo_id[-1:] == '/' %}
    {% set repo_id = repo_id[:-1] %}
  {% endif %}
{% endif %}

Any better ideas on this?

@d0ugal
Copy link
Author

d0ugal commented Feb 10, 2016

That looks like a good fix for now.

We probably do want to make themes more flexible at some point, but that starts to overlap with a plugin API. I hadn't really considered plugins from a theme point of view before but there is general discussion here: mkdocs/mkdocs#206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug
Projects
None yet
Development

No branches or pull requests

2 participants