File tree Expand file tree Collapse file tree 8 files changed +49
-48
lines changed Expand file tree Collapse file tree 8 files changed +49
-48
lines changed Original file line number Diff line number Diff line change
1
+ {}
Original file line number Diff line number Diff line change 1
- import { makeBadge } from ' ../../../../lib/badge' ;
2
- import { html } from ' ../../../../lib/fetch' ;
1
+ import { makeBadge } from " ../../../../lib/badge" ;
2
+ import { html } from " ../../../../lib/fetch" ;
3
3
4
4
export default makeBadge ( async ( { country, id } ) => {
5
5
const url = `https://apps.apple.com/${ country } /app/${ id } ` ;
6
6
const dom = await html ( url ) ;
7
7
const schema = JSON . parse (
8
8
dom . window . document . querySelector (
9
- 'script[name="schema:software-application"]' ,
10
- ) ?. textContent ?? '' ,
9
+ 'script[name="schema:software-application"]'
10
+ ) ?. textContent ?? ""
11
11
) ;
12
12
13
13
if ( ! schema . aggregateRating ) {
14
14
return {
15
- label : ' rating' ,
16
- color : ' gray' ,
17
- status : ' unavailable' ,
15
+ label : " rating" ,
16
+ color : " gray" ,
17
+ status : " unavailable" ,
18
18
} ;
19
19
}
20
20
const reviewCount = schema . aggregateRating . reviewCount ;
21
21
22
22
return {
23
- label : ' rating count' ,
24
- color : ' 0070c9' ,
23
+ label : " rating count" ,
24
+ color : " 0070c9" ,
25
25
status : reviewCount . toString ( ) ,
26
26
} ;
27
27
} ) ;
Original file line number Diff line number Diff line change 1
- import { makeBadge } from ' ../../../../lib/badge' ;
2
- import { html } from ' ../../../../lib/fetch' ;
1
+ import { makeBadge } from " ../../../../lib/badge" ;
2
+ import { html } from " ../../../../lib/fetch" ;
3
3
4
4
export default makeBadge ( async ( { country, id } ) => {
5
5
const url = `https://apps.apple.com/${ country } /app/${ id } ` ;
6
6
const dom = await html ( url ) ;
7
7
const schema = JSON . parse (
8
8
dom . window . document . querySelector (
9
- 'script[name="schema:software-application"]' ,
10
- ) ?. textContent ?? '' ,
9
+ 'script[name="schema:software-application"]'
10
+ ) ?. textContent ?? ""
11
11
) ;
12
12
13
13
if ( ! schema . aggregateRating ) {
14
14
return {
15
- label : ' rating' ,
16
- color : ' gray' ,
17
- status : ' unavailable' ,
15
+ label : " rating" ,
16
+ color : " gray" ,
17
+ status : " unavailable" ,
18
18
} ;
19
19
}
20
20
const rating = parseInt ( schema . aggregateRating . ratingValue ) ;
21
21
const stars = '★' . repeat ( rating ) ;
22
22
23
23
return {
24
- label : ' rating' ,
25
- color : ' 0070c9' ,
24
+ label : " rating" ,
25
+ color : " 0070c9" ,
26
26
status : stars ,
27
27
} ;
28
28
} ) ;
Original file line number Diff line number Diff line change 1
- import { makeBadge } from ' ../../../lib/badge' ;
2
- import { text } from ' ../../../lib/fetch' ;
1
+ import { makeBadge } from " ../../../lib/badge" ;
2
+ import { text } from " ../../../lib/fetch" ;
3
3
4
4
export default makeBadge ( async ( { url } ) => {
5
5
const status = await text (
6
6
`https://bookmark.hatenaapis.com/count/entry?url=https://${ encodeURIComponent (
7
- url as string ,
8
- ) } `,
7
+ url as string
8
+ ) } `
9
9
) ;
10
10
11
11
return {
12
- label : ' bookmarks' ,
13
- color : ' 04A4DE' ,
12
+ label : " bookmarks" ,
13
+ color : " 04A4DE" ,
14
14
status,
15
15
} ;
16
16
} ) ;
Original file line number Diff line number Diff line change 1
- import { makeBadge } from ' ../../../lib/badge' ;
2
- import { graphql } from ' ../../../lib/fetch' ;
1
+ import { makeBadge } from " ../../../lib/badge" ;
2
+ import { graphql } from " ../../../lib/fetch" ;
3
3
4
4
export default makeBadge ( async ( { slug } ) => {
5
5
const status = await graphql (
6
- ' https://api.producthunt.com/v2/api/graphql' ,
6
+ " https://api.producthunt.com/v2/api/graphql" ,
7
7
`
8
8
{
9
9
post(slug: "${ slug } ") {
@@ -15,20 +15,20 @@ export default makeBadge(async ({ slug }) => {
15
15
headers : {
16
16
authorization : `Bearer ${ process . env . PRODUCT_HUNT_TOKEN } ` ,
17
17
} ,
18
- } ,
18
+ }
19
19
) ;
20
20
21
21
if ( ! status . post ) {
22
22
return {
23
- label : ' upvotes' ,
24
- color : ' gray' ,
25
- status : ' not found' ,
23
+ label : " upvotes" ,
24
+ color : " gray" ,
25
+ status : " not found" ,
26
26
} ;
27
27
}
28
28
29
29
return {
30
- label : ' upvotes' ,
31
- color : ' cc4d29' ,
30
+ label : " upvotes" ,
31
+ color : " cc4d29" ,
32
32
status : status . post . votesCount . toString ( ) ,
33
33
} ;
34
34
} ) ;
Original file line number Diff line number Diff line change 18
18
< div id ="app "> </ div >
19
19
< script >
20
20
window . $docsify = {
21
- name : ' badge.now.sh' ,
22
- repo : ' uetchy/badge' ,
21
+ name : " badge.now.sh" ,
22
+ repo : " uetchy/badge" ,
23
23
} ;
24
24
</ script >
25
25
< script src ="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js "> </ script >
Original file line number Diff line number Diff line change 1
- import { NowRequest , NowResponse , NowRequestQuery } from ' @vercel/node' ;
2
- import { badgen } from ' badgen' ;
1
+ import { NowRequest , NowResponse , NowRequestQuery } from " @vercel/node" ;
2
+ import { badgen } from " badgen" ;
3
3
4
4
export interface BadgenOptions {
5
5
status : string ;
6
6
subject ?: string ;
7
7
color ?: string ;
8
8
label ?: string ;
9
9
labelColor ?: string ;
10
- style ?: ' flat' | ' classic' ;
10
+ style ?: " flat" | " classic" ;
11
11
icon ?: string ;
12
12
iconWidth ?: number ;
13
13
scale ?: number ;
14
14
}
15
15
16
16
export function makeBadge (
17
- resolve : ( query : NowRequestQuery ) => Promise < BadgenOptions > | BadgenOptions ,
17
+ resolve : ( query : NowRequestQuery ) => Promise < BadgenOptions > | BadgenOptions
18
18
) {
19
19
return async ( req : NowRequest , res : NowResponse ) => {
20
20
const isFlat = req . query . flat !== undefined ;
21
21
delete req . query . flat ;
22
22
23
- res . setHeader ( ' Content-Type' , ' image/svg+xml' ) ;
23
+ res . setHeader ( " Content-Type" , " image/svg+xml" ) ;
24
24
25
25
try {
26
26
const badge = badgen ( {
27
27
...( await Promise . resolve ( resolve ( req . query ) ) ) ,
28
- style : isFlat ? ' flat' : ' classic' ,
28
+ style : isFlat ? " flat" : " classic" ,
29
29
} ) ;
30
30
31
- res . setHeader ( ' Cache-Control' , ' s-maxage=86400' ) ;
31
+ res . setHeader ( " Cache-Control" , " s-maxage=86400" ) ;
32
32
res . send ( badge ) ;
33
33
} catch ( err ) {
34
34
res . send (
35
35
badgen ( {
36
- label : ' error' ,
37
- color : ' gray' ,
36
+ label : " error" ,
37
+ color : " gray" ,
38
38
status : err . message ,
39
- } ) ,
39
+ } )
40
40
) ;
41
41
}
42
42
} ;
Original file line number Diff line number Diff line change 1
- import ' cross-fetch/polyfill' ;
2
- import { JSDOM } from ' jsdom' ;
3
- import { GraphQLClient } from ' graphql-request' ;
1
+ import " cross-fetch/polyfill" ;
2
+ import { JSDOM } from " jsdom" ;
3
+ import { GraphQLClient } from " graphql-request" ;
4
4
5
5
export async function graphql ( url : string , query : string , init ?: RequestInit ) {
6
6
const graphQLClient = new GraphQLClient ( url , init ) ;
You can’t perform that action at this time.
0 commit comments