mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fixed stats for private GitHub repositories
This commit is contained in:
parent
b5353cbc67
commit
ca05a2d342
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/bundle.f81dfb4d.min.js.map
Normal file
1
material/assets/javascripts/bundle.f81dfb4d.min.js.map
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/vendor.0ac82a11.min.js.map
Normal file
1
material/assets/javascripts/vendor.0ac82a11.min.js.map
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,8 +1,8 @@
|
||||
{
|
||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.7836ba4d.min.js",
|
||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.7836ba4d.min.js.map",
|
||||
"assets/javascripts/vendor.js": "assets/javascripts/vendor.fd16492e.min.js",
|
||||
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.fd16492e.min.js.map",
|
||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.f81dfb4d.min.js",
|
||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.f81dfb4d.min.js.map",
|
||||
"assets/javascripts/vendor.js": "assets/javascripts/vendor.0ac82a11.min.js",
|
||||
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.0ac82a11.min.js.map",
|
||||
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.4ac00218.min.js",
|
||||
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.4ac00218.min.js.map",
|
||||
"assets/stylesheets/main.css": "assets/stylesheets/main.19753c6b.min.css",
|
||||
|
@ -177,8 +177,8 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ 'assets/javascripts/vendor.fd16492e.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/bundle.7836ba4d.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/vendor.0ac82a11.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/bundle.f81dfb4d.min.js' | url }}"></script>
|
||||
{%- set translations = {} -%}
|
||||
{%- for key in [
|
||||
"clipboard.copy",
|
||||
|
@ -22,7 +22,13 @@
|
||||
|
||||
import { Repo, User } from "github-types"
|
||||
import { Observable, from } from "rxjs"
|
||||
import { map } from "rxjs/operators"
|
||||
import {
|
||||
defaultIfEmpty,
|
||||
filter,
|
||||
map,
|
||||
share,
|
||||
switchMap
|
||||
} from "rxjs/operators"
|
||||
|
||||
import { round } from "utilities"
|
||||
|
||||
@ -46,25 +52,29 @@ export function fetchSourceFactsFromGitHub(
|
||||
const url = typeof repo !== "undefined"
|
||||
? `https://api.github.com/repos/${user}/${repo}`
|
||||
: `https://api.github.com/users/${user}`
|
||||
return from(fetch(url).then(res => res.json()))
|
||||
return from(fetch(url))
|
||||
.pipe(
|
||||
filter(res => res.status === 200),
|
||||
switchMap(res => res.json()),
|
||||
map(data => {
|
||||
|
||||
/* GitHub repository */
|
||||
if (typeof repo !== "undefined") {
|
||||
const { stargazers_count, forks_count }: Repo = data
|
||||
return [
|
||||
`${round(stargazers_count || 0)} Stars`,
|
||||
`${round(forks_count || 0)} Forks`
|
||||
`${round(stargazers_count!)} Stars`,
|
||||
`${round(forks_count!)} Forks`
|
||||
]
|
||||
|
||||
/* GitHub user/organization */
|
||||
} else {
|
||||
const { public_repos }: User = data
|
||||
return [
|
||||
`${round(public_repos || 0)} Repositories`
|
||||
`${round(public_repos!)} Repositories`
|
||||
]
|
||||
}
|
||||
})
|
||||
}),
|
||||
defaultIfEmpty([]),
|
||||
share()
|
||||
)
|
||||
}
|
||||
|
@ -22,7 +22,13 @@
|
||||
|
||||
import { ProjectSchema } from "gitlab"
|
||||
import { Observable, from } from "rxjs"
|
||||
import { map } from "rxjs/operators"
|
||||
import {
|
||||
defaultIfEmpty,
|
||||
filter,
|
||||
map,
|
||||
share,
|
||||
switchMap
|
||||
} from "rxjs/operators"
|
||||
|
||||
import { round } from "utilities"
|
||||
|
||||
@ -44,11 +50,15 @@ export function fetchSourceFactsFromGitLab(
|
||||
base: string, project: string
|
||||
): Observable<SourceFacts> {
|
||||
const url = `https://${base}/api/v4/projects/${encodeURIComponent(project)}`
|
||||
return from(fetch(url).then(res => res.json()))
|
||||
return from(fetch(url))
|
||||
.pipe(
|
||||
filter(res => res.status === 200),
|
||||
switchMap(res => res.json()),
|
||||
map(({ star_count, forks_count }: ProjectSchema) => ([
|
||||
`${round(star_count)} Stars`,
|
||||
`${round(forks_count)} Forks`
|
||||
]))
|
||||
])),
|
||||
defaultIfEmpty([]),
|
||||
share()
|
||||
)
|
||||
}
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
import { NEVER, Observable } from "rxjs"
|
||||
import { catchError, map, switchMap } from "rxjs/operators"
|
||||
import { catchError, filter, map, switchMap } from "rxjs/operators"
|
||||
|
||||
import { getElementOrThrow, getElements } from "browser"
|
||||
import { renderSource } from "templates"
|
||||
@ -69,12 +69,12 @@ function fetchSourceFacts(
|
||||
|
||||
/* GitHub repository */
|
||||
case "github":
|
||||
const [, user, repo] = url.match(/^.+github\.com\/([^\/]+)\/?([^\/]+)?/i)
|
||||
const [, user, repo] = url.match(/^.+github\.com\/([^\/]+)\/?([^\/]+)?/i)!
|
||||
return fetchSourceFactsFromGitHub(user, repo)
|
||||
|
||||
/* GitLab repository */
|
||||
case "gitlab":
|
||||
const [, base, slug] = url.match(/^.+?([^\/]*gitlab[^\/]+)\/(.+?)\/?$/i)
|
||||
const [, base, slug] = url.match(/^.+?([^\/]*gitlab[^\/]+)\/(.+?)\/?$/i)!
|
||||
return fetchSourceFactsFromGitLab(base, slug)
|
||||
|
||||
/* Everything else */
|
||||
@ -104,6 +104,7 @@ export function patchSource(
|
||||
switchMap(({ href }) => (
|
||||
cache(`${hash(href)}`, () => fetchSourceFacts(href))
|
||||
)),
|
||||
filter(facts => facts.length > 0),
|
||||
catchError(() => NEVER)
|
||||
)
|
||||
.subscribe(facts => {
|
||||
|
Loading…
Reference in New Issue
Block a user