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

This commit is contained in:
squidfunk 2016-02-10 14:09:30 +01:00
parent d67bfc0375
commit ee05f7d870
10 changed files with 28 additions and 15 deletions

View File

@ -1,3 +1,7 @@
mkdocs-material-0.x.x (2016-xx-xx) [in progress]
* Fixed #1: GitHub stars don't work if the repo_url ends with a '/'
mkdocs-material-0.1.0 (2016-02-09) mkdocs-material-0.1.0 (2016-02-09)
* Initial release * Initial release

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,13 +39,19 @@
<link rel="icon" type="image/x-icon" href="{{ base_url }}/{{ icon }}"> <link rel="icon" type="image/x-icon" href="{{ base_url }}/{{ icon }}">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,700"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,700">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu+Mono"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu+Mono">
<link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-334f02ec.css"> <link rel="stylesheet" href="{{ base_url }}/assets/stylesheets/application-1f184bc3.css">
{% for path in extra_css %} {% for path in extra_css %}
<link rel="stylesheet" href="{{ path }}"> <link rel="stylesheet" href="{{ path }}">
{% endfor %} {% endfor %}
{% block extrahead %}{% endblock %} {% block extrahead %}{% endblock %}
</head> </head>
<body> <body>
{% 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 %}
<div class="backdrop"> <div class="backdrop">
<div class="backdrop-paper"></div> <div class="backdrop-paper"></div>
</div> </div>
@ -98,7 +104,6 @@
</div> </div>
</main> </main>
<script src="{{ base_url }}/assets/javascripts/modernizr-79394028.js"></script> <script src="{{ base_url }}/assets/javascripts/modernizr-79394028.js"></script>
{% set repo_id = repo_url | replace('https://github.com/', '') %}
<script> <script>
var base_url = '{{ base_url }}'; var base_url = '{{ base_url }}';
var repo_id = '{{ repo_id }}'; var repo_id = '{{ repo_id }}';

View File

@ -1,6 +1,3 @@
{% if repo_name == 'GitHub' %}
{% set repo_id = repo_url | replace('https://github.com/', '') %}
{% endif %}
<nav aria-label="navigation"> <nav aria-label="navigation">
<a href="{{ repo_url }}" class="project"> <a href="{{ repo_url }}" class="project">
<div class="banner"> <div class="banner">

View File

@ -2,5 +2,5 @@
"assets/images/favicon.ico": "assets/images/favicon-e565ddfa.ico", "assets/images/favicon.ico": "assets/images/favicon-e565ddfa.ico",
"assets/javascripts/application.js": "assets/javascripts/application-d84ecdee.js", "assets/javascripts/application.js": "assets/javascripts/application-d84ecdee.js",
"assets/javascripts/modernizr.js": "assets/javascripts/modernizr-79394028.js", "assets/javascripts/modernizr.js": "assets/javascripts/modernizr-79394028.js",
"assets/stylesheets/application.css": "assets/stylesheets/application-334f02ec.css" "assets/stylesheets/application.css": "assets/stylesheets/application-1f184bc3.css"
} }

View File

@ -508,9 +508,9 @@ document.addEventListener('DOMContentLoaded', function() {
function(data, xhr) { function(data, xhr) {
var count = data.stargazers_count; var count = data.stargazers_count;
if (count > 10000) if (count > 10000)
count = (count / 1000).toFixed(0) + "k"; count = (count / 1000).toFixed(0) + 'k';
else if (count > 1000) else if (count > 1000)
count = (count / 1000).toFixed(1) + "k"; count = (count / 1000).toFixed(1) + 'k';
/* Set number of stars */ /* Set number of stars */
var stars = document.querySelector('.repo-stars .count'); var stars = document.querySelector('.repo-stars .count');

View File

@ -82,6 +82,18 @@
</head> </head>
<body> <body>
<!--
Sadly the jinja template engine is not very flexible - it doesn't support
regular expressions out-of-the-box. Since there might be a slash at the
end of the repository name, we just do a string comparison and kill it.
-->
{% 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 %}
<!-- Backdrop --> <!-- Backdrop -->
<div class="backdrop"> <div class="backdrop">
<div class="backdrop-paper"></div> <div class="backdrop-paper"></div>
@ -170,7 +182,6 @@
<script src="{{ base_url }}/assets/javascripts/modernizr.js"></script> <script src="{{ base_url }}/assets/javascripts/modernizr.js"></script>
<!-- Theme-related and custom javascripts --> <!-- Theme-related and custom javascripts -->
{% set repo_id = repo_url | replace('https://github.com/', '') %}
<script> <script>
var base_url = '{{ base_url }}'; var base_url = '{{ base_url }}';
var repo_id = '{{ repo_id }}'; var repo_id = '{{ repo_id }}';

View File

@ -1,7 +1,3 @@
{% if repo_name == 'GitHub' %}
{% set repo_id = repo_url | replace('https://github.com/', '') %}
{% endif %}
<!-- Navigation --> <!-- Navigation -->
<nav aria-label="navigation"> <nav aria-label="navigation">