1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-11-24 07:30:12 +01:00

Fixed missing pagination on GitHub API

This commit is contained in:
squidfunk 2017-08-07 19:05:50 +02:00 committed by Martin Donath
parent 18b2ca47b2
commit cc7facb199
4 changed files with 33 additions and 25 deletions

File diff suppressed because one or more lines are too long

View File

@ -150,7 +150,7 @@
{% endblock %}
</div>
{% block scripts %}
<script src="{{ base_url }}/assets/javascripts/application-1d6ee6ee6c.js"></script>
<script src="{{ base_url }}/assets/javascripts/application-6940329b9f.js"></script>
{% set languages = lang.t("search.languages").split(",") %}
{% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %}

View File

@ -59,28 +59,37 @@ export default class GitHub extends Abstract {
* @return {Promise<Array<string>>} Promise returning an array of facts
*/
fetch_() {
return fetch(this.base_)
.then(response => response.json())
.then(data => {
if (!(data instanceof Array))
throw new TypeError
const paginate = (page = 0) => {
return fetch(`${this.base_}?per_page=30&page=${page}`)
.then(response => response.json())
.then(data => {
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 stars and forks, if repository is given */
if (this.name_) {
const repo = data.find(item => item.name === this.name_)
if (!repo && data.length === 30)
return paginate(page + 1)
/* If we found a repo, extract the facts */
return repo
? [
`${this.format_(repo.stargazers_count)} Stars`,
`${this.format_(repo.forks_count)} Forks`
]
: []
/* Display number of repositories, otherwise */
} else {
return [
`${data.length} Repositories`
]
: []
}
})
}
/* Display number of repositories, otherwise */
} else {
return [
`${data.length} Repositories`
]
}
})
/* Paginate through repos */
return paginate()
}
}

View File

@ -2020,9 +2020,9 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"
flow-bin@^0.51.1:
version "0.51.1"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.51.1.tgz#7929c6f0a94e765429fcb2ee6e468278faa9c732"
flow-bin@^0.52.0:
version "0.52.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.52.0.tgz#b6d9abe8bcd1ee5c62df386451a4e2553cadc3a3"
flow-jsdoc@^0.3.0:
version "0.3.0"