配置hexo

配置hexo

软件版本
nodejs16.20.0
nginx1.24.0
节点IP系统功能CPU内存硬盘
node110.80.10.1centos7.9hexo4核心8GB20GB

node1

hexo目录:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# tree -L 1 /data/hexo/
/data/hexo/
├── _config.landscape.yml
├── _config.yml
├── db.json
├── node_modules
├── package.json
├── package-lock.json
├── public
├── run.js
├── scaffolds
├── source
└── themes

5 directories, 6 files

下载安装主题:

1
2
# cd /data/hexo/themes/
# git clone -b v8.18.2 https://github.com/next-theme/hexo-theme-next.git

选择主题:

1
2
3
# vim /data/hexo/_config.yml
# 100行,修改主题,默认为landscape主题
theme: hexo-theme-next

配置网站基本信息:

1
2
3
4
5
6
7
8
9
# vim /data/hexo/_config.yml
# 6行~12行,修改网站名称
title: Mrch
subtitle: ''
description: ''
keywords:
author: 墨染初华
language: zh-CN
timezone: 'Asia/Shanghai'

配置主题样式:

1
2
3
4
5
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 40行,注释配置
#scheme: Muse
# 43行,开启配置
scheme: Gemini
1
# pm2 restart /data/hexo/run.js

浏览器访问:http://10.80.10.1/

设置菜单,默认有首页,其它需要创建目录:

1
2
3
4
5
6
7
8
9
10
11
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 98~106行,开启菜单注释
menu:
home: / || fa fa-home
#about: /about/ || fa fa-user
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat
1
2
3
# hexo new page "tags"
# hexo new page "categories"
# hexo new page "archives"

设置图片放大:

1
2
3
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 585行,点击图片可以放大
ancybox: true

指定头像:

1
2
3
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 144行,指定头像
url: /avatar.jpg
  • 头像位置:/data/hexo/source/。

修改标签和分类页面显示为中文:

1
2
3
4
5
6
# vim /data/hexo/source/tags/index.md
---
title: 标签
date: 2023-11-24 14:21:00
type: "tags"
---
1
2
3
4
5
6
# vim /data/hexo/source/categories/index.md
---
title: 分类
date: 2023-11-24 14:21:04
type: "categories"
---

添加文章版权:

1
2
3
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 70行,添加文章版权
post: true

新建博客及图片显示:

1
2
# hexo new "xxx"
# hexo g
  • 博客位置:/data/hexo/source/_posts/xxx.md。

  • 图片文件夹对应存放位置:/data/hexo/source/。

  • 图片需要使用![]()格式插入,不能使用<img src>格式插入,否则无法识别。

添加建站时间:

1
2
3
4
5
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 206行,设置时间
footer:
# Specify the year when the site was setup. If not defined, current year will be used.
since: 2023-11

自定义背景:

1
2
3
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 32行,取消注释
style: source/_data/styles.styl
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
# mkdir /data/hexo/source/_data
# vim /data/hexo/source/_data/styles.styl
//背景图片
body {
background:url(/images/background.png);
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
background-position: center;
}
//文章内容颜色
body {
color: #000000;
}
//文章标题颜色
.posts-expand .post-title-link {
color: #000000;
}
//文章日期颜色
.posts-expand .post-meta-container {
color: #00008B;
}
//底部字体颜色
.footer-inner {
color: #000000;
}
//页面透明度
.main {
opacity: 0.9;
}
  • background:url:背景图片的地址,放置于Next主题文件下的。

    • 位置:/data/hexo/themes/hexo-theme-next/source/images/
  • fixed:表示是否随鼠标滚动,选择fixed固定。

  • size:表示填充。

  • posi:表示位置。

关闭文章目录:

1
2
3
4
5
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 185行,关闭文章目录
enable: false
# 187行,关闭文章目录编号
number: false

添加网站运行时间:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# vim /data/hexo/themes/hexo-theme-next/layout/_partials/footer.njk
# 尾行,添加计算时间代码
<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date();
function createtime() {
var grt= new Date("11/23/2023 22:49:00");//此处修改你的建站时间或者网站上线时间
now.setTime(now.getTime()+250);
days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days);
hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours);
if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum);
mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;}
seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;}
document.getElementById("timeDate").innerHTML = "本站已安全运行 "+dnum+" 天 ";
document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()",250);
</script>

文章置顶:

1
2
3
4
5
6
7
8
9
# npm install hexo-generator-index-pin-top --save
# pm2 restart /data/hexo/run.js
# vi test.md
---
title: 图片测试
date: 2023-11-24 11:23:34
tags:
top: 1
---

图片懒加载,加载中显示loading:

1
2
3
4
5
6
7
# npm install hexo-lazyload-image --save
# vim /data/hexo/_config.yml
# 尾行,添加配置
lazyload:
enable: true
onlypost: false
loadingTmg:
1
# pm2 restart /data/hexo/run.js

关闭更新时间:

1
2
3
4
# vim /data/hexo/themes/hexo-theme-next/_config.yml
# 253~254行,修改配置
enable: false
another_day: false