diff --git a/README.md b/README.md index 4dc9064..26d364d 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Copy paste following markdown into your markdown content, and that's it. Easy Easy Tammam Tammam! -Change the `?userID=` value to your StackOverflow's userID. +Change the `?userID=` value to your StackExchange userID (for the relevant site). ```md [![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042)](https://stackoverflow.com/users/6558042/omid-nikrah) @@ -28,21 +28,38 @@ If you want to have a compact layout, just you need to add `layout=compact` as a [![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042&layout=compact)](https://stackoverflow.com/users/6558042/omid-nikrah) [![Omid Nikrah StackOverflow](https://github-readme-stackoverflow.vercel.app/?userID=6558042&layout=compact&theme=dark)](https://stackoverflow.com/users/6558042/omid-nikrah) +#### Other Sites + +You can use other StackExchange sites instead of StackOverflow too, such as Biology StackExchange or AskUbuntu. Just add `site={SITE}` as a parameter. Examples: +- `site=biology` +- `site=askubuntu` +- `site=money` + +The site name provided as a parameter must be the same as the domain for that site. For example, Personal Finance and Money StackExchange has a URL of `money.stackexchange.com`, so `site=money` must be provided. + +> **Warning** +> Different sites have different userIDs. So your StackOverflow userID will not be the same as your Biology StackExchange userID. + +[![Zohan Subhash Biology.SE](https://github-readme-stackoverflow.zohan.tech/?userID=68669&site=biology)](https://biology.stackexchange.com/users/68669/zo-bro-23) +[![Zohan Subhash Biology.SE](https://github-readme-stackoverflow.zohan.tech/?userID=68669&theme=dark&site=biology)](https://biology.stackexchange.com/users/68669/zo-bro-23)
## Options | Name | Description | Default value | | ---------- | ------------------------------- | -------------------------- | -| userID | Your StackOverflow userID | REQUIRED | +| userID | Your StackExchange userID | REQUIRED | | theme | Theme of the StackOverflow card (light or dark) | light | -| layout | Layout of the StackOverflow card (compact or default) | default | +| layout | Layout of the StackOverflow card (compact or default) | default | +| site | Which StackExchange site to get the data from | stackoverflow |
## Contributors - [Omid Nikrah](https://github.com/omidnikrah) - [Soroush Chehresa](https://github.com/soroushchehresa) +- [Zohan Subhash](https://github.com/Zo-Bro-23) +- [Jéf Bueno](https://github.com/jfbueno)
diff --git a/index.js b/index.js index 60a46b7..425b4fb 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const StackOverflowCard = require('./src/StackOverflowCard'); http.createServer(async (req, res) => { const reqURL = url.parse(req.url, true); - const { userID, theme = 'light', layout = 'default' } = reqURL.query; + const { userID, theme = 'light', layout = 'default', site = 'stackoverflow' } = reqURL.query; if (!userID) { res.write(JSON.stringify({error: 'Add your StackOverflow userID as query string'})); @@ -13,11 +13,11 @@ http.createServer(async (req, res) => { return; } - const responseArticles = await fetch(`https://api.stackexchange.com/2.2/users/${userID}?site=stackoverflow&filter=!--1nZv)deGu1`); + const responseArticles = await fetch(`https://api.stackexchange.com/2.2/users/${userID}?site=${site}&filter=!--1nZv)deGu1`); const json = await responseArticles.json(); if (!json.items || json.items.length === 0) { - res.write(JSON.stringify({error: 'Your stackoverflow userID is not correct'})); + res.write(JSON.stringify({error: 'Your userID/site is not valid'})); res.end(); return; } @@ -33,4 +33,4 @@ http.createServer(async (req, res) => { res.end(); }).listen(process.env.PORT || 3000, function(){ console.log("server start at port 3000"); -}); \ No newline at end of file +}); diff --git a/vercel.json b/vercel.json index 33d8629..d75206a 100644 --- a/vercel.json +++ b/vercel.json @@ -1,6 +1,13 @@ { + "version": 2, "builds": [{ "src": "index.js", - "use": "@now/node-server" - }] + "use": "@vercel/node" + }], + "routes": [ + { + "src": "/(.*)", + "dest": "index.js" + } + ] }