前言

如何在 Github 主页上设置贪吃蛇。

源教程地址:https://blog.csdn.net/m0_63230155/article/details/136700206

最终效果图:

操作系统:Windows 11 家庭中文版

步骤

  1. 在 Github 上创建一个与用户同名 Public 的仓库(如 LuYF-Lemon-love)。

  2. 创建一个 Github 工作流,用于自动生成贪吃蛇动画。即创建一个文件 .github/workflows/snake.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
39
40
name: generate animation

on:
# run automatically every 12 hours
schedule:
- cron: "0 2 * * *"

# allows to manually run the job at any time
workflow_dispatch:

# run on every push on the main branch
push:
branches:
- main



jobs:
generate:
runs-on: ubuntu-latest
timeout-minutes: 10

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@v4
with:
target_branch: output
build_dir: dist
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
  1. 生成一个 token,(具备 workflow 权限即可),步骤依次为: Github 用户设置 (Settings)-> Developer Settings -> Personal access tokens -> Tokens (classic) -> Generate new token -> Generate new token (classic) -> 生成具备 workflow 权限的即可

复制生成的 Token,一定要保存好,可以放到备忘录里面,这玩意儿只能看一次。

  1. 将自己的 token 按下面的操作新建保存就可以了。

  1. 重新运行工作流。

  1. README.md 中填写下面代码,即会出现两条贪吃蛇。
1
2
![暗色](https://raw.githubusercontent.com/你的用户名/你的仓库名/output/github-contribution-grid-snake-dark.svg)
![亮色](https://raw.githubusercontent.com/你的用户名/你的仓库名/output/github-contribution-grid-snake.svg)

我的主页仓库为: https://github.com/LuYF-Lemon-love/LuYF-Lemon-love

结语

第一百一十七篇博文写完,开心!!!!

今天,也是充满希望的一天。