本博客仅作云笔记使用
一、安装nginx
yum install -y nginx
用此方法安装的nginx配置文字在/etc/nginx/nginx.conf
,我们将其root内容改为/home/blog
一些常用的命令如下
// 启动nginx
systemctl start nginx
// 重启nginx
systemctl restart nginx
// 停止nginx
systemctl stop nginx
// 开机自启
systemctl enable nginx
二、 安装git
yum install -y git
三、安装nodejs
安装
安装nodejs的方法很多,yum
这种方法是我尝试失败的一种,想安装高版本nodejs,但是安装的版本始终是v6.17
:
curl -sL https://rpm.nodesource.com/setup_10.x | sudo -E bash -
sudo yum install nodejs
因此,我选择安装包安装:
- 下载node安装包
cd /usr/local/src wget https://nodejs.org/dist/v10.11.0/node-v10.11.0-linux-x64.tar.xz
- 解压安装包
tar -zxvf node-v10.11.0-linux-x64.tar.xz // 解压 mv node-v10.11.0-linux-x64 node // 重命名
- 添加进
node
和npm
进环境变量ln -s /usr/local/src/node/bin/node /usr/bin/node ln -s /usr/local/src/node/bin/npm /usr/bin/node
- 查看安装是否成功
node -v npm -v
更换源
更换npm源
npm config set registry https://registry.npm.taobao.org
安装cnpm
npm install -g cnpm --registry=https://registry.npm.taobao.org
四、安装hexo
cnpm install -g hexo-cli
新建一个项目
cd /home/
hexo init blog ;新建项目
cd /blog
npm install ;安装依赖
npm install hexo-deployer-git --save ;插件
npm install hexo-server ;插件
hexo server ;启动hexo
不出意外,我们就可以在http://yourip:4000上看到首页了
新建一篇文章
hexo new "new article"
我们可以在/home/blog/source/_posts/
下看到new-article.md
这个文件,就可以写博客了。
更换next主题
1.下载主题
cd /home/blog/themes
git clone https://github.com/iissnan/hexo-theme-next.git next
2.将blog目录下_config.yml
里theme的名称由landscape修改为next
3.清除hexo缓存使用命令:hexo clear
更换语言为中文
查看themes/next/languages/目录下是否有zh-Hans.yml 文件,里面有很多yml文件,对应着不同的语言
修改blog目录下的_config.yml
,修改language为zh_Hans
设置阅读更多
方法一
在文章中使用< !–more–> 手动进行截断
方法二
对于next主题,修改主题目录下的_config.yml
,修改
auto_excerpt:
enable: false
length: 150
将false改为true即可
让hexo博客在后台跑起来
安装pm2
npm install -g pm2
写一个执行脚本
//run.js
const { exec } = require('child_process')
exec('hexo server',(error, stdout, stderr) => {
if(error){
console.log(`exec error: ${error}`)
return
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
})
在博客根目录下运行
pm2 start run.js
pm2 status ;查看状态
有可能pm2报错,类似node/npm一样需要添加软连接
Cannot GET /archives/%20/
经过一通搜索,知道%20 是空格的意思,把themes/netxt配置文件里 ||之前所有的空格删掉即可。
分类、归档、标签
一、主题配置打开
打开主题配置文件找到Menu Settings ,把 categories 和 tags 取消注释。
二、添加分类模块
- 新建一个分类页面。
hexo new page categories
- 你会发现你的
source
文件夹下有了tags\index.md
,打开index.md
文件将title
设置为title: 标签
。 - 把文章归入分类只需在文章的顶部标题下方添加categories字段,即可自动创建分类名并加入对应的分类中。
三、添加标签模块
- 新建一个标签页面 。
hexo new page tags
- 你会发现你的
source
文件夹下有了tags\index.md
,打开index.md
文件将title
设置为title: 标签
。 - 把文章添加标签只需在文章的顶部标题下方添加
tags
字段,即可自动创建标签名并归入对应的标签中 。
四、修改 index.md 文件
打开 categories 文件夹下的 index.md ,在最下面一行加一行文字就行,注意中间有空格。
type: categories
同理,tags 也是如此。
五、在线写博客
安装hexo admin
npm install --save hexo-admin
启动服务器
hexo server
六、添加mathajx
npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-kramed --save
修改
打开node_modules/hexo-renderer-kramed/lib/renderer.js
,将
// Change inline math rule
function formatText(text) {
// Fit kramed's rule: $$ + \1 + $$
return text.replace(/`\$(.*?)\$`/g, '$$$$$1$$$$');
}
改为:
// Change inline math rule
function formatText(text) {
return text;
}
卸载
npm uninstall hexo-math --save
安装
npm install hexo-renderer-mathjax --save
修改
打开node_modules/hexo-renderer-mathjax/mathjax.html
,将 <script>
改为:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>
打开node_modules/kramed/lib/rules/inline.js
:
首先将
escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
改为:
escape: /^\\([`*\[\]()# +\-.!_>])/,
然后将
em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
改为:
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
开启公式支持功能
在home/_config.yml
中添加如下内容
mathjax:
enable: true
七、插入图片
绝对路径本地引用
当Hexo项目中只用到少量图片时,可以将图片统一放在source/images文件夹中,通过markdown语法访问它们。
![](/images/image.jpg)
图片既可以在首页内容中访问到,也可以在文章正文中访问到。
相对路径本地引用
图片除了可以放在统一的images文件夹中,还可以放在文章自己的目录中。文章的目录可以通过站点配置文件_config.yml来生成。
post_asset_folder: true
将_config.yml文件中的配置项post_asset_folder设为true后,执行命令$ hexo new post_name,在source/_posts中会生成文章post_name.md和同名文件夹post_name。将图片资源放在post_name中,文章就可以使用相对路径引用图片资源了。
![](image.jpg)