|
1 | | -# GitHub breakout |
| 1 | +# Github Breakout |
2 | 2 |
|
3 | | -Generate a Breakout game SVG from a GitHub contribution graph |
| 3 | +Generate a Breakout game SVG from a GitHub user's contributions graph |
| 4 | + |
| 5 | +This project will grab your contribution graph through the GitHub API and generate images for light and dark mode: |
| 6 | + |
| 7 | +<picture> |
| 8 | + <source |
| 9 | + media="(prefers-color-scheme: dark)" |
| 10 | + srcset="example/dark.svg" |
| 11 | + /> |
| 12 | + <source |
| 13 | + media="(prefers-color-scheme: light)" |
| 14 | + srcset="example/light.svg" |
| 15 | + /> |
| 16 | + <img alt="Breakout Game" src="example/light.svg" /> |
| 17 | +</picture> |
| 18 | + |
| 19 | +## Usage |
| 20 | + |
| 21 | +### GitHub Action |
| 22 | + |
| 23 | +You can use the provided GitHub Action to build the SVGs so you can display them like on my profile ([github.com/cyprieng](https://github.com/cyprieng)): |
| 24 | + |
| 25 | +Generate the SVGs every day and commit them to your repository: |
| 26 | + |
| 27 | +```yaml |
| 28 | +name: generate breakout svg |
| 29 | + |
| 30 | +on: |
| 31 | + schedule: |
| 32 | + - cron: "0 */24 * * *" |
| 33 | + workflow_dispatch: |
| 34 | + |
| 35 | +jobs: |
| 36 | + generate-svg: |
| 37 | + permissions: |
| 38 | + contents: write |
| 39 | + runs-on: ubuntu-latest |
| 40 | + timeout-minutes: 5 |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout repository |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: generate SVG |
| 47 | + |
| 48 | + with: |
| 49 | + github_username: ${{ github.repository_owner }} |
| 50 | + |
| 51 | + - name: Move generated SVGs |
| 52 | + run: | |
| 53 | + mkdir -p images |
| 54 | + mv output/light.svg images/breakout-light.svg |
| 55 | + mv output/dark.svg images/breakout-dark.svg |
| 56 | +
|
| 57 | + - name: Configure git |
| 58 | + run: | |
| 59 | + git config user.name "github-actions[bot]" |
| 60 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 61 | +
|
| 62 | + - name: Commit and push SVGs |
| 63 | + run: | |
| 64 | + git add images/breakout-light.svg images/breakout-dark.svg |
| 65 | + git commit -m "chore: update breakout SVGs" || echo "No changes to commit" |
| 66 | + git push |
| 67 | +``` |
| 68 | +
|
| 69 | +Add them to your README.md: |
| 70 | +
|
| 71 | +```html |
| 72 | +<picture> |
| 73 | + <source |
| 74 | + media="(prefers-color-scheme: dark)" |
| 75 | + srcset="images/breakout-dark.svg" |
| 76 | + /> |
| 77 | + <source |
| 78 | + media="(prefers-color-scheme: light)" |
| 79 | + srcset="images/breakout-light.svg" |
| 80 | + /> |
| 81 | + <img alt="Breakout Game" src="images/breakout-light.svg" /> |
| 82 | +</picture> |
| 83 | +``` |
| 84 | + |
| 85 | +### CLI |
| 86 | + |
| 87 | +You need to get a GitHub Token, then you can run the following command: |
| 88 | + |
| 89 | +`node dist/cli.js {username} {github token} {dark mode: true/false}` |
| 90 | + |
| 91 | +### Library |
| 92 | + |
| 93 | +The package is currently not available on npm, so you can install it with: |
| 94 | + |
| 95 | +`npm i --save git+ssh://[email protected]:cyprieng/github-breakout.git` |
| 96 | + |
| 97 | +And then you can use it like this: |
| 98 | + |
| 99 | +```javascript |
| 100 | +import { generateSVG } from "github-breakout"; |
| 101 | + |
| 102 | +await generateSVG(username, token, false); |
| 103 | +``` |
| 104 | + |
| 105 | +### Try it |
| 106 | + |
| 107 | +You can try it here: [www.cyprien.io/projects/github-breakout](https://www.cyprien.io/projects/github-breakout/#try-it) |
0 commit comments