Skip to content

Commit 2ad4628

Browse files
Implemented nice name for all stack exchange sites
1 parent a323470 commit 2ad4628

File tree

6 files changed

+407
-23
lines changed

6 files changed

+407
-23
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"scripts": {
99
"dev": "nodemon ./source/index.js",
1010
"start": "node ./source/index.js",
11-
"prod": "cross-env NODE_ENV=production node ./source/index.js"
11+
"prod": "cross-env NODE_ENV=production node ./source/index.js",
12+
"map": "node ./scripts/createMaps.js"
1213
},
1314
"repository": {
1415
"type": "git",

scripts/createMaps.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as dotenv from 'dotenv'
2+
import fetch from 'node-fetch'
3+
4+
dotenv.config()
5+
6+
const names = {}
7+
const icons = {}
8+
9+
fetch(
10+
`https://api.stackexchange.com/2.3/sites?key=${process.env.STACK_EXCHANGE_API_KEY}&pagesize=999`,
11+
)
12+
.then(async (response) => {
13+
const body = await response.json()
14+
console.log(body.items.length)
15+
const items = body.items
16+
17+
items.forEach(async ({ api_site_parameter, name, icon_url }) => {
18+
names[api_site_parameter] = name
19+
icons[api_site_parameter] = icon_url
20+
})
21+
})
22+
.then(async () => {
23+
console.log(names)
24+
console.log(icons)
25+
})

source/components/ReputationContainer/reputationContainer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const getRep = async (rep, surfix = '') => {
1+
const getRep = (rep, surfix = '') => {
22
if (rep > 9999) {
33
switch (surfix) {
44
case '':
@@ -13,7 +13,7 @@ const getRep = async (rep, surfix = '') => {
1313
}
1414

1515
let obj = {}
16-
obj = await getRep(Math.round(rep / 1000), surfix)
16+
obj = getRep(Math.round(rep / 1000), surfix)
1717
dist = obj.dist
1818
rep = obj.rep
1919
surfix = obj.surfix
@@ -25,8 +25,8 @@ const getRep = async (rep, surfix = '') => {
2525
}
2626
}
2727

28-
export const reputationContainer = async (useImage, reputation) => {
29-
const reputationInfo = await getRep(reputation)
28+
export const reputationContainer = (useImage, reputation) => {
29+
const reputationInfo = getRep(reputation)
3030

3131
const reputationText = `${reputationInfo.rep}${reputationInfo.surfix}`
3232
return `

0 commit comments

Comments
 (0)