如何搭建一个自己的博客(二)
如何搭建一个自己的博客(二)
系列文章
第一部分 Hexo配置
-
网页基本信息填写(_config.yml):
1
2
3
4
5
6
7
8
9#网页基本信息:
#网页名称
title: 'CzrTuringB的博客'
subtitle: 'CzrTuringB'
description: '林深时见鹿,海蓝时见鲸,梦醒时见你'
keywords:
author: CzrTuringB
language: zh-CN
timezone: Asia/Shanghai -
部署信息填写:
1
2
3
4
5
6#部署信息
#部署信息
deploy:
type: git
repo: blog@43.138.32.12:/home/blog/blog.git
branch: master -
文章链接永久化:
- 安装插件:
1
npm install hexo-abbrlink --save
-
配置:
1
2
3
4
5
6
7
8# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://www.czrturingb.top
permalink: :year/:month/:day/:title/
permalink_defaults:
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks
第二部分 Hexo主题美化
第一章 安装Butterfly主题
-
下载主题:
1
2
3
4
5cd #自己的博客路径
下载主题
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
下载插件
npm install hexo-renderer-pug hexo-renderer-stylus --save -
更改项目配置文件:
1
2#在blog/_config.yml文件中,配置主题
theme: butterfly -
测试:
1
2hexo clean
hexo s
第二章 主题配置
**注意:**在Blog目录下新建一个_config.butterfly.yml文件,把主题的配置文件内容复制过来,之后所有的更改都在这个文件中进行。
第一节 顶部导航栏配置
-
顶部导航栏配置:
1
2
3
4
5#顶部导航栏配置
nav:
logo: /img/001.jpg #导航栏图标
display_title: true #导航栏上是否显示标题
fixed: false #是否固定导航栏 -
顶部导航栏按钮的配置【每次添加页面都需要在这里配置导航栏按钮】:
1
2
3
4
5
6
7
8
9
10
11
12#目录相关
menu:
主页: / || fas fa-home
时间轴: /archives/ || fas fa-archive
标签: /tags/ || fas fa-tags
分类: /categories/ || fas fa-folder-open
说说: /chat/ || fal fa-share-alt
# 清单 List||fas fa-list:
# 音乐: /music/ || fas fa-music
# 视频: /movies/ || fas fa-video
友情链接: /link/ || fas fa-link
#关于: /about/ || fas fa-heart -
顶部导航栏目录配置格式:
1
2
3
4
5#只有一个选项的导航目录
{页面名称}: {路径} || fas fa-{图标名称}
#包含多个子选项的导航目录
{一级菜单名称} || fas fa-{图标名称}:
{二级页面名称}: {路径} || fas fa-{图标名称} -
顶部导航栏按钮的图标设置:
-
安装相关插件:
1
npm install hexo-butterfly-extjs
-
更改CDN配置:
1
2
3
4
5
6
7
8# CDN
# 非必要不要修改
CDN:
internal_provider: local
#主要就是把这里改为local
third_party_provider: local
version: true
custom_format: -
进入到https://fontawesome.com/v5/search选择图标复制图标的HTML代码内容到上述格式中即可。
-
-
添加导航栏搜索选项:
-
安装依赖:
1
npm install hexo-generator-search --save
-
配置搜索项:
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# search (搜索)
# see https://butterfly.js.org/posts/ceeb73f/#搜索系統
# --------------------------------------
# Algolia search
algolia_search:
enable: false
hits:
per_page: 6
# Local search
local_search:
enable: true
#在页面加载时提前加载数据
preload: false
#每篇文章展示多少搜索结果,如果全部展示则设置为-1
top_n_per_article: 1
# Unescape html strings to the readable one.
unescape: false
CDN:
# Docsearch
docsearch:
enable: false
appId:
apiKey:
indexName:
option:
-
第二节 图像设置
1 | # 图片设置 |
第三节 动画设置
-
加载动画:
1
2
3
4
5
6
7
8
9# Loading Animation (加載動畫)
preloader:
enable: false
# source
# 1. fullpage-loading
# 2. pace (progress bar)
source: 1
# pace theme (see https://codebyzach.github.io/pace/)
pace_css_url: -
主页循环打字效果:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23# 如果有英文逗號' , ',請使用轉義字元 ,
# 如果有英文雙引號' " ',請使用轉義字元 "
# 開頭不允許轉義字元,如需要,請把整個句子用雙引號包住
# 如果關閉打字效果,subtitle只會顯示sub的第一行文字
# the subtitle on homepage (主頁subtitle)
# 设置首页循环打字效果
subtitle:
enable: true
effect: true
# Customize typed.js (配置typed.js)
# https://github.com/mattboldt/typed.js/#customization
typed_option:
# source 調用第三方服務
# source: false 關閉調用
# source: 1 調用一言網的一句話(簡體) https://hitokoto.cn/
# source: 2 調用一句網(簡體) https://yijuzhan.com/
# source: 3 調用今日詩詞(簡體) https://www.jinrishici.com/
# subtitle 會先顯示 source , 再顯示 sub 的內容
source: false
# 如果關閉打字效果,subtitle 只會顯示 sub 的第一行文字
sub:
- 林深时见鹿,海蓝时见鲸,梦醒时见你。
- 择一事,终一生,唯有热爱可抵岁月漫长。 -
主页冒泡特效添加:
- 在Blog/themes/butterfly/source/js目录下新建bubble.js文件:
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$(function() {
// 气泡
function bubble() {
$('#page-header').circleMagic({
radius: 10,
density: .2,
color: 'rgba(255,255,255,.4)',
clearOffset: 0.99
});
}! function(p) {
p.fn.circleMagic = function(t) {
var o, a, n, r, e = !0,
i = [],
d = p.extend({ color: "rgba(255,0,0,.5)", radius: 10, density: .3, clearOffset: .2 }, t),
l = this[0];
function c() { e = !(document.body.scrollTop > a) }
function s() { o = l.clientWidth, a = l.clientHeight, l.height = a "px", n.width = o, n.height = a }
function h() {
if (e)
for (var t in r.clearRect(0, 0, o, a), i) i[t].draw();
requestAnimationFrame(h)
}
function f() {
var t = this;
function e() { t.pos.x = Math.random() * o, t.pos.y = a 100 * Math.random(), t.alpha = .1 Math.random() * d.clearOffset, t.scale = .1 .3 * Math.random(), t.speed = Math.random(), "random" === d.color ? t.color = "rgba(" Math.floor(255 * Math.random()) ", " Math.floor(0 * Math.random()) ", " Math.floor(0 * Math.random()) ", " Math.random().toPrecision(2) ")" : t.color = d.color }
t.pos = {}, e(), this.draw = function() { t.alpha <= 0 && e(), t.pos.y -= t.speed, t.alpha -= 5e-4, r.beginPath(), r.arc(t.pos.x, t.pos.y, t.scale * d.radius, 0, 2 * Math.PI, !1), r.fillStyle = t.color, r.fill(), r.closePath() }
}! function() {
o = l.offsetWidth, a = l.offsetHeight,
function() {
var t = document.createElement("canvas");
t.id = "canvas", t.style.top = 0, t.style.zIndex = 0, t.style.position = "absolute", l.appendChild(t), t.parentElement.style.overflow = "hidden"
}(), (n = document.getElementById("canvas")).width = o, n.height = a, r = n.getContext("2d");
for (var t = 0; t < o * d.density; t++) {
var e = new f;
i.push(e)
}
h()
}(), window.addEventListener("scroll", c, !1), window.addEventListener("resize", s, !1)
}
}(jQuery);
// 调用气泡方法
bubble();
})-
在inject的bottom中添加:
1
2- <script defer src="https://npm.elemecdn.com/jquery@latest/dist/jquery.min.js"></script>
- <script data-pjax defer src="https://npm.elemecdn.com/tzy-blog/lib/js/theme/chocolate.js"></script> -
主页流星雨特效添加:
-
打开_config.butterfly.yml文件,搜索inject,在head下添加:
1
- <link rel="stylesheet" href="/css/meteor.css">
-
打开_config.butterfly.yml文件,搜索inject,在bottom下添加:
1
2
3#背景宇宙星光canvas
- '<canvas id="universe"></canvas>'
- <script data-pjax defer src="/js/meteor.js"></script> -
在/source/js目录下添加meteor.js文件
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//夜晚模式下流星特效的添加
function dark()
{
window.requestAnimationFrame=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame;
var n,e,i,h,t=.05,s=document.getElementById("universe"),o=!0,a="180,184,240",r="226,225,142",d="226,225,224",c=[];
function f()
{
n=window.innerWidth,
e=window.innerHeight,
i=.216*n,
s.setAttribute("width",n),s.setAttribute("height",e)
}
function u()
{
h.clearRect(0,0,n,e);
for(var t=c.length,i=0;i<t;i++)
{
var s=c[i];
s.move(),
s.fadeIn(),
s.fadeOut(),
s.draw()
}
}
function y()
{
this.reset=function()
{
this.giant=m(3),
this.comet=!this.giant&&!o&&m(10),
this.x=l(0,n-10),
this.y=l(0,e),
this.r=l(1.1,2.6),
this.dx=l(t,6*t)+(this.comet+1-1)*t*l(50,120)+2*t,
this.dy=-l(t,6*t)-(this.comet+1-1)*t*l(50,120),
this.fadingOut=null,
this.fadingIn=!0,
this.opacity=0,
this.opacityTresh=l(.2,1-.4*(this.comet+1-1)),
this.do=l(5e-4,.002)+.001*(this.comet+1-1)},
this.fadeIn=function()
{
this.fadingIn&&(this.fadingIn=!(this.opacity>this.opacityTresh),this.opacity+=this.do)
},
this.fadeOut=function()
{
this.fadingOut&&(this.fadingOut=!(this.opacity<0),this.opacity-=this.do/2,(this.x>n||this.y<0)&&(this.fadingOut=!1,this.reset()))
},
this.draw=function()
{
if(h.beginPath(),this.giant)h.fillStyle="rgba("+a+","+this.opacity+")",h.arc(this.x,this.y,2,0,2*Math.PI,!1);
else if(this.comet)
{
h.fillStyle="rgba("+d+","+this.opacity+")",
h.arc(this.x,this.y,1.5,0,2*Math.PI,!1);
for(var t=0;t<30;t++)
h.fillStyle="rgba("+d+","+(this.opacity-this.opacity/20*t)+")",h.rect(this.x-this.dx/4*t,this.y-this.dy/4*t-2,2,2),h.fill()
}
else
h.fillStyle="rgba("+r+","+this.opacity+")",h.rect(this.x,this.y,this.r,this.r);
h.closePath(),h.fill()
},
this.move=function()
{
this.x+=this.dx,this.y+=this.dy,!1===this.fadingOut&&this.reset(),(this.x>n-n/4||this.y<0)&&(this.fadingOut=!0)},setTimeout(function(){o=!1},50)
}
function m(t)
{
return Math.floor(1e3*Math.random())+1<10*t
}
function l(t,i)
{
return Math.random()*(i-t)+t
}
f(),window.addEventListener("resize",f,!1),function()
{
h=s.getContext("2d");
for(var t=0;t<i;t++)c[t]=new y,c[t].reset();u()
}(),
function t()
{
document.getElementsByTagName('html')[0].getAttribute('data-theme')=='dark'&&u(),window.requestAnimationFrame(t)
}()
};
dark() -
在/source/css目录下添加meteor.styl文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19/* 夜间模式下背景宇宙星光 */
#universe {
display: block;
position: fixed;
margin: 0;
padding: 0;
border: 0;
outline: 0;
left: 0;
top: 0;
width: 100%;
height: 100%;
pointer-events: none;
z-index: 1;
}
/* 亮色模式下隐藏 */
[data-theme='light'] #universe {
display: none;
}
-
第四节 右侧侧边栏配置
-
社交按钮:
1
第三章 博客页面
第一节 博客标签页面的添加
-
标签页的添加:
1
hexo new page tags
-
编辑Blog/source/tags/index.md:
1
2
3
4
5
6
7---
title: 文章标签
date: 2023-05-29 21:42:56
type: "tags"
orderby: random
order: 1
---
第二节 博客分类页面的添加
-
分类页的添加:
1
hexo new page categories
-
编辑Blog/source/categories/index.md:
1
2
3
4
5---
title: 文章分类
date: 2023-05-29 21:57:07
type: "categories"
---
第三节 友情链接页的添加
-
添加友情链接页面:
1
hexo new page link
-
编辑Blog/source/link/index.md:
1
2
3
4
5---
title: 友情链接
date: 2023-05-29 22:03:35
type: "link"
--- -
在Blog/source/_data目录下创建一个link.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14- class_name: CzrTuringB
class_desc: 相关链接
link_list:
- name: 博客
link: http://czr.czrturingb.top/
avatar: /img/001.jpg
descr: 怀念过去就是在时间的长河里刻舟求剑
- class_name: 我的推荐
class_desc: 大佬们的HomePage
link_list:
- name: 稚晖的个人站
link: https://zhihui.lingjun.life/
avatar: https://tse4-mm.cn.bing.net/th/id/OIP-C.t8bhJWGAQxHSq4jOXct-eAHaFl?rs=1&pid=ImgDetMain
descr: 十年饮冰,难凉热血
第四节 说说页面的添加
-
首先前往这个页面创建一个账号并进行认证LeanCloud
-
创建一个应用,应用名称自行定义。
-
在结构化数据的_User类中新建一个列,其列名称为img,数据类型为String,并设置默认值为头像的url链接。
-
在结构化数据的_User类中新建一个行,输入用户名和密码,用于说说的发表。
-
配置_User类的所有权限都指向刚才创建的用户。
-
在结构化数据中创建一个shuoshuo类,然后将更新、删除、创建、添加域权限指向刚才创建的用户。
-
在结构化数据中创建一个atComment类,然后将所有的权限都指向所有用户。
-
打开设置----应用凭证----获取应用的AppID和AppKey。
-
我有一个已经备案的域名,所以我使用的时leanCloud大陆版,在域名解析中添加一个新的解析,其解析类型选择:CNAME。解析值为leanCloud中的设置----域名绑定----API访问域名绑定所给的值。
-
在安全中心,设置Web安全域名,填写自己博客的地址即可。
-
创建一个说说页面:
1
hexo new page chat
-
在创建的index.md文件中添加下面的内容:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18---
title: 说说
date: 2024-08-22 07:53:47
---
<!-- 引用 artitalk -->
<script type="text/javascript" src="https://unpkg.com/artitalk" data-pjax></script>
<!-- 存放说说的容器 -->
<div id="artitalk_main"></div>
<script>
new Artitalk({
appId: '', // Your LeanCloud appId
appKey: '', // Your LeanCloud appKey
serverURL: '',//刚才解析的子域名完整地址
avatarPla: '',//默认头像URL链接'
atComment: 0 //关闭评论
})
</script>
第四章 博客功能配置
第一节 搜索引擎收录
-
百度收录:
-
进入站长页面站点管理_站长工具_百度搜索资源平台创建网站,按提示填写信息即可。
-
验证方式选择文件验证,将下载的文件上传到服务器网站根目录下。
-
安装站点地图插件:
1
2npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save -
在Hexo配置文件中添加:
1
2
3
4
5#站点地图配置
baidusitemap:
path: baidusitemap.xml
sitemap:
path: sitemap.xml
-
-
Bing收录
-
登陆后选择手动提交页面,输入自己网站的域名,并下载验证文件,将其上传到服务器网站根目录下。
-
安装主动推送插件:
1
npm install --save hexo-submit-urls-to-search-engine
-
在Hexo配置文件中添加:
1
2
3
4
5
6
7
8
9
10
11
12
13#主动推送
hexo_submit_urls_to_search_engine:
submit_condition: count #链接被提交的条件,可选值:count | period 现仅支持count
count: 10 # 提交最新的10个链接
period: 900 # 提交修改时间在 900 秒内的链接
google: 0 # 是否向Google提交,可选值:1 | 0(0:否;1:是)
bing: 1 # 是否向Bing提交,可选值:1 | 0(0:否;1:是)
baidu: 1 # 是否向Baidu提交,可选值:1 | 0(0:否;1:是)
txt_path: submit_urls.txt # 文本文档名,需要推送的链接会保存在此文本文档里
bing_host: http://www.czrturingb.top # 在Bing站长平台中注册的域名
bing_token: # 您的Bing密钥,从Bing站长平台获取
baidu_host: http://www.czrturingb.top ## 在百度站长平台中注册的域名
baidu_token: ## 请注意这是您的秘钥, 所以请不要把它直接发布在公众仓库里! -
部署信息:
1
2
3
4
5
6
7
8
9#部署信息
deploy:
- type: git
#repo: git@192.168.100.12:/home/git/blog.git
repo: git@43.138.32.12:/home/git/blog.git
branch: master
- type: cjh_bing_url_submitter
- type: cjh_baidu_url_submitter -
在Bing中提交站点地图,依据提示填写站点地图ID即可。
第二节 全局音乐播放器
-
安装插件:
1
npm i hexo-tag-aplayer --save
-
在项目配置文件中添加下面内容:
1
2
3
4#音乐播放器
aplayer:
meting: true
asset_inject: false -
更改_config.butterfly.yml中的内容:
1
2
3
4# Inject the css and script (aplayer/meting)
aplayerInject:
enable: true
per_page: true -
添加全局吸底音乐播放器:
-
变量说明:
1
2@data-id:即自己网易云歌单的ID,通过网页打开网易云歌单,即可在连接处查看歌单ID
@data-server:相关音乐播放平台,这里我设置为网易云netease -
添加inject:
1
2
3#在inject bottom下面添加
#底部音乐播放器
- <div class="aplayer no-destroy" data-id="8424336101" data-server="netease" data-type="playlist" data-fixed="true" data-mini="true" data-listFolded="false" data-order="random" data-lrctype="1" data-preload="none" data-autoplay="true" muted></div> -
切换页面音乐不中断:
1
2
3
4#开启pjax
pjax:
enable: true
exclude:
-
第三部分 主题最终配置文件
1 | # -------------------------------------- |