添加贪吃蛇动画

1.创建一个 public 的仓库

image-20251204133647112

2.搜索 snk 项目,并 Fork 一下

image-20251204133748828

3.在刚刚创建的仓库中新建两个文件,README.mdmain.yml,其中 main.yml(名字随意) 需要放在 .github/workflows 文件夹下,这个文件夹是 githubAction 执行文件

image-20251204134025009

README.md 文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<picture>
<source
media="(prefers-color-scheme: dark)"
srcset="https://raw.githubusercontent.com/kluhten/kluhten/output/github-contribution-grid-snake-dark.svg"
/>
<source
media="(prefers-color-scheme: light)"
srcset="https://raw.githubusercontent.com/kluhten/kluhten/output/github-contribution-grid-snake.svg"
/>
<img
alt="github contribution grid snake animation"
src="https://raw.githubusercontent.com/kluhten/kluhten/output/github-contribution-grid-snake-dark.svg"
/>
</picture>

这段代码可以在这里找到:

image-20251204134123331

这里需要注意的是 https://raw.githubusercontent.com/xxx/xxx/output/github-contribution-grid-snake-dark.svg xxx要改成自己的仓库的路劲,否则该图片不会是你自己的贡献度

main.yml 文件内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
name: generate animation

on:
schedule:
- cron: "00 00 * * *"

workflow_dispatch:

push:
branches: [ main ]

jobs:
generate:
permissions:
contents: write
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
# generates a snake game from a github user (<github_user_name>) contributions graph, output a svg animation at <svg_out_path>
- name: generate github-contribution-grid-snake.svg
uses: Platane/snk/svg-only@v3
with:
github_user_name: ${{ github.repository_owner }}
outputs: |
dist/github-contribution-grid-snake.svg
dist/github-contribution-grid-snake-dark.svg?palette=github-dark


# push the content of <build_dir> to a branch
# the content will be available at https://raw.githubusercontent.com/<github_user>/<repository>/<target_branch>/<file> , or as github page
- name: push github-contribution-grid-snake.svg to the output branch
uses: crazy-max/ghaction-github-pages@v3.1.0
with:
target_branch: output
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

这段文件可以在这里找到:

image-20251204134200143

image-20251204134325239