Skip to content

Commit

Permalink
Fetch badges directly from Shields.io, Add more customizations, Add e…
Browse files Browse the repository at this point in the history
…asy to use badge generator
  • Loading branch information
therealsujitk committed Dec 9, 2023
1 parent 84696d5 commit 04d5e79
Show file tree
Hide file tree
Showing 53 changed files with 11,228 additions and 506 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 20.x
- run: yarn install --frozen-lockfile
- run: yarn run build
- name: Run git push
run: |
git config --global user.email "[email protected]"
git config --global user.name "earphone-jack"
git add --all
git commit -m "Build output for commit $GITHUB_SHA" || true
git push
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.DS_Store
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Vercel](http://therealsujitk-vercel-badge.vercel.app/?app=therealsujitk-vercel-badge) ![License](https://img.shields.io/badge/license-MIT-blue)

Include a [Vercel](http://vercel.com) deployment badge in your `README.md` file.
Include a [Vercel](http://vercel.com) deployment badge in your `README.md` file. Visit the [home page](http://therealsujitk-vercel-badge.vercel.app) to generate a badge for your Vercel project.

## Usage

Expand All @@ -24,21 +24,20 @@ For the application [`http://therealsujitk.vercel.app`](http://therealsujitk.ver

- **`?style=`** - The style of the badge. Available styles: **`flat`** (Default), **`flat-square`**, **`plastic`** & **`for-the-badge`**.
- **`?root=`** - Use this paramater if you'd like to check the deployment of a different path. Example: To check the deployment of [`http://therealsujitk.vercel.app/projects/vercel-badge`](http://therealsujitk.vercel.app/projects/vercel-badge), specify root as `projects/vercel-badge`.
- **`?logo=`** - Use this paramater if you'd like to disable the vercel logo on the badge. Available values: **`true`** (Default), **`false`**.
- **`?logo=`** - Use this paramater if you'd like to change the vercel logo on the badge. To learn more visit [the Shields.io documentation](https://shields.io/docs/logos).
- **`?name=`** - Use this parameter if you'd like to change the name of the badge.


To combine paramaters, use **`&`**. Example:

![Vercel](http://therealsujitk-vercel-badge.vercel.app/?app=therealsujitk-vercel-badge&style=for-the-badge&logo=false)
![Vercel](http://therealsujitk-vercel-badge.vercel.app/?app=therealsujitk-vercel-badge&style=for-the-badge&logo=none)

```http
```
http://therealsujitk-vercel-badge.vercel.app/?app=therealsujitk-vercel-badge&style=for-the-badge&logo=false
```

## Styles
### Links

| `flat` (Default) | `flat-square` | `plastic` | `for-the-badge` |
| ---------------- | ------------- | --------- | --------------- |
| ![Vercel](/public/assets/images/logo/vercel-deployed-flat.svg) | ![Vercel](/public/assets/images/logo/vercel-deployed-flat-square.svg) | ![Vercel](/public/assets/images/logo/vercel-deployed-plastic.svg) | ![Vercel](/public/assets/images/logo/vercel-deployed-for-the-badge.svg) |
| ![Vercel](/public/assets/images/logo/vercel-not-found-flat.svg) | ![Vercel](/public/assets/images/logo/vercel-not-found-flat-square.svg) | ![Vercel](/public/assets/images/logo/vercel-not-found-plastic.svg) | ![Vercel](/public/assets/images/logo/vercel-not-found-for-the-badge.svg) |
| ![Vercel](/public/assets/images/logo/vercel-failed-flat.svg) | ![Vercel](/public/assets/images/logo/vercel-failed-flat-square.svg) | ![Vercel](/public/assets/images/logo/vercel-failed-plastic.svg) | ![Vercel](/public/assets/images/logo/vercel-failed-for-the-badge.svg) |
- [Badge Generator](https://therealsujitk-vercel-badge.vercel.app)
- [About Me](https://therealsuji.tk)
- [Donate](https://therealsuji.tk/donate)
81 changes: 0 additions & 81 deletions app.js

This file was deleted.

93 changes: 93 additions & 0 deletions app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import express from 'express';
import got from 'got';
import http from 'http';
import https from 'https';
import NodeCache from 'node-cache';

const app = express();
const cache = new NodeCache();

interface Badge {
key: string,
value: string,
color: string,
style: string,
logo: string,
}

async function createBadge(badge: Badge) {
badge.value = badge.value.replace(/-/g, '--');
const url = new URL(`http://img.shields.io/badge/${badge.key}-${badge.value}-${badge.color}?style=${badge.style}&logo=${badge.logo}`);

if (cache.has(url.toString())) {
return cache.get(url.toString());
}

const response = (await got(url)).body;
cache.set(url.toString(), response);
return response;
}

app.use(express.static(__dirname + '/frontend/build', {index: false}));
app.get('/*', (req, res) => {

if (!("app" in req.query)) {
return res.status(200).sendFile(__dirname + '/frontend/build/index.html');
}

const appName = req.query.app;
const root = req.query.root ?? '';
const style = req.query.style ?? 'flat';
const badgeName = req.query.name ?? 'vercel'
const logo = req.query.logo ?? 'vercel';

const url = appName + '.vercel.app/' + root;
const handleRequest = async (statusCode: number = 404) => {
const badge: Badge = {
key: (badgeName as string).replace(/-/g, '--').replace(/_/g, '__'),
value: 'deployed',
color: 'brightgreen',
style: style as string,
logo: logo as string,
};

if (statusCode <= 599 && statusCode >= 500) {
// 500 - 599 -> Server Errors
badge.value = 'failed';
badge.color = 'red';
} else if (statusCode <= 499 && statusCode >= 400) {
// 400 - 499 -> Client Errors
badge.value = 'not-found';
badge.color = 'lightgrey';
} else if (statusCode <= 399 && statusCode >= 300) {
// 300 - 399 -> Redirects
}

// 200 - 299 -> Successful Responses
// 100 - 199 -> Informational Responses

res.setHeader('Content-type', 'image/svg+xml');
res.status(200).send(await createBadge(badge));
}

try {
https.get("https://" + url, async (response) => {
var statusCode = response.statusCode;
await handleRequest(statusCode);
}).on('error', () => {
// This could mean the HTTPS site is not available so we check for HTTP
http.get("http://" + url, async (response) => {
var statusCode = response.statusCode;
await handleRequest(statusCode);
}).on('error', () => {
// Invalid Application Name
handleRequest(404);
});
});
} catch {
// An error was encountered for some unknown reason
res.status(500).send('Internal Server Error. Please open an issue at <a href="https://github.com/therealsujitk/vercel-badge/issues">vercel-badge/issues</a>.');
}
});

export default app;
10 changes: 0 additions & 10 deletions bin/server.js

This file was deleted.

12 changes: 12 additions & 0 deletions bin/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import app from '../app';
import http from 'http';

const httpServer = http.createServer(app);
const port = process.env.PORT || 3000;

/*
Starting the listener
*/
httpServer.listen(port, () => {
console.log('listening on *:' + port);
});
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
46 changes: 46 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Getting Started with Create React App

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.\
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).
46 changes: 46 additions & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/joy": "^5.0.0-beta.17",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.2",
"@types/node": "^16.18.68",
"@types/react": "^18.2.42",
"@types/react-dom": "^18.2.17",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added frontend/public/favicon.ico
Binary file not shown.
Loading

0 comments on commit 04d5e79

Please sign in to comment.