Mac搭建hexo指南

来源:互联网 发布:mac 卸载自带输入法 编辑:程序博客网 时间:2024/06/08 08:09

Mac搭建Hexo指南

亲身搭建成功,总结的步骤

  1. 安装brew包管理器,Mac自带ruby命令
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. 安装Nodejs

    brew install node
  2. 安装hexo

    npm config set registry="http://registry.cnpmjs.org"sudo npm install -g hexo
  3. 初始化hexo

    hexo init <folder>  #执行init命令初始化hexo到你指定的目录例如:hexo init hexo,则会在当前目录下生成hexo目录以下命令在hexo目录下执行。
  4. 安装依赖包

    npm install
  5. 生成静态网页

     hexo generate #自动根据当前目录下文件,生成静态网页或者hexo g
  6. 运行本地服务

    hexo server或者hexo s

    此时在浏览器中输入:localhost:4000,可查看静态的网页

  7. 添加博文

    hexo new "postName"  #新建博文,其中postName是博文题目例如:hexo n "青云"

    刷新上述静态网页,可看到新添加的一篇博文。

    PS:博文会自动生成在博客目录下source/_posts/postName.md

  8. 部署到github

    1. 打开github.com,注册github账户,如名字username,创建仓库仓库username.github.io
    2. 配置ssh-key

      git config --global user.email "你的邮箱"git config --global user.name "你的用户名"ssh-keygen -t rsa -C "你的邮箱"回车三次,在~/.ssh/下会生成id_rsa和id_rsa.pub两个文件复制id_rsa.pub文件内容到github账户下的ssh keys的新建key里面,ADD
    3. 修改hexo目录下_config.yml,在最后添加以下内容

      deploy:type: gitrepository: git@github.com:username/username.github.io.gitbranch: master
    4. 执行npm install hexo-deployer-git --save
    5. 执行hexo ghexo d完成部署
  9. 打开浏览器并输入username.github.io来查看你的博客
0 0