前言

上班摸鱼,看着Github主页有点单调,就像整点好玩的,通过了解,可以在同名仓库的Readme文件里编写个人主页,下面我来汇总一下。

建一个和用户名相同的仓库

贪吃蛇

贪吃蛇是我很喜欢的一个特效,看到蛇蛇吃掉你的贡献有一种莫名的解压。

首先,在setting选择action栏下面的general,然后给Workflow permissions设置读写权限。

建一个和用户名相同的仓库

然后在actions中创建新的工作流

建一个和用户名相同的仓库

创建一个yaml文件,将下面的代码粘贴进去

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
41
42
43
44
name: generate animation

on:
# run automatically every 24 hours
schedule:
- cron: "0 */24 * * *"

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

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



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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


# 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 }}

接着运行这个工作流,build成功之后可以在output中看到生成的svg

建一个和用户名相同的仓库

最后我们在Readme中嵌入,media方法可以适配dark和light两种主题,这样我们就在主页得到可爱的蛇蛇了

1
2
3
4
5
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/JCvvv/JCvvv/output/github-contribution-grid-snake-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/JCvvv/JCvvv/output/github-contribution-grid-snake.svg">
<img alt="github contribution grid snake animation" src="https://raw.githubusercontent.com/JCvvv/JCvvv/output/github-contribution-grid-snake.svg">
</picture>