魔改
修改网站整体配色
- vi themes/hexo-theme-matery/source/css/matery.css 修改bg-color 的background-image属性来设置颜色,修改opacity设置透明度
1 | .bg-color { |
取消banner蒙层
- vi themes/hexo-theme-matery/source/css/matery.css 将bg-cover:after 注释
1 | /*.bg-cover:after { |
设置网站背景图
- vi themes/hexo-theme-matery/source/css/matery.css
1 | body { |
1.5 适配目录
- 好像没有生效
1 | vi themes/hexo-theme-matery/source/css/post.css |
1 | .toc-widget { |
修改banner图
方式一:banner轮播
- 在hexo-theme-matery._config中配置featureImages
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22featureImages:
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover17.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover18.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover19.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover20.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover21.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover22.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover23.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover24.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover25.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover26.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover27.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover28.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover29.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover30.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover31.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover32.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover33.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover34.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover35.jpg
- https://zhangtq-blog.oss-cn-hangzhou.aliyuncs.com/theme/cover36.jpg- vi themes/hexo-theme-matery/layout/_partial/bg-cover-content.ejs
1
2
3
4
5
6
7<script>
// 每天切换 banner 图. Switch banner image every day.
//var bannerUrl = "<%- theme.jsDelivr.url %><%- url_for('/medias/banner/') %>" + new Date().getDay() + '.jpg';
//$('.bg-cover').css('background-image', 'url(' + bannerUrl + ')');
// 随机选择配置文件中featureImages配置的图片
$('.bg-cover').css('background-image', 'url(<%- theme.featureImages[Math.floor(Math.random() * theme.featureImages.length + 1)-1] %>)');
</script>方式二:设置为外部链接图片
vi themes/hexo-theme-matery/layout/_partial/bg-cover-content.ejs
1 | <script> |
优化背景壁纸和目录栏
- vi themes/hexo-theme-matery/source/css/matery.css
1 | body { |
修改页脚访问量等信息
vi themes/hexo-theme-matery/layout/_partial/footer.ejs
增加建站时间
1 | <script language=javascript> |
新增社交链接
vi themes/hexo-theme-matery/layout/_partial/social-link.ejs
添加git链接
1 | <% if (theme.socialLink.git) { %> |
- 其中图标类似fa-gitlab可以在[Font Awesome](Font Awesome)中查找
- 常用图标如下
1 | Facebook: fa-facebook |
- 然后在主题配置文件中配置自己的git地址
1 | socialLink: |
修改打赏二维码
- 在主题文件的
source/medias/reward
文件中,可以替换成你的的微信和支付宝的打赏二维码图片
部署到多个仓库
- 在根目录下设置deploy
1 | deploy: |
文章字数统计
1 | npm i --save hexo-wordcount |
- 修改根目录下的_config.yaml
1 | wordCount: |
添加rss订阅
- 安装插件
1 | npm install hexo-generator-feed --save |
- 修改根目录下的_config.yaml
1 | feed: |
添加动态标签
- vi themes/hexo-theme-matery/layout/layout.ejs
1 | <script type="text/javascript"> |
新建文章模板
- 修改/scaffolds/post.md中的内容
1 | --- |
添加404页面
- hexo new page 404
- vi ./source/404/404.md 添加如下内容
1 | --- |
- vi themes/hexo-theme-matery/layout/404.ejs 添加如下内容
1 | <style type="text/css"> |
- 在nginx的config做如下配置
- 本网站做了私有话部署,是部署在阿里云服务器,所以需要需改静态资源服务器的404指向
- 如果是托管在gitee 或者github上显示404页面,需要在/source/目录下新建404.md文件,文件内容和404.index内容相同,这是因为gitee或者github托管时,静态资源服务器配置的404页面是在根目录下
1 | server { |
去除banner上的logo 和左上角title
1 | vi themes/hexo-theme-matery/layout/_partial/header.ejs |
1 | <header class="navbar-fixed"> |
修改建站时间为动态变化
1 | vi themes/hexo-theme-matery/layout/_partial/footer.ejs |
1 | <!-- 运行天数提醒. --> |
卜算子
1 | vi themes/hexo-theme-matery/layout/_partial/footer.ejs |
- 在打开文件的中替换原来的内容为以下内容
1 |
|
- 在这个文件最后加上如下代码
1 | <script> $(document).ready(function () { |
替换icon和baner上的图标
1 | 替换 themes\hexo-theme-matery\source\medias中的logo.png |
添加博客动态标签
1 | vi themes/hexo-theme-matery/layout/layout.ejs |
- 在对应的位置下添加如下代码
1 | <script type="text/javascript"> |
hexo-neat代码优化加速
- 站点根目录下_config.yaml添加如下内容
1 | #hexo-neat 优化提速插件(去掉HTML、css、js的blank字符) |
- 安装插件
1 | npm install hexo-neat |
- 运行hexo
1 | hexo clean && hexo g&& hexo s |
修复详情页下面的上一篇/下一篇摘要失效
1 | vi theme/hexo-theme-matery/layout/_partial/prev-next.js |
- 找到上一页对应的位置,大概在41行
1 |
|
- 找到下一页对应的位置,大概在103行
1 | <div class="summary block-with-text"> |
文章详情页头部添加作者信息
1 | vi themes/hexo-theme-matery/layout/_partial/post-detail.ejs |
- 在36行附近添加如下内容
1 |
|
标签
- 最终效果如下
- 在themes/hexo-theme-matery/scripts/ 新建block.js文件
1 | vi themes/hexo-theme-matery/scripts/block.js |
- 添加如下内容
1 | hexo.extend.tag.register('r', function(args, content){ |
- 在head.ejs文件中添加样式
1 | vi themes/hexo-theme-matery/layout/_partial/head.ejs |
1 | <style type="text/css"> |
- 引用方法
1 | {%r%} |
图片懒加载
- 在博客根目录执行
1 | npm install hexo-lazyload-image --save |
- 根目录配置文件中开启懒加载
1 | lazyload: |
到这里就配置完了,执行
hexo cl&&hexo g&&hexo s
就有效果了,以后博客上的图片就都是懒加载了,以上步骤理论上任何主题都可以用一般情况下懒加载会和gallery插件会发生冲突,结果可能就是点开图片,左翻右翻都是loading image。matery主题的解决方案是:
修改
/themes/matery/source/js
中的matery.js
文件在108行加入以下内容
1 | $(document).find('img[data-original]').each(function(){ |
- 修改后代码
1 |
|
做完这步之后,还有点小Bug,首页的logo点击会直接打开logo图,而不是跳到首页。
伪解决方案:打开
/themes/matery/layout/_partial/header.ejs
文件,在
img
和span
的两个头加个div
:
1 | <div class="brand-logo"> |
自定义加载logo
hexo-lazyload-image
插件提供了自定义loading图片的选项- 方法就是在
loadingImg
后配置图片的路径就好了
1 | lazyload: |
解决懒加载后图片不能立即显示问题
此优化后可以做到懒加载无感知
在根目录的配置文件_config.yaml 添加如下内容
1 | lazyload: |
- 配置优化达到性能最佳
1 | # 图片懒加载 |
我的梦想card添加一言
- vi themes\hexo-theme-matery\source\css\matery.css
- 在最后添加如下样式内容
1 | /* 增加每日一言模块 */ |
- vi themes\hexo-theme-matery\layout_widget\dream.ejs
- 修改为如下内容
1 | <script> |
- 在主题配置文件中开启dream显示
1 | dream: |
自定义我的相册
- 修改主题配置文件
vi themes\hexo-theme-matery\_config.yml
1 | # 二级菜单写法如下 |
- 新建相册页
1 | hexo new page gallery |
- 在
source\galleries\
下新建或者修改index.md为以下内容
1 | --- |
在
themes\hexo-theme-matery\source\css\
新建或者修改gallery.cssvi themes\hexo-theme-matery\source\css\gallery.css
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
```css
.gallery-wrapper{
padding-top: 30px;
}
.gallery-wrapper .gallery-box{
padding: 5px !important;
}
.gallery-wrapper .gallery-item {
display: block;
overflow: hidden;
background-color: #fff;
padding: 5px;
padding-bottom: 0;
position: relative;
-moz-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
-webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
}
.gallery-cover-box{
width: 100%;
padding-top: 60%;
text-align: center;
overflow: hidden;
position: relative;
background: center center no-repeat;
-webkit-background-size: cover;
background-size: cover;
}
.gallery-cover-box .gallery-cover-img {
display: inline-block;
width: 100%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
}
.gallery-item .gallery-name{
font-size: 14px;
line-height: 24px;
text-align: center;
color: #666;
margin: 0;
}
.waterfall {
column-count: 3;
column-gap: 1em;
}
.photo-wrapper{
padding-top: 20px;
}
.photo-item {
display: block;
padding: 10px;
padding-bottom: 0;
margin-bottom: 14px;
font-size: 0;
-moz-page-break-inside: avoid;
-webkit-column-break-inside: avoid;
break-inside: avoid;
background: white;
-moz-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
-webkit-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.22);
}
.photo-item img {
width: 100%;
}
.photo-item .photo-name{
font-size: 14px;
line-height: 30px;
text-align: center;
margin-top: 10px;
margin-bottom: 10px;
border-top: 1px solid #dddddd;
}
/*适配移动端布局*/
@media only screen and (max-width: 601px) {
.waterfall {
column-count: 2;
column-gap: 1em;
}
}在
themes\hexo-theme-matery\layout\
目录下新建 或者修改galleries.ejs
文件,替换为以下内容该版本为添加了一言api的版本,如果不需要删除对应的代码就行
1 | <link rel="stylesheet" href="/css/gallery.css"> |
- 在
themes\hexo-theme-matery\layout\
下新建或者修改gallery.ejs
文件
1 | <link rel="stylesheet" href="/css/gallery.css"> |
- 需要几个文件,我把文件地址放在下面,用浏览器打开链接,就会显示出代码,然后复制粘贴到文加中去就行。开头的是文件路径,如果没有的话,就新建一个就 OK 了。
hemes\hexo-theme-matery\source\libs\fancybox\jquery.fancybox.css
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/libs/fancybox/jquery.fancybox.css
themes\hexo-theme-matery\source\libs\fancybox\fancybox.js
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/libs/fancybox/fancybox.js
themes\hexo-theme-matery\source\libs\justifiedGallery\justifiedGallery.min.css
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/libs/justifiedGallery/justifiedGallery.min.css
themes\hexo-theme-matery\source\libs\justifiedGallery\justifiedGallery.min.js
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/libs/justifiedGallery/justifiedGallery.min.js
hemes\hexo-theme-matery\source\js\crypto-js.js
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/js/crypto-js.js
hemes\hexo-theme-matery\source\js\gallery-encrypt.js
https://cdn.jsdelivr.net/gh/Yafine/cdn@3.3.4/source/js/gallery-encrypt.js
链接有可能失效,这里提供压缩包下载
相册加密
- 依赖于上面的的
crypto-js.js
和gallery-encrypt.js
放到相同的目录下就可以
1 | npm install --save hexo-blog-encrypt |
vi themes\hexo-theme-matery\_config.yml
修改enable为True
1 | verifyPassword: |
- 新建如下
themes\hexo-theme-matery\scripts\helpers\
目录,如果目录不存在先新建目录 - 在encrypt.j文件中加入如下内容
1 | /* global hexo */ |
- 在
themes\hexo-theme-matery\source\css\
的my.css中添加如下内容
1 | .hbe-input-container .btn-decrypt{ |
- 至此,添加密码功能就实现了
- 在新建的 index.md 文章内添加 password属性,后面写上你的密码即可,然后执行命令,查看本地效果即可**注意:密码需要经过sha256加密, 这里提供加密网站在线加密网站
一级菜单或二级菜单页面改成友链形式
themes\hexo-theme-matery\_config.yml
这里以二级菜单书籍为例
1 | Friends: |
vi themes\hexo-theme-matery\languages\zh-CN.yml
添加如下内容- 这一步相当于做了中英文对照,使页面下的大标题和菜单中文一致,如果不做的话,在页面上会直接显示books,而不是书籍
1 | books: 书籍 |
hexo new page books
vi source\books\index.md
替换为如下内容
1 | --- |
- 拷贝friends.ej文件作为books.ejs
1 | cp themes\hexo-theme-matery\layout\friends.ejs themes\hexo-theme-matery\layout\books.ejs |
- 修改books.ejs
1 | vi themes\hexo-theme-matery\layout\books.ejs |
- 打开 musics.ejs 文本内搜索 friends ,把它们改成 books,注意定义的 class 和 id 内的不要改,只改变量,更改目标为下图高亮部分
- 复制friends.json 文件为books.json
1 | cp source\_data\friends.json source\_data\books.json |
- hexo g && hexo s
- 至此就会将页面改为友链样式,后续只需要在books.json中修改具体内容就可以了
自定义菜单下友链样式修改
- 修改缩略图边框为方形(大多图片是方形的,这样后续添加内容会更美观)
- 以下步骤其实就是找到你菜单详情页面的js文件,做出修改
1 | vi themes\hexo-theme-matery\layout\books.ejs |
- 这个属性是控制弯曲度的
1 | .frind-ship img { |
- 修改高度,还是上面这个文件,由于我后来对卡片内容做了调整,后来值有所变化,按需修改width和height值就可以了
1 | .frind-ship .title img { |
- 增加显示卡片内容
- 先看效果图
- 还是上面的文件,大约210行附近,这块的内容可以自定以,注意取值和json 文件的字段相同就行
1 | <div class="title"> |
- 修改books.json文件
1 | [ |
- 一级菜单和二级菜单的改法相同,只是在_config.yaml里配置的menu 不一致罢了
1 | Friends: |
1 | # 一级菜单写法如下 |
- 注意头像链接,可以下载下来放到自己的图床上比如oss ,防止不能访问,目前豆瓣的头像会有限制
hexo+ typora+ oss 最佳实践
方式一
- 修改博客根目录中
_config.yml
文件的配置项post_asset_folder
为true
: - 完成此设置后,当你通过
hexo new 文件名
新建博客后,会产生一个和文件同名的文件夹。 - 下载插件 npm install https://github.com/CodeFalling/hexo-asset-image –save
- 当文章需要添加图片时,将需要添加的图片放入同名的文件夹中,同时通过相对路径索引到该图片
- 在typora中设置: 文件–>偏好设置–>图像
- 以后直接粘贴图片就可以自动保存到 hexo 配置的 post_asset_folder 文件夹里,自动渲染了
- 直接渲染时会发现显示不了,此时需要在typora中将图片路径前的文件目录去除
- 可以通过typor中批量替换的方式,但是替换后在typora中又不能显示了,网页显示正常
方式二通过阿里云oss图床
阿里云的操作就不再这里详谈了,有一点注意的使创建bucket后需要将buckeet改为公开
配置typora: 文件–>偏好设置
在进行第五步打开配置文件添加如下内容
1 | { |
- 至此,每次我们复制图片到typora中后,都会自动上传至oss,同时在md文件中自动引用url
最开是博主是按照大多数人一样,通过在根目录下设置post_asset_folder: true,这样每次hexo new 文件名后会产生一个同名的文件夹