利用 template 打造属于自己的 github 首页

1 篇文章 0 订阅


​ 笔记内容按照 中文文案排版指北 进行排版,以保证内容的可读性。
自动化排版工具 ,clone 下来之后,点击 index.html 就可以使用了。

利用 template 打造属于自己的 github 首页

准备模板

README.md.tpl 文件如下:

<h1 align="center">Hi 👋, I'm {{.Name}} ⏱️</h1>
<h3 align="center">{{.SelfDescription}}</h3>
<h2 align="center"><em>🌟 {{.Motto}}<em> 💪</h2>
<p align="center">
	<img src="https://github-readme-stats.vercel.app/api?username={{.GithubName}}&theme=dracula&show_icons=true" alt="stats loading failure" width="380" height="152" />
	<img src="http://github-readme-streak-stats.herokuapp.com?user={{.GithubName}}&theme=dracula&hide_border=false" alt="streak stats loading failure" width="380" height="152"/>
</p>

<p align="center">
	<a href="https://github.com/ryo-ma/github-profile-trophy"><img src="https://github-profile-trophy.vercel.app/?username={{.GithubName}}" alt="profile loading failure" /></a>
</p>

<strong>Check out my work below!</strong>Time I contributed this year: 🎉<img src="https://img.shields.io/badge/wakatime-2178hrs_30mins-blue?logo=wakatime&color=blue">🎉

<h4 align="left">🔭 Check out what I'm currently working on {{.StudyContent}}</h4>
- {{.StudyContentDescription}} - 👀

<h4 align="left">🌱 Check out my recent projects</h4>
{{ range .RecentProjects -}}
- [{{.Name}}]({{.URL}}) - {{.Description}}
{{end}}
<h4 align="left">⚡ Check out what I’m currently learning </h4>
- {{ join .LearnTechAbility " And "}}

<h4 align="left">📫 How to reach me</h4>
- {{.Email}}

#### 🚧 My Todoist Stats: ⬇️👀
<details><summary><b>💡 more (about github❗)</b></summary>
<hr></hr>
### 🔮 Platform & Tools

[![](https://img.shields.io/badge/mac%20os-292e33?style=for-the-badge&logo=apple&logoColor=ffffff)](https://www.apple.com/macos/big-sur/)
[![](https://img.shields.io/badge/Arch%20Linux-1793D1?logo=arch-linux&logoColor=fff&style=for-the-badge)](https://archlinux.org/)
[![](https://img.shields.io/badge/FireFox-FF7139?style=for-the-badge&logo=Firefox-Browser&logoColor=ffffff)](https://www.mozilla.org/zh-CN/firefox/new/)
[![](https://img.shields.io/badge/Vercel-%23000000.svg?style=for-the-badge&logo=vercel&logoColor=white)](https://vercel.com/)
![](https://img.shields.io/badge/OnePlus-%23F5010C.svg?style=for-the-badge&logo=oneplus&logoColor=white)
[![](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)](https://t.me/cloudnativer)

[![](https://img.shields.io/badge/IDE-Goland-black?style=flat-square&logo=goland&logoColor=ffffff)](https://www.jetbrains.com/)
[![](https://img.shields.io/badge/Editor-Visual%20Studio%20Code-007ACC?style=flat-square&logo=visual-studio-code&logoColor=ffffff)](https://code.visualstudio.com/)
[![](https://img.shields.io/badge/Note-Notion-000000?style=flat-square&logo=notion&logoColor=ffffff)](https://notion.so)


[![](https://img.shields.io/badge/OS-Arch%20Linux-33aadd?style=flat-square&logo=arch-linux&logoColor=ffffff)](https://www.archlinux.org/)
[![](https://img.shields.io/badge/macOS-Big%20Sur-292e33?style=flat-square&logo=apple&logoColor=ffffff)](https://www.apple.com/macos/big-sur/)
[![](https://img.shields.io/badge/Windows-11-4e9eee?style=flat-square&logo=windows&logoColor=ffffff)](https://www.microsoft.com/windows/windows-11)
[![](https://img.shields.io/badge/IDE-Visual%20Studio%20Code-blue?style=flat-square&logo=visual-studio-code&logoColor=ffffff)](https://code.visualstudio.com/)

[![](https://img.shields.io/badge/OnePlus-7%20Pro-f5010c?style=flat-square&logo=oneplus&logoColor=ffffff)](https://www.oneplus.com/)
[![](https://img.shields.io/badge/iPhone-XS-999999?style=flat-square&logo=apple&logoColor=ffffff)](https://www.apple.com/)
[![](https://img.shields.io/badge/Blackberry-Classic-000000?style=flat-square&logo=blackberry&logoColor=ffffff)](https://www.blackberry.com/)

[![](https://img.shields.io/badge/-Webpack-8dd6f9?style=flat-square&logo=webpack&logoColor=white)](https://webpack.js.org/)
[![](https://img.shields.io/badge/-React-61dafb?style=flat-square&logo=react&logoColor=ffffff)](https://reactjs.org/)
[![](https://img.shields.io/badge/-Docker-2496ED?style=flat-square&logo=docker&logoColor=ffffff)](https://www.docker.com/)
[![](https://img.shields.io/badge/-Yarn-2c8ebb?style=flat-square&logo=yarn&logoColor=ffffff)](https://yarnpkg.com/)
[![](https://img.shields.io/badge/-TypeScript-007acc?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
[![](https://img.shields.io/badge/-CSS3-1572B6?style=flat-square&logo=css3&logoColor=white)](https://www.w3.org/Style/CSS/)
[![](https://img.shields.io/badge/-Less-1d365d?style=flat-square&logo=less&logoColor=ffffff)](https://lesscss.org/)
[![](https://img.shields.io/badge/-NPM-cb3837?style=flat-square&logo=npm&logoColor=white)](https://npmjs.com/)
[![](https://img.shields.io/badge/-PostCSS-dd3a0a?style=flat-square&logo=postcss&logoColor=white)](https://postcss.org/)
[![](https://img.shields.io/badge/-HTML5-E34F26?style=flat-square&logo=html5&logoColor=white)](https://html.spec.whatwg.org/)
[![](https://img.shields.io/badge/-Git-f05032?style=flat-square&logo=git&logoColor=white)](https://git-scm.com/)
[![](https://img.shields.io/badge/-rollup.js-ec4a3f?style=flat-square&logo=rollup.js&logoColor=ffffff)](https://rollupjs.org/)
[![](https://img.shields.io/badge/-Stylus-ff6347?style=flat-square&logo=stylus&logoColor=ffffff)](https://stylus-lang.com/)
[![](https://img.shields.io/badge/-Serverless-fd5750?style=flat-square&logo=serverless&logoColor=ffffff)](https://www.serverless.com/)
[![](https://img.shields.io/badge/-Linux-fcc624?style=flat-square&logo=linux&logoColor=white)](https://www.linuxfoundation.org/)
[![](https://img.shields.io/badge/-JavaScript-f7e018?style=flat-square&logo=javascript&logoColor=white)](https://www.ecma-international.org/)
[![](https://img.shields.io/badge/-Vue.js-4fc08d?style=flat-square&logo=vue.js&logoColor=ffffff)](https://vuejs.org/)
[![](https://img.shields.io/badge/-MongoDB-47a248?style=flat-square&logo=mongodb&logoColor=ffffff)](https://www.mongodb.com/)
[![](https://img.shields.io/badge/-Nginx-269539?style=flat-square&logo=nginx&logoColor=ffffff)](https://nginx.org/)
[![](https://img.shields.io/badge/-Node.js-43853d?style=flat-square&logo=node.js&logoColor=ffffff)](https://nodejs.org/)


### 🗃️ Code & Skills

![](https://skillicons.dev/icons?i=kubernetes,grafana,prometheus,docker,linux,ansible,cloudflare,css,github,go,md)
[![](https://img.shields.io/badge/-WireGuard-88171A?style=flat-square&logo=wireguard&logoColor=ffffff)](https://www.wireguard.com/)
[![](https://img.shields.io/badge/-Kubernetes-326CE5?style=flat-square&logo=kubernetes&logoColor=ffffff)](https://kubernetes.io/)
[![](https://img.shields.io/badge/-Docker-2496ED?style=flat-square&logo=docker&logoColor=ffffff)](https://www.docker.com/)
[![](https://img.shields.io/badge/-Podman-892CA0?style=flat-square&logo=podman&logoColor=ffffff)](https://podman.io/)
[![](https://img.shields.io/badge/-Prometheus-E6522C?style=flat-square&logo=prometheus&logoColor=ffffff)](https://prometheus.io/)
[![](https://img.shields.io/badge/-Grafana-F46800?style=flat-square&logo=grafana&logoColor=ffffff)](https://grafana.com/)
[![](https://img.shields.io/badge/-Harbor-60B932?style=flat-square&logo=harbor&logoColor=ffffff)](https://goharbor.io/)
[![](https://img.shields.io/badge/-Consul-F24C53?style=flat-square&logo=consul&logoColor=ffffff)](https://www.consul.io/)

[![](https://img.shields.io/badge/-Hugo-FF4088?style=flat-square&logo=hugo&logoColor=ffffff)](https://gohugo.io/)
[![](https://img.shields.io/badge/-Linux-Fcc624?style=flat-square&logo=linux&logoColor=ffffff)](https://www.linux.org/)
[![](https://img.shields.io/badge/-Nginx-269539?style=flat-square&logo=nginx&logoColor=ffffff)](https://nginx.org/)
[![](https://img.shields.io/badge/-GitHub%20Actions-2088FF?style=flat-square&logo=github-actions&logoColor=ffffff)](https://github.com/features/actions)
[![](https://img.shields.io/badge/-Golang-00ADD8?style=flat-square&logo=go&logoColor=ffffff)](https://golang.org/)
[![](https://img.shields.io/badge/-Ceph-EF5C55?style=flat-square&logo=ceph&logoColor=ffffff)](https://ceph.io/)
[![](https://img.shields.io/badge/-Ansible-EE0000?style=flat-square&logo=ansible&logoColor=ffffff)](https://www.ansible.com/)
[![](https://img.shields.io/badge/-Markdown-black?style=flat-square&logo=markdown&logoColor=ffffff)](https://www.markdownguide.org/)

</br>
</details>
 🚀

解释一下:

第一行:介绍一下自己是谁
第二行:描述自己 (如 A passionate developer)
第三行:人生格言

github-readme-stats:动态生成 GitHub 统计信息
github-readme-streak-stats:显示您的总贡献、当前连胜和最长连胜
github-profile-trophy:动态生成的 GitHub 奖杯
以上三个工具来自于更多资源 ,可以跟据个人需求自行选择

第 13 行 taketime 是一个开发人员的自动时间跟踪工具,可以统计编码时间,类似的还有 Code time,在这里,只是放了一个静态的按钮,需要动态的话,可以自行弄 (个人感觉很麻烦且不太安全就没弄。。)

第 15 行:介绍一下当前研究方向是什么
第 16 行:简要描述一下目前研究方向的进展
19-21 行:描述一下你当前在 github 上正在做的项目
第 23 行:描述一下你当前正在学习的技术
第 26 行:你的电子邮箱,方便联系你
15-26 对自我的介绍可以跟据自己的需求进行更改,打造属于自己的风格。。

28 行到最后:一些图标,有关你所使用的平台以及工具和语言以及技能的图标,还是比较全,如还要添加,可以自行去网上找。。

参照模板,准备配置文件

{
  "Name": "某某某",
  "SelfDescription": "A passionate developer",
  "Motto": "You never lose, either you win or you learn!",
  "GithubName": "xxx",
  "StudyContent": "AI",
  "StudyContentDescription": "None",
  "RecentProjects": [
    {
      "Name": "hello",
      "URL": "https://github.com/xxx/hello",
      "Description": "Starting the repository study"
    },
    {
      "Name": "test",
      "URL": "https://github.com/xxx/test",
      "Description": "Test Repository"
    }
  ],
  "LearnTechAbility": [
    "Go language",
    "cloud native technology"
  ],
  "Email": "xxx@gmain.com"
}

//这里 RecentProjects 可以有多个,这里放了两个样例,可以自行更改
//正在学习的技术也可以有多个

定义对象

type Repo struct {
	Name        string `json:"Name"`
	URL         string `json:"URL"`
	Description string `json:"Description"`
}

type TemplateA struct {
	Name                    string   `json:"Name"`
	SelfDescription         string   `json:"SelfDescription"`
	Motto                   string   `json:"Motto"`
	GithubName              string   `json:"GithubName"`
	StudyContent            string   `json:"StudyContent"`
	StudyContentDescription string   `json:"StudyContentDescription"`
	RecentProjects          []Repo   `json:"RecentProjects"`
	LearnTechAbility        []string `json:"LearnTechAbility"`
	Email                   string   `json:"Email"`
}

读取配置文件

func ReadConfig(filePath string) (data TemplateA, err error) {
	var file *os.File
	file, err = os.Open(filePath)
	if err != nil {
		fmt.Println("Error opening file:", err)
		return
	}
	defer file.Close()

	decoder := json.NewDecoder(file)
	err = decoder.Decode(&data)
	if err != nil {
		fmt.Println("Error decoding JSON:", err)
		return
	}
	return
}

主函数

var (
	funcs = template.FuncMap{
		"join": strings.Join,
	}
)

func main() {
	data, err1 := ReadConfig("./config.json")
	if err1 == nil {
		fmt.Println("读取配置文件成功!")
		//fmt.Printf("%#v", data)
	}
	//注意 new(模板名),应该和第一个文件名相同。new 和 ParseFiles 都会产生模板,模板要相关联才能建立成功。
	tmpl := template.Must(template.New("README.md.tpl").Funcs(funcs).ParseFiles("./README.md.tpl"))
	file, err2 := os.OpenFile("./README.md", os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0664)
	if err2 != nil {
		fmt.Println("create README.md failed, err:", err2)
		return
	}
	if err3 := tmpl.Execute(file, data); err3 != nil {
		fmt.Println("parse template failed, err:", err3)
	}

}

完整 demo

package main

import (
	"encoding/json"
	"fmt"
	"html/template"
	"os"
	"strings"
)

type Repo struct {
	Name        string `json:"Name"`
	URL         string `json:"URL"`
	Description string `json:"Description"`
}

type TemplateA struct {
	Name                    string   `json:"Name"`
	SelfDescription         string   `json:"SelfDescription"`
	Motto                   string   `json:"Motto"`
	GithubName              string   `json:"GithubName"`
	StudyContent            string   `json:"StudyContent"`
	StudyContentDescription string   `json:"StudyContentDescription"`
	RecentProjects          []Repo   `json:"RecentProjects"`
	LearnTechAbility        []string `json:"LearnTechAbility"`
	Email                   string   `json:"Email"`
}

func ReadConfig(filePath string) (data TemplateA, err error) {
	var file *os.File
	file, err = os.Open(filePath)
	if err != nil {
		fmt.Println("Error opening file:", err)
		return
	}
	defer file.Close()

	decoder := json.NewDecoder(file)
	err = decoder.Decode(&data)
	if err != nil {
		fmt.Println("Error decoding JSON:", err)
		return
	}
	return
}

var (
	funcs = template.FuncMap{
		"join": strings.Join,
	}
)

func main() {
	data, err1 := ReadConfig("./config.json")
	if err1 == nil {
		fmt.Println("读取配置文件成功!")
		//fmt.Printf("%#v", data)
	}
	//注意 new(模板名),应该和第一个文件名相同。new 和 ParseFiles 都会产生模板,模板要相关联才能建立成功。
	tmpl := template.Must(template.New("README.md.tpl").Funcs(funcs).ParseFiles("./README.md.tpl"))
	file, err2 := os.OpenFile("./README.md", os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0664)
	if err2 != nil {
		fmt.Println("create README.md failed, err:", err2)
		return
	}
	if err3 := tmpl.Execute(file, data); err3 != nil {
		fmt.Println("parse template failed, err:", err3)
	}
}

效果

效果图 1

效果图 2

效果还行,ok,完工了。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值