mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2025-02-17 18:49:21 +01:00
Fixed JavaScript error for GitHub organization URLs
This commit is contained in:
parent
056e91e9f4
commit
0e30256604
File diff suppressed because one or more lines are too long
@ -149,7 +149,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ base_url }}/assets/javascripts/application-6b4ff16fa7.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/application-fb835c1558.js"></script>
|
||||
<script>app.initialize({url:{base:"{{ base_url }}"}})</script>
|
||||
{% for path in extra_javascript %}
|
||||
<script src="{{ path }}"></script>
|
||||
|
@ -43,7 +43,6 @@ export default class Abstract {
|
||||
const ref = (typeof el === "string")
|
||||
? document.querySelector(el)
|
||||
: el
|
||||
|
||||
if (!(ref instanceof HTMLAnchorElement))
|
||||
throw new ReferenceError
|
||||
this.el_ = ref
|
||||
|
@ -40,14 +40,17 @@ export default class GitHub extends Abstract {
|
||||
constructor(el) {
|
||||
super(el)
|
||||
|
||||
/* Extract user and repository name from URL, as we have to query for all
|
||||
/* Extract user (and repository name) from URL, as we have to query for all
|
||||
repositories, to omit 404 errors for private repositories */
|
||||
const [, user, name] = /^.+github\.com\/([^\/]+)\/([^\/]+).*$/
|
||||
const matches = /^.+github\.com\/([^\/]+)\/?([^\/]+)?.*$/
|
||||
.exec(this.base_)
|
||||
if (matches && matches.length === 3) {
|
||||
const [, user, name] = matches
|
||||
|
||||
/* Initialize base URL and repository name */
|
||||
this.base_ = `https://api.github.com/users/${user}/repos`
|
||||
this.name_ = name
|
||||
/* Initialize base URL and repository name */
|
||||
this.base_ = `https://api.github.com/users/${user}/repos`
|
||||
this.name_ = name
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,15 +60,27 @@ export default class GitHub extends Abstract {
|
||||
*/
|
||||
fetch_() {
|
||||
return fetch(this.base_)
|
||||
.then(response => response.json())
|
||||
.then(response => response.json(), () => {})
|
||||
.then(data => {
|
||||
const repo = data.find(item => item.name === this.name_)
|
||||
return repo
|
||||
? [
|
||||
`${this.format_(repo.stargazers_count)} Stars`,
|
||||
`${this.format_(repo.forks_count)} Forks`
|
||||
if (!(data instanceof Array))
|
||||
throw new TypeError
|
||||
|
||||
/* Display number of stars and forks, if repository is given */
|
||||
if (this.name_) {
|
||||
const repo = data.find(item => item.name === this.name_)
|
||||
return repo
|
||||
? [
|
||||
`${this.format_(repo.stargazers_count)} Stars`,
|
||||
`${this.format_(repo.forks_count)} Forks`
|
||||
]
|
||||
: []
|
||||
|
||||
/* Display number of repositories, otherwise */
|
||||
} else {
|
||||
return [
|
||||
`${data.length} Repositories`
|
||||
]
|
||||
: []
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user