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 %} {% endblock %}
</div> </div>
{% block scripts %} {% 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(",") %} {% set languages = lang.t("search.languages").split(",") %}
{% if languages | length and languages[0] != "" %} {% if languages | length and languages[0] != "" %}
{% set path = base_url + "/assets/javascripts/lunr" %} {% set path = base_url + "/assets/javascripts/lunr" %}

View File

@ -59,7 +59,8 @@ export default class GitHub extends Abstract {
* @return {Promise<Array<string>>} Promise returning an array of facts * @return {Promise<Array<string>>} Promise returning an array of facts
*/ */
fetch_() { fetch_() {
return fetch(this.base_) const paginate = (page = 0) => {
return fetch(`${this.base_}?per_page=30&page=${page}`)
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (!(data instanceof Array)) if (!(data instanceof Array))
@ -68,6 +69,10 @@ export default class GitHub extends Abstract {
/* Display number of stars and forks, if repository is given */ /* Display number of stars and forks, if repository is given */
if (this.name_) { if (this.name_) {
const repo = data.find(item => item.name === 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 return repo
? [ ? [
`${this.format_(repo.stargazers_count)} Stars`, `${this.format_(repo.stargazers_count)} Stars`,
@ -83,4 +88,8 @@ export default class GitHub extends Abstract {
} }
}) })
} }
/* Paginate through repos */
return paginate()
}
} }

View File

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