-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17618.html
More file actions
239 lines (224 loc) · 32.9 KB
/
17618.html
File metadata and controls
239 lines (224 loc) · 32.9 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>利用GitHub自动化部署Blog | Bluecode</title><meta name="author" content="Bluecode"><meta name="copyright" content="Bluecode"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="both">
<meta property="og:type" content="article">
<meta property="og:title" content="利用GitHub自动化部署Blog">
<meta property="og:url" content="http://example.com/17618.html">
<meta property="og:site_name" content="Bluecode">
<meta property="og:description" content="both">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="http://example.com/img/cover.png">
<meta property="article:published_time" content="2022-11-12T16:50:32.000Z">
<meta property="article:modified_time" content="2022-11-16T10:38:21.000Z">
<meta property="article:author" content="Bluecode">
<meta property="article:tag" content="hexo">
<meta property="article:tag" content="github">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/img/cover.png"><link rel="shortcut icon" href="/img/favicon.svg"><link rel="canonical" href="http://example.com/17618"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
root: '/',
algolia: undefined,
localSearch: undefined,
translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
noticeOutdate: {"limitDay":500,"position":"top","messagePrev":"It has been","messageNext":"days since the last update, the content of the article may be outdated."},
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":300},
copy: {
success: 'Copy successfully',
error: 'Copy error',
noSupport: 'The browser does not support'
},
relativeDate: {
homepage: false,
post: false
},
runtime: 'days',
date_suffix: {
just: 'Just',
min: 'minutes ago',
hour: 'hours ago',
day: 'days ago',
month: 'months ago'
},
copyright: {"limitCount":50,"languages":{"author":"Author: Bluecode","link":"Link: ","source":"Source: Bluecode","info":"Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source."}},
lightbox: 'fancybox',
Snackbar: undefined,
source: {
justifiedGallery: {
js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
}
},
isPhotoFigcaption: false,
islazyload: false,
isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: '利用GitHub自动化部署Blog',
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
postUpdate: '2022-11-16 18:38:21'
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
}
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
}
}
const t = saveToLocal.get('theme')
if (t === 'dark') activateDarkMode()
else if (t === 'light') activateLightMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">Articles</div><div class="length-num">2</div></a><a href="/tags/"><div class="headline">Tags</div><div class="length-num">2</div></a><a href="/categories/"><div class="headline">Categories</div><div class="length-num">0</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/img/top.png')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Bluecode</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">利用GitHub自动化部署Blog<a class="post-edit-link" href="https://github.com/bluecodecc/blog/edit/main/source/_posts_posts/博客安装记录.md" title="Edited on" target="_blank"><i class="fas fa-pencil-alt"></i></a></h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2022-11-12T16:50:32.000Z" title="Created 2022-11-13 00:50:32">2022-11-13</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2022-11-16T10:38:21.000Z" title="Updated 2022-11-16 18:38:21">2022-11-16</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">Word count:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">Reading time:</span><span>4min</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="利用GitHub自动化部署Blog"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span><span class="post-meta-separator">|</span><span class="post-meta-commentcount"><i class="far fa-comments fa-fw post-meta-icon"></i><span class="post-meta-label">Comments:</span><a href="/17618.html#post-comment" itemprop="discussionUrl"><span class="valine-comment-count" data-xid="/17618.html" itemprop="commentCount"><i class="fa-solid fa-spinner fa-spin"></i></span></a></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>最近由于工作需要所以研究了一下GitLab的CI/CD的功能,事后想起荒废了很久的博客,所以萌生了使用GitHub的Actions重新部署一下的想法,这里记录一下安装的过程。</p>
<h1 id="环境说明"><a href="#环境说明" class="headerlink" title="环境说明"></a>环境说明</h1><ol>
<li>博客框架: Hexo</li>
<li>博客主题: Butterfly</li>
<li>托管环境: GitHub Pages</li>
<li>源程序仓库: 可以设置成私有仓库,用来保存原始文件</li>
<li>页面文件仓库: 用来存放编译后的页面文件</li>
<li>更新流程: 编写文章PUSH到源程序仓库,源程序仓库Actions触发预先定义的任务,编译后PUSH到页面文件仓库,页面文件仓库Actions触发默认的github-pages任务部署网页服务。</li>
</ol>
<h1 id="安装hexo并初始化项目"><a href="#安装hexo并初始化项目" class="headerlink" title="安装hexo并初始化项目"></a>安装hexo并初始化项目</h1><p>Hexo依赖于Node.js环境,所以需要先安装Node.js,对于Mac来说,可以去Node.js官网下载安装包也可以通过brew命令安装。还需要安装GIT环境,Mac OS默认已安装。</p>
<ol>
<li>全局安装hexo-cli <code>npm install -g hexo-cli</code></li>
<li>初始化一个名为blog的hexo工程 <code>hexo init blog</code></li>
<li>安装依赖 <code>cd blog && npm install</code></li>
<li>启动hexo服务 <code>hexo server</code></li>
</ol>
<h1 id="安装主题"><a href="#安装主题" class="headerlink" title="安装主题"></a>安装主题</h1><p>推荐通过git clone主题仓库到hexo的themes文件夹下,这样比较容易管理<br>执行命令<code>git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly</code>将主题butterfly安装到hexo的themes文件夹下。</p>
<h1 id="建立源程序仓库"><a href="#建立源程序仓库" class="headerlink" title="建立源程序仓库"></a>建立源程序仓库</h1><p>在GitHub建立源程序仓库,名称随意,可以设置成私有仓库,我这里取名为blog。</p>
<h1 id="建立页面文件仓库"><a href="#建立页面文件仓库" class="headerlink" title="建立页面文件仓库"></a>建立页面文件仓库</h1><p>在GitHub建立页面文件仓库,如果想通过githubname.github.io访问,需要将仓库命名为githubname.github.io,如果没有这个需求,可以任意取名。</p>
<h1 id="设置秘钥"><a href="#设置秘钥" class="headerlink" title="设置秘钥"></a>设置秘钥</h1><p>需要在GitHub设置三个秘钥文件</p>
<h2 id="SSH-keys"><a href="#SSH-keys" class="headerlink" title="SSH keys"></a>SSH keys</h2><p>添加Authentication Keys到GitHub的SSH keys,成功设置后可以免密执行git命令。</p>
<ol>
<li><code>ssh-keygen -t rsa -C "your.email@example.com" -b 4096</code>,按提示生成秘钥,也可以一路无脑回车</li>
<li><code>pbcopy < ~/.ssh/id_rsa.pub</code>,拷贝公钥到<a target="_blank" rel="noopener" href="https://github.com/settings/ssh/new">SSH keys</a></li>
<li><code>ssh -T git@github.com</code>,测试是否可以通过认证。</li>
</ol>
<h2 id="源程序仓库的Actions-secrets"><a href="#源程序仓库的Actions-secrets" class="headerlink" title="源程序仓库的Actions secrets"></a>源程序仓库的Actions secrets</h2><p>添加私钥blog-deploy-key到源程序仓库的Actions secrets</p>
<ol>
<li><code>ssh-keygen -f blog-deploy-key</code>,生成公私钥对</li>
<li><code>pbcopy < ~/.ssh/blog-deploy-key</code>,拷贝私钥到<a target="_blank" rel="noopener" href="https://github.com/settings/ssh/new">Actions secrets</a>,命名为BLOG_DEPLOY_PRI</li>
</ol>
<h2 id="页面文件仓库的Deploy-keys"><a href="#页面文件仓库的Deploy-keys" class="headerlink" title="页面文件仓库的Deploy keys"></a>页面文件仓库的Deploy keys</h2><p>添加公钥blog-deploy-key.pub到页面文件仓库的Deploy keys,<mark class="hl-label orange">切记勾选Allow write access</mark> ,设置成功后源程序仓库的Actions任务可以PUSH代码到页面文件仓库</p>
<ol>
<li><code>pbcopy < ~/.ssh/blog-deploy-key.pub</code>,拷贝公钥粘贴到<a target="_blank" rel="noopener" href="https://github.com/bluecodecc/bluecodecc.github.io/settings/keys/new">Deploy keys</a>,命名为BLOG_DEPLOY_PUB</li>
</ol>
<h1 id="编写blog仓库的Actions文件"><a href="#编写blog仓库的Actions文件" class="headerlink" title="编写blog仓库的Actions文件"></a>编写blog仓库的Actions文件</h1><p>新建文件<code>.github/workflows/deploy.yml</code>,编写Actions任务。</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">CI</span></span><br><span class="line"></span><br><span class="line"><span class="attr">on:</span></span><br><span class="line"> <span class="attr">push:</span></span><br><span class="line"> <span class="attr">branches:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="string">main</span></span><br><span class="line"></span><br><span class="line"><span class="attr">env:</span></span><br><span class="line"> <span class="attr">GIT_USER:</span> <span class="string">xxx</span></span><br><span class="line"> <span class="attr">GIT_EMAIL:</span> <span class="string">xxx@xx.com</span></span><br><span class="line"> <span class="attr">THEME_REPO:</span> <span class="string">jerryc127/hexo-theme-butterfly</span></span><br><span class="line"> <span class="attr">THEME_BRANCH:</span> <span class="string">master</span></span><br><span class="line"> <span class="attr">THEME:</span> <span class="string">butterfly</span></span><br><span class="line"></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"> <span class="attr">build:</span></span><br><span class="line"> <span class="attr">name:</span> <span class="string">Build</span> <span class="string">on</span> <span class="string">node</span> <span class="string">${{</span> <span class="string">matrix.node_version</span> <span class="string">}}</span> <span class="string">and</span> <span class="string">${{</span> <span class="string">matrix.os</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">runs-on:</span> <span class="string">ubuntu-latest</span></span><br><span class="line"> <span class="attr">strategy:</span></span><br><span class="line"> <span class="attr">matrix:</span></span><br><span class="line"> <span class="attr">os:</span> [<span class="string">ubuntu-latest</span>]</span><br><span class="line"> <span class="attr">node_version:</span> [<span class="number">18.</span><span class="string">x</span>]</span><br><span class="line"></span><br><span class="line"> <span class="attr">steps:</span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Checkout</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v2</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Checkout</span> <span class="string">theme</span> <span class="string">repo</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/checkout@v2</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">repository:</span> <span class="string">${{</span> <span class="string">env.THEME_REPO</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">ref:</span> <span class="string">${{</span> <span class="string">env.THEME_BRANCH</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">path:</span> <span class="string">themes/${{</span> <span class="string">env.THEME</span> <span class="string">}}</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Use</span> <span class="string">Node.js</span> <span class="string">${{</span> <span class="string">matrix.node_version</span> <span class="string">}}</span></span><br><span class="line"> <span class="attr">uses:</span> <span class="string">actions/setup-node@v1</span></span><br><span class="line"> <span class="attr">with:</span></span><br><span class="line"> <span class="attr">node-version:</span> <span class="string">${{</span> <span class="string">matrix.node_version</span> <span class="string">}}</span></span><br><span class="line"></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Configuration</span> <span class="string">environment</span></span><br><span class="line"> <span class="attr">env:</span></span><br><span class="line"> <span class="attr">BLOG_DEPLOY_PRI:</span> <span class="string">${{secrets.BLOG_DEPLOY_PRI}}</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> sudo timedatectl set-timezone "Asia/Shanghai"</span></span><br><span class="line"><span class="string"> mkdir -p ~/.ssh/</span></span><br><span class="line"><span class="string"> echo "$BLOG_DEPLOY_PRI" > ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string"> chmod 600 ~/.ssh/id_rsa</span></span><br><span class="line"><span class="string"> ssh-keyscan github.com >> ~/.ssh/known_hosts</span></span><br><span class="line"><span class="string"> git config --global user.name $GIT_USER</span></span><br><span class="line"><span class="string"> git config --global user.email $GIT_EMAIL</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Install</span> <span class="string">dependencies</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"><span class="string"> npm install</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"> <span class="bullet">-</span> <span class="attr">name:</span> <span class="string">Deploy</span> <span class="string">hexo</span></span><br><span class="line"> <span class="attr">run:</span> <span class="string">|</span></span><br><span class="line"> <span class="string">npm</span> <span class="string">run</span> <span class="string">deploy</span></span><br></pre></td></tr></table></figure>
<h1 id="自定义主题配置"><a href="#自定义主题配置" class="headerlink" title="自定义主题配置"></a>自定义主题配置</h1><p>可以遵照官方建议操作</p>
<div class="note success simple"><p>在 hexo 的根目錄創建一個文件 _config.butterfly.yml,並把主題目錄的 _config.yml 內容複製到 _config.butterfly.yml 去。( 注意: 複製的是主題的 _config.yml ,而不是 hexo 的 _config.yml)</p>
</div>
<p>如果某些主题不支持读取根目录下的配置文件,可以考虑使用根目录下的配置文件覆盖主题目录下的配置文件,只需要在<code>Configuration environment</code>任务最后添加<code>cp _config.${{ env.THEME }}.yml themes/${{ env.THEME }}/_config.yml </code></p>
<div class="note warning simple"><p>当然主题可能出现破坏性升级,可以考虑不追踪最新的主题,自己手动更新主题文件,去掉上面的<code>Checkout theme repo</code>任务,并且将themes文件夹添加到git版本追踪中</p>
</div>
<h1 id="设置hexo部署路径"><a href="#设置hexo部署路径" class="headerlink" title="设置hexo部署路径"></a>设置hexo部署路径</h1><p>在hexo的配置文件_config.yml中,补全设置deploy子参数</p>
<figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">deploy:</span></span><br><span class="line"> <span class="attr">type:</span> <span class="string">git</span></span><br><span class="line"> <span class="attr">repo:</span> <span class="string">git@github.com:githubname/githubname.github.io.git</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">main</span></span><br></pre></td></tr></table></figure>
<div class="note warning simple"><p>以上涉及到的所有branch参数都需要一一对应,源程序仓库和页面文件仓库我都是使用的main分支,主题使用的master分支,按需修改即可,页面文件仓库的<a target="_blank" rel="noopener" href="https://github.com/githubname/githubname.github.io/settings/pages">Pages</a>也需要设置成对应的分支</p>
</div>
<h1 id="参考链接"><a href="#参考链接" class="headerlink" title="参考链接"></a>参考链接</h1><p><a target="_blank" rel="noopener" href="https://makefile.so/2021/11/28/use-github-actions-to-deploy-hexo-blog/">使用GitHub Actions部署Hexo博客</a><br><a target="_blank" rel="noopener" href="https://sanonz.github.io/2020/deploy-a-hexo-blog-from-github-actions/">利用 Github Actions 自动部署 Hexo 博客</a></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="http://example.com">Bluecode</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="http://example.com/17618.html">http://example.com/17618.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/hexo/">hexo</a><a class="post-meta__tags" href="/tags/github/">github</a></div><div class="post_share"><div class="social-share" data-image="/img/cover.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-full"><a href="/5586.html"><img class="prev-cover" src="/5586/cover.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">私人密码库Bitwarden部署</div></div></a></div></nav><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> Comment</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E8%AF%B4%E6%98%8E"><span class="toc-text">环境说明</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85hexo%E5%B9%B6%E5%88%9D%E5%A7%8B%E5%8C%96%E9%A1%B9%E7%9B%AE"><span class="toc-text">安装hexo并初始化项目</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AE%89%E8%A3%85%E4%B8%BB%E9%A2%98"><span class="toc-text">安装主题</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BB%BA%E7%AB%8B%E6%BA%90%E7%A8%8B%E5%BA%8F%E4%BB%93%E5%BA%93"><span class="toc-text">建立源程序仓库</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BB%BA%E7%AB%8B%E9%A1%B5%E9%9D%A2%E6%96%87%E4%BB%B6%E4%BB%93%E5%BA%93"><span class="toc-text">建立页面文件仓库</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E7%A7%98%E9%92%A5"><span class="toc-text">设置秘钥</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#SSH-keys"><span class="toc-text">SSH keys</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%BA%90%E7%A8%8B%E5%BA%8F%E4%BB%93%E5%BA%93%E7%9A%84Actions-secrets"><span class="toc-text">源程序仓库的Actions secrets</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E6%96%87%E4%BB%B6%E4%BB%93%E5%BA%93%E7%9A%84Deploy-keys"><span class="toc-text">页面文件仓库的Deploy keys</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BC%96%E5%86%99blog%E4%BB%93%E5%BA%93%E7%9A%84Actions%E6%96%87%E4%BB%B6"><span class="toc-text">编写blog仓库的Actions文件</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%BB%E9%A2%98%E9%85%8D%E7%BD%AE"><span class="toc-text">自定义主题配置</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AEhexo%E9%83%A8%E7%BD%B2%E8%B7%AF%E5%BE%84"><span class="toc-text">设置hexo部署路径</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%82%E8%80%83%E9%93%BE%E6%8E%A5"><span class="toc-text">参考链接</span></a></li></ol></div></div></div></div></main><footer id="footer" style="background-image: url('/img/top.png')"><div id="footer-wrap"><div class="copyright">©2014 - 2022 By Bluecode</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="Switch Between Traditional Chinese And Simplified Chinese">繁</button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="chat_btn" type="button" title="Chat"><i class="fas fa-sms"></i></button><a id="to_comment" href="#post-comment" title="Scroll To Comments"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="Back To Top"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script>function panguFn () {
if (typeof pangu === 'object') pangu.autoSpacingPage()
else {
getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
.then(() => {
pangu.autoSpacingPage()
})
}
}
function panguInit () {
if (false){
GLOBAL_CONFIG_SITE.isPost && panguFn()
} else {
panguFn()
}
}
document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadValine () {
function initValine () {
const valine = new Valine(Object.assign({
el: '#vcomment',
appId: 'XlSlTmQWdXge5wfZIlnZHyAg-gzGzoHsz',
appKey: 'se2ul5b86qcSXcZYItD7rKc4',
avatar: 'robohash',
serverURLs: '',
emojiMaps: "",
path: window.location.pathname,
visitor: false
}, null))
}
if (typeof Valine === 'function') initValine()
else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}
if ('Valine' === 'Valine' || !false) {
if (false) btf.loadComment(document.getElementById('vcomment'),loadValine)
else setTimeout(loadValine, 0)
} else {
function loadOtherComment () {
loadValine()
}
}</script></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>