使用markdown写东西比较多,所以决定弃掉之前自己用java写的一个blog网站,改用hexo。
hexo官网:https://hexo.io/zh-cn/docs/
# 安装 npm install -g hexo-cli # 建立软连接 ln -s /usr/local/node/lib/node_modules/hexo-cli/bin/hexo /usr/local/bin/hexo # 建立hexo目录 hexo init <folder> cd <folder> npm installhexo常用命令
# 生成静态文件 hexo g # 启动服务器,默认端口4000 # -p 重设端口 hexo s # 清除缓存文件 (db.json) 和已生成的静态文件 (public) hexo cleanhexo-admin官网:https://jaredforsyth.com/hexo-admin/
# 在安装hexo目录的位置安装 npm install --save hexo-admin经过以上步骤执行hexo s后,访问4000端口就可以看到hexo网站了,这里我们首先配置一下hexo-admin, 访问http://localhost:4000/admin/,进入setting菜单,点击 Setup authentification here 可以设置admin的账号密码,然后将对应的信息复制到_config.yml文件中,如下
# hexo-admin authentification admin: username: username password_hash: $2a$10$L.XAIqIWgTc5S1zpvV3MEu7/rH34p4Is/nq824smv8EZ3lIPCp1su secret: my super secret phrase deployCommand: './hexo-generate.sh'接下来我们配置一个脚本,可以让我们在发布一篇新的文章之后利用hexo-admin手动生成静态文件
# 创建脚本 touch hexo-generate.sh; vim hexo-generate.sh; # 脚本内容 #!/usr/bin/env sh hexo g # 执行权限 chmod +x hexo-generate.sh现在,我们就可以使用hexo-admin在线进行文章的发布了。
pm2可以用来管理node应用,接下来安装pm2来对hexo进行管理。
安装pm2 npm install -g pm2 建立软连接 ln -s /usr/local/node/lib/node_modules/pm2/bin/pm2 /usr/local/bin/pm2在刚刚的hexo目录下创建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 stop all # 停止 id为 0的指定应用程序 pm2 stop 0 # 重启所有应用 pm2 restart all可参考 https://github.com/guoxwOvO/hexo-theme-rabb
下面是我更换主题时遇到的一些问题:(centos7)
1、报没有权限
gyp ERR! stack Error: EACCES: permission denied, mkdir ‘/usr/local/hexo/node_modules/node-sass/.node-gyp’
sudo npm install hexo-renderer-scss --save`2、报 /usr/bin/env: node: No such file or directory 则需将node以及npm的可执行文件链接到/usr/bin下
ln -s /usr/local/node/bin/node /usr/bin/node ln -s /usr/local/node/bin/npm /usr/bin/npm