快速搭建GitHub博客教程 - Hexo及Next主题安装

本文为在Mac上利用Hexo搭建GitHub博客过程,选择主题为Next。

Git安装和配置

Git安装

  • 下载地址:downloads

  • 选择Mac版本并安装

  • 确认安装成功

1
git --version

Git GUI安装

  • 下载地址:git-scm

    建议:命令行用git bash,工具用SourceTree

    git常用命令:gittutorial

Git私钥公钥配置

Github配置

注册

创建Respository

  • new

    Repository name:[username].github.io

配置公钥

  • settings

  • 新建SSH Keys,输入本地公钥

  • 查看本地公钥:
    cd ~
    cd .ssh/
    cat id_rsa.pub
    拷贝结果至github的SSH Keys

Hexo安装和配置

Hexo安装

  • 安装:npm install -g hexo-cli

  • 初始化目录

    hexo init [folder]

  • hexo

Next主题安装

Hexo配置Github部署地址

  • 安装插件

    npm install hexo-deployer-git –save

  • 修改Hexo

    vi _config.yml,修改内容如下:

1
2
3
4
deploy:
type: git
repo: git@github.com:username/username.github.io.git
brach: master

Hexo操作

1
2
3
4
5
hexo s,启动

hexo d -g,生成并发布

hexo new ’title‘,新建文章

Mac后台启动Hexo服务

准备工作

  • 安装pm2

    npm install -g pm2

  • 编辑脚本代码

在hexo博客的根目录下新建run.js文件

1
2
3
4
5
6
7
8
9
10
//run.js
const { exec } = require('child_process')
exec('hexo s',(error, stdout, stderr) => {
if(error){
console.log(`exec error: ${error}`)
return
}
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
})
  • 运行

    pm2 start run.js

  • 重启
    pm2 restart all

------ 本文结束------

本文标题:快速搭建GitHub博客教程 - Hexo及Next主题安装

文章作者:Perkins

发布时间:2019年04月15日

原始链接:https://perkins4j2.github.io/posts/17587/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。