Github主页设置贪吃蛇详细教程

先看最终实现结果:

有条贪吃蛇放在主页还是蛮酷的哈哈哈。接下来我来讲一讲怎么在Github主页添加一条贪吃蛇。

首先要修改自己的Github的主页,我们得有一个特殊的仓库------这个仓库必须与你的Github用户名保持一致,并且需要公开,没有的话可以自行创建。

接下来我们需要新建一个Github工作流,用于自动生成贪吃蛇动画。在该仓库点击新建文件:

注意路径问题,只有放在.github/workflows下工作流才会生效。工作流文件命名snake.yml

代码如下:

yaml 复制代码
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 }}          

需要注意的点:

  • 如果你的仓库默认主分支是master分支,请将代码中的main改为master

  • 查看Platane/snk/svg-only的最新版本,访问github.com/Platane/snk

  • 查看crazy-max/ghaction-github-pages的最新版本,访问github.com/crazy-max/g...

  • 设置PERSONAL_ACCESS_TOKEN,这个token应该有足够的权限来新建一个分支,并推送代码。关于如何新建token可以参考下面这篇文章的一些步骤:juejin.cn/post/726784...,在勾选token的权限时可以全部勾上(免得到时候权限不够),拿到具有相关权限的token后我们就需要在这个仓库设置PERSONAL_ACCESS_TOKEN。将自己的token按下面的操作新建保存就可以了。

点击Commit changes...后再点击Run workflow就可以了。

可以看到我们的仓库多了一个output分支,并且里面有亮色和暗色的贪吃蛇。

最后在你的Readme文档里面添加下面的内容即可:

markdown 复制代码
![暗色](https://raw.githubusercontent.com/你的用户名/你的仓库名/output/github-contribution-grid-snake-dark.svg)
![亮色](https://raw.githubusercontent.com/你的用户名/你的仓库名/output/github-contribution-grid-snake.svg)
相关推荐
passerby60612 小时前
完成前端时间处理的另一块版图
前端·github·web components
草梅友仁3 小时前
墨梅博客 1.4.0 发布与开源动态 | 2026 年第 6 周草梅周报
开源·github·ai编程
学电子她就能回来吗5 小时前
深度学习速成:损失函数与反向传播
人工智能·深度学习·学习·计算机视觉·github
xuhe28 小时前
[全流程详细教程]Docker部署ClawBot, 使用GLM4.7, 接入TG Bot实现私人助理. 解决Docker Openclaw Permission Denied问题
linux·docker·ai·github·tldr
宇宙帅猴9 小时前
GitHub 私有仓库认证完整指南:告别密码错误,使用 PAT 令牌
github
前端市界12 小时前
用 React 手搓一个 3D 翻页书籍组件,呼吸海浪式翻页,交互体验带感!
前端·架构·github
happyprince12 小时前
2026年02月07日热门github项目
github
CoderJia程序员甲13 小时前
GitHub 热榜项目 - 日榜(2026-02-06)
人工智能·ai·大模型·github·ai教程
荔枝吻14 小时前
忘记服务器密码,在Xshell7中查看已保存密码
运维·服务器·github
tod11317 小时前
TCP全连接队列与tcpdump抓包
网络·网络协议·tcp/ip·github·tcpdump