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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
| # 网页访问该仓库并使用该仓库模板,基于该仓库模块创建自己的仓库,格式为:username/username.github.io或organizationName/organizationName.github.io
# username是你注册github时的名字,organizationName是你在github账户下另外创建组织时的名字
# 基于模板仓库
https://github.com/CaiJimmy/hugo-theme-stack-starter
# 创建自己的仓库
https://github.com/ynhugo/ynhugo.github.io
# repo's github pages设置为从github actions部署
# 克隆基于模板创建的仓库
git clone git@github.com:ynhugo/ynhugo.github.io.git
hugo mod get -u github.com/CaiJimmy/hugo-theme-stack/v4
hugo mod tidy
# 修改配置文件
# 修改baseurl
sed -i 's|\(^baseurl = "\).*\("\)|\1https://ynhugo.github.io/\2|g' config/_default/config.toml
# 修改语言
sed -i 's|\(^locale[[:space:]]*= "\).*\("\)|\1zh-cn\2|g' config/_default/config.toml
# 修改title
sed -i 's|\(^title[[:space:]]*= "\).*\("\)|\1ynhugo\2|g' config/_default/config.toml
# 修改默认博文语言
sed -i 's|\(^defaultContentLanguage[[:space:]]*= "\).*\("\)|\1zh-cn\2|g' config/_default/config.toml
# 修改每页显示博文数量
sed -i 's|\(^[[:space:]]*pagerSize[[:space:]]*= \).*|\120|g' config/_default/config.toml
# 添加中文归档
cat > content/page/archives/index.zh-cn.md << 'EOF'
---
title: "文章归档"
date: 2019-05-28
layout: "archives"
slug: "archives"
menu:
main:
weight: -70
params:
icon: archives
---
EOF
# 添加中文主页
cat > content/_index.zh-cn.md << 'EOF'
---
menu:
main:
name: 主页
weight: 1
params:
icon: home
---
EOF
# 添加中文搜索
cat > content/page/search/index.zh-cn.md << 'EOF'
---
title: "搜索"
slug: "search"
layout: "search"
outputs:
- html
- json
menu:
main:
weight: -60
params:
icon: search
---
EOF
# 添加中文友情链接
cat > content/page/links/index.zh-cn.md << 'EOF'
---
title: 友情链接
links:
- title: GitHub
description: GitHub is the world's largest software development platform.
website: https://github.com
image: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
menu:
main:
weight: 4
params:
icon: link
comments: false
---
To use this feature, add `links` section to frontmatter.
This page's frontmatter:
```yaml
links:
- title: GitHub
description: GitHub is the world's largest software development platform.
website: https://github.com
image: https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png
- title: TypeScript
description: TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
website: https://www.typescriptlang.org
image: ts-logo-128.jpg
```
`image` field accepts both local and external images.
EOF
# 添加配置短代码的脚本
cat - > shortcode.sh << 'END'
mkdir -p layouts/shortcodes/
# 添加网易云短代码
cat - > layouts/shortcodes/netease.html <<'EOF'
<iframe
frameborder="no"
border="0"
marginwidth="0"
marginheight="0"
width=330 height=86
src="//music.163.com/outchain/player?type=2&id={{.Get 0}}&auto=0&height=66">
</iframe>
EOF
# 添加文字属性
cat - > layouts/shortcodes/align.html <<'EOF'
<p style="text-align:{{ index .Params 0 }}">{{ index .Params 1 | markdownify }}</p>
EOF
# 插入github仓库
cat - > layouts/shortcodes/github.html <<'EOF'
<div class="github">
<div class="logo">
{{ replace $.Site.Data.SVG.repository "icon" "icon github-icon" | safeHTML }}
<a class="name" href={{ .Get "link" }} target="_blank">{{ .Get "name" }}</a>
</div>
<div class="description">{{ .Get "description" }}</div>
<div class="language">
<span class="language-color" style="background-color: {{ .Get "color" }}"></span>
<span class="language-name">{{ .Get "language" }}</span>
</div>
</div>
EOF
END
chmod +x shortcode.sh
# 追加配置短代码的命令
sed -i 's|\(^[[:space:]]*\)\(hugo \\\)|\1echo "添加短代码"\n\1./shortcode.sh\n\1\2|g' .github/workflows/deploy.yml
# 执行常规push操作,我封装在脚本中执行了
~/git_push_pull.sh push
|