-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
287 lines (163 loc) · 14.9 KB
/
index.html
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>xxx的博客</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta property="og:type" content="website">
<meta property="og:title" content="xxx的博客">
<meta property="og:url" content="http://example.com/index.html">
<meta property="og:site_name" content="xxx的博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
<link rel="alternate" href="/atom.xml" title="xxx的博客" type="application/atom+xml">
<link rel="shortcut icon" href="/favicon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/index.min.css">
<link rel="stylesheet" href="/css/style.css">
<link rel="stylesheet" href="/fancybox/jquery.fancybox.min.css">
<meta name="generator" content="Hexo 6.3.0"></head>
<body>
<div id="container">
<div id="wrap">
<header id="header">
<div id="banner"></div>
<div id="header-outer" class="outer">
<div id="header-title" class="inner">
<h1 id="logo-wrap">
<a href="/" id="logo">xxx的博客</a>
</h1>
</div>
<div id="header-inner" class="inner">
<nav id="main-nav">
<a id="main-nav-toggle" class="nav-icon"><span class="fa fa-bars"></span></a>
<a class="main-nav-link" href="/">Home</a>
<a class="main-nav-link" href="/archives">Archives</a>
</nav>
<nav id="sub-nav">
<a class="nav-icon" href="/atom.xml" title="RSS 订阅"><span class="fa fa-rss"></span></a>
<a class="nav-icon nav-search-btn" title="搜索"><span class="fa fa-search"></span></a>
</nav>
<div id="search-form-wrap">
<form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="搜索"><button type="submit" class="search-form-submit"></button><input type="hidden" name="sitesearch" value="http://example.com"></form>
</div>
</div>
</div>
</header>
<div class="outer">
<section id="main">
<article id="post-deploy_with_github" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<div class="article-meta">
<a href="/2024/03/04/deploy_with_github/" class="article-date">
<time class="dt-published" datetime="2024-03-04T09:07:44.485Z" itemprop="datePublished">2024-03-04</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="p-name article-title" href="/2024/03/04/deploy_with_github/">如何利用 GitHub 在自己的服务器上部署 Hexo 博客</a>
</h1>
</header>
<div class="e-content article-entry" itemprop="articleBody">
<p>This is a simple guide to deploy the blog on my server with GitHub.</p>
<h2 id="第一步:安装-Hexo"><a href="#第一步:安装-Hexo" class="headerlink" title="第一步:安装 Hexo"></a>第一步:安装 Hexo</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install -g hexo-cli</span><br></pre></td></tr></table></figure>
<p>然后到准备写博客的目录下执行:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo init</span><br></pre></td></tr></table></figure>
<h2 id="第二步:安装-hexo-deployer-git"><a href="#第二步:安装-hexo-deployer-git" class="headerlink" title="第二步:安装 hexo-deployer-git"></a>第二步:安装 hexo-deployer-git</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install hexo-deployer-git --save</span><br></pre></td></tr></table></figure>
<h2 id="第三步:Github-上创建一个新的仓库"><a href="#第三步:Github-上创建一个新的仓库" class="headerlink" title="第三步:Github 上创建一个新的仓库"></a>第三步:Github 上创建一个新的仓库</h2><p>在 github 上创建一个新的仓库,名字任意,这里取名 <code>anything</code> 。</p>
<h2 id="第四步:配置-Github-SSH-keys"><a href="#第四步:配置-Github-SSH-keys" class="headerlink" title="第四步:配置 Github SSH keys"></a>第四步:配置 Github SSH keys</h2><p>在服务器上配置好 Github 的 SSH keys,这样 Hexo 才能够通过 SSH 协议推送博客到 Github 。</p>
<p>这里推荐看<a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/62022220">这篇文章</a>进行部署,这里不细说</p>
<h2 id="第五步:配置-Hexo"><a href="#第五步:配置-Hexo" class="headerlink" title="第五步:配置 Hexo"></a>第五步:配置 Hexo</h2><p>在博客目录下找到 <code>_config.yml</code> 文件,修改 <code>deploy</code> 部分:</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></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">[email protected]:my_account/anything.git</span></span><br><span class="line"> <span class="attr">branch:</span> <span class="string">main</span></span><br><span class="line"> <span class="attr">message:</span> <span class="string">flag{flag_is_here}</span></span><br></pre></td></tr></table></figure>
<p>这样,部署时 Hexo 就会将博客推送到 <code>my_account/anything</code> 仓库的 <code>main</code> 分支,提交信息为 <code>message</code> 中的内容。</p>
<h2 id="第六步:上传博客至-Github"><a href="#第六步:上传博客至-Github" class="headerlink" title="第六步:上传博客至 Github"></a>第六步:上传博客至 Github</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">$ hexo clean</span><br><span class="line">$ hexo g</span><br><span class="line">$ hexo d</span><br></pre></td></tr></table></figure>
<p>这样,博客就会被推送到 Github 上了。</p>
<h2 id="第七步:在服务器上拉取博客"><a href="#第七步:在服务器上拉取博客" class="headerlink" title="第七步:在服务器上拉取博客"></a>第七步:在服务器上拉取博客</h2><p>在服务器上拉取博客:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ <span class="built_in">cd</span> /path/to/your/blog/on/the/server</span><br><span class="line">$ git <span class="built_in">clone</span> https://www.github.com/my_account/anything.git</span><br></pre></td></tr></table></figure>
<h2 id="第八步:配置-Nginx"><a href="#第八步:配置-Nginx" class="headerlink" title="第八步:配置 Nginx"></a>第八步:配置 Nginx</h2><p>在 Nginx 的 <code>conf</code> 文件夹下找到 <code>nginx.conf</code> 文件,添加如下配置:</p>
<figure class="highlight nginx"><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></pre></td><td class="code"><pre><span class="line"><span class="section">server</span> {</span><br><span class="line"> <span class="attribute">listen</span> <span class="number">80</span>;</span><br><span class="line"> <span class="attribute">server_name</span> your_domain.xyz;</span><br><span class="line"> <span class="section">location</span> / {</span><br><span class="line"> <span class="attribute">root</span> /path/to/your/blog/<span class="literal">on</span>/the/server/anything;</span><br><span class="line"> <span class="attribute">index</span> index.html;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>之后,重启 Nginx 服务:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ nginx -s reload</span><br></pre></td></tr></table></figure>
<p>这样,当有人访问 <code>your_domain.xyz</code> 时,就会访问到你的博客了。</p>
<h2 id="第九步:配置-crontab"><a href="#第九步:配置-crontab" class="headerlink" title="第九步:配置 crontab"></a>第九步:配置 crontab</h2><p>在服务器上配置 crontab,定时拉取博客:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ crontab -e</span><br></pre></td></tr></table></figure>
<p>然后添加如下内容:</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">*/1 * * * * <span class="built_in">cd</span> /path/to/your/blog/on/the/server/anything && git pull</span><br></pre></td></tr></table></figure>
<p>这样,每分钟服务器就会自动拉取一次博客。</p>
<p>这样,你就可以在自己的服务器上部署 Hexo 博客了。</p>
</div>
<footer class="article-footer">
<a data-url="http://example.com/2024/03/04/deploy_with_github/" data-id="cltcrj5ja0000nsuy74wo6f45" data-title="如何利用 GitHub 在自己的服务器上部署 Hexo 博客" class="article-share-link"><span class="fa fa-share">分享</span></a>
</footer>
</div>
</article>
<article id="post-hello-world" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
<div class="article-meta">
<a href="/2024/03/04/hello-world/" class="article-date">
<time class="dt-published" datetime="2024-03-04T09:05:49.157Z" itemprop="datePublished">2024-03-04</time>
</a>
</div>
<div class="article-inner">
<header class="article-header">
<h1 itemprop="name">
<a class="p-name article-title" href="/2024/03/04/hello-world/">Hello World</a>
</h1>
</header>
<div class="e-content article-entry" itemprop="articleBody">
<p>Welcome to <a target="_blank" rel="noopener" href="https://hexo.io/">Hexo</a>! This is your very first post. Check <a target="_blank" rel="noopener" href="https://hexo.io/docs/">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a target="_blank" rel="noopener" href="https://hexo.io/docs/troubleshooting.html">troubleshooting</a> or you can ask me on <a target="_blank" rel="noopener" href="https://github.com/hexojs/hexo/issues">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/writing.html">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/server.html">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/generating.html">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure>
<p>More info: <a target="_blank" rel="noopener" href="https://hexo.io/docs/one-command-deployment.html">Deployment</a></p>
</div>
<footer class="article-footer">
<a data-url="http://example.com/2024/03/04/hello-world/" data-id="cltcrj5kj0001nsuy6tkgay1s" data-title="Hello World" class="article-share-link"><span class="fa fa-share">分享</span></a>
</footer>
</div>
</article>
</section>
<aside id="sidebar">
<div class="widget-wrap">
<h3 class="widget-title">归档</h3>
<div class="widget">
<ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2024/03/">三月 2024</a></li></ul>
</div>
</div>
<div class="widget-wrap">
<h3 class="widget-title">最新文章</h3>
<div class="widget">
<ul>
<li>
<a href="/2024/03/04/deploy_with_github/">如何利用 GitHub 在自己的服务器上部署 Hexo 博客</a>
</li>
<li>
<a href="/2024/03/04/hello-world/">Hello World</a>
</li>
</ul>
</div>
</div>
</aside>
</div>
<footer id="footer">
<div class="outer">
<div id="footer-info" class="inner">
© 2024 John Doe<br>
Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
</div>
</div>
</footer>
</div>
<nav id="mobile-nav">
<a href="/" class="mobile-nav-link">Home</a>
<a href="/archives" class="mobile-nav-link">Archives</a>
</nav>
<script src="/js/jquery-3.6.4.min.js"></script>
<script src="/fancybox/jquery.fancybox.min.js"></script>
<script src="/js/script.js"></script>
</div>
</body>
</html>