记一次使用 Hexo + GitHub Pages 搭建 blogs


前几天掘金在首页推荐了一个Hexo+GitHub Pages自己搭建博客的文章,于是开始自己摸索去搭建的试一下。按照官网的步骤初始化了一个Hexo项目,并根据官方的GitHub Pages部署文档尝试着部署项目。


本地项目搭建完成,github pages搭建完成,ssh配置完成后:

1. 修改_config.yml配置文件

在项目根目录下的_config.yml配置文件最后改为

deploy:
  type: git
  repository: 远程仓库地址
  branch: master

2. 安装hexo-deployer-git插件

安装部署插件hexo-deployer-git,必须安装不然会报错,详情可以看官方这个issues

npm install hexo-deployer-git --save

3. 部署

执行部署上传命令即可访问线上博客项目,g 是 generate 缩写,d 是 deploy 缩写。

# 生成静态文件
hexo g
# 启动本地服务
hexo server
# 部署网站
hexo d
# 文件生成后立即部署网站
hexo g -d
# 清除缓存,建议每次部署前先清除缓存
hexo clean

4. 新建文章

# 新建一篇文章
hexo new [layout] 
# 例如
hexo new "post title with whitespace"
</code></pre>
<p>如果没有设置 layout 的话,默认使用_config.yml 中的 default_layout 参数代替。如果标题包含空格的话,需要使用引号括起来。<strong>title必须设置</strong>。</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>-p, --path</td>
<td>自定义新文章的路径</td>
</tr>
<tr>
<td>-r, --replace</td>
<td>如果存在同名文章,将其替换</td>
</tr>
<tr>
<td>-s, --slug</td>
<td>文章的Slug,作为新文章的文件名和发布后的URL</td>
</tr>
</tbody>
</table>
<pre><code class="language-powershell"># 创建一个 source/about/me.md 文件,且标题为 About me
hexo new page --path about/me "About me"
</code></pre>
<h4 id="5-分类">5. 分类</h4>
<p><strong>分类具有顺序性和层次性,例如Foo, Bar 不等于 Bar, Foo</strong></p>
<ol>
<li>子分类</li>
</ol>
<pre><code class="language-yaml">categories:
    - Diary
    - Life
</code></pre>
<p>分类 Life 会成为 Diary 的子分类,而不是并列分类</p>
<ol start="2">
<li>并列分类</li>
</ol>
<pre><code class="language-yaml">categories:
    - [Diary]
    - [Life]
</code></pre>
<p>Diary 和 Life 为并列分类</p>
<ol start="3">
<li>并列+子分类</li>
</ol>
<pre><code class="language-yaml">categories:
    - [Diary, PlayStation]
    - [Diary, Games]
    - [Life]
</code></pre>
<p>PlayStation 和 Games 分别都是父分类 Diary 的子分类,同时 Life 是一个没有子分类的分类</p>
<h4 id="6-标签">6. 标签</h4>
<p><strong>标签没有顺序和层次</strong></p>
<pre><code class="language-yaml">tags:
    - PS3
    - Games
</code></pre>
<p>PS3 和 Games 是两个独立的标签,没有层级和顺序</p>
<h4 id="结语">结语</h4>
<p>官方部署文档如下:</p>
<p><img src="https://img.yipin100.com/p.php?img=https://gitee.com/huqian025/my-images/raw/master/%E5%85%B6%E4%BB%96/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BD%BF%E7%94%A8Hexo%E6%90%AD%E5%BB%BAblog/hexo%E5%AE%98%E6%96%B9%E9%83%A8%E7%BD%B2%E6%96%87%E6%A1%A3.png" alt="官方部署文档" loading="lazy"></p>
<p><strong>再使用 Travis CI 时,官方提示需要添加一个 plan 才能使用,但添加 plan 需要 stripe 信用卡信息,直接劝退。</strong></p>
<p><img src="https://img.yipin100.com/p.php?img=https://gitee.com/huqian025/my-images/raw/master/%E5%85%B6%E4%BB%96/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BD%BF%E7%94%A8Hexo%E6%90%AD%E5%BB%BAblog/Travis_CI%E6%B7%BB%E5%8A%A0plan.png" alt="Travis CI添加plan" loading="lazy"><br>
<img src="https://img.yipin100.com/p.php?img=https://gitee.com/huqian025/my-images/raw/master/%E5%85%B6%E4%BB%96/%E8%AE%B0%E4%B8%80%E6%AC%A1%E4%BD%BF%E7%94%A8Hexo%E6%90%AD%E5%BB%BAblog/Travis_CI%E6%B7%BB%E5%8A%A0plan-%E4%B8%AD%E6%96%87.png" alt="Travis CI添加plan-中文" loading="lazy"></p>
<p>最后参照了一下大佬的文章,本来都想记录分享一下搭建过程的,但是大佬写的真的太细了。。</p>
						  
					  </div>
						<!--conend-->
							<div class="p-2"></div>

						<div class="arcinfo my-3 fs-7 text-center">
							
							
			<a href='/t/etagid700-0.html' class='tagbtn' target='_blank'>其他</a>							
						



						</div>
						
						<div class="p-2"></div>

						

						
					</div>
					<div class="p-2"></div>
					<!--xg-->
					<div class="lbox p-4 shadow-sm rounded-3">
						<div class="boxtitle"><h2 class="fs-4">相关</h2></div>
						
<hr>				
						
			<div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-562767.html">007.SMB其他应用</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-559774.html">python的WeakKeyDictionary类和weakref模块的其他函数</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-558520.html">jQuery 当前展开其他收缩 三级下拉菜单(转载)</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-556453.html">Dora.Interception,为.NET Core度身打造的AOP框架 [5]:轻松地实现与其他AOP框架的整合</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-555575.html">九、测试经销商能看到其他经销商的工单数据排查--excel如何单列去重</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-545235.html">img图片跨域问题(场景:阿里oss,腾讯oss,其他第三方文件服务器)</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-544559.html">【其他】修改服务器时间,oracle数据库时间</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-533577.html">如何申请 Apple 的 Dun & Bradstreet Code (邓白氏编码 2021)(最新的,网上其他的流程都</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-529621.html">表单组件里面放其他组件的方法</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-520295.html">表单组件里面放其他组件的方法</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-506192.html">7_less中引入其他文件 / 模块</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div><div class="row g-0 py-2 border-bottom align-items-center">
																
								<div class="col-7 col-lg-11 border-lg-end">
										<h3 class="fs-6 mb-0 mb-lg-2"><a href="/a/1-494732.html">Windows 2003 只能打开百度,不能打开其他网页的一个解决方法</a></h3>
									
									<div class="ltag fs-8 d-none d-lg-block">
								 

        </div>
								</div>
							
							</div>            
            
            <!---->
                                    
           <!---->
  			
						

					</div>
					<!--xgend-->
				</div>

				<div class="col-lg-3 col-12 p-0 ps-lg-2">
					<!--box-->									
					<!--boxend-->
					<!--<div class="p-2"></div>-->

					<!--box-->
									<div class="lbox p-4 shadow-sm rounded-3">
					
									   <div class="boxtitle pb-2"><h2 class="fs-4"><a href="#">标签</a></h2></div>
										<div class="clearfix"></div>
										<ul class="m-0 p-0 fs-7 r-tag">
										</ul>
									

										
										<div class="clearfix"></div>
									</div>
					<!--box end-->

					
				</div>

			</div>
		
		
		
		</div>	

</main>
						<div class="p-2"></div>
<footer>
<div class="container-fluid p-0 bg-black">
	<div class="container p-0  fs-8">
	<p class="text-center m-0 py-2 text-white-50">一品网 <a class="text-white-50" href="https://beian.miit.gov.cn/" target="_blank">冀ICP备14022925号-6</a></p>
	</div>	
</div>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?6e3dd49b5f14d985cc4c6bdb9248f52b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</footer>
		
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.min.js"></script>

</body>
</html>