美文网首页
使用Hexo博客搭建的个人博客-macOS系统

使用Hexo博客搭建的个人博客-macOS系统

作者: 时间之友 | 来源:发表于2019-02-23 18:28 被阅读39次

    一、基础安装

    安装Git(略),安装 nvm

    curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
    nvm install stable
    
    

    安装后,输入若未出现 command not found ,而是出现一大串显示,则证明安装成功。

    二、本地部署

    npm install hexo-cli -g
    hexo init blog
    cd blog
    npm install
    hexo server
    

    依次输入上述指令。
    参考官网

    完成上述步骤,可以在本地打开blog了。

    三、网络部署

    1. 在 GitHub上新建一个 repository,命名规则是自定义名字+.github.io
    2. 在终端输入以下内容:
    git config --global user.name "你的"
    git config --global user.mail "你的邮箱"
    ssh-keygen -t rsa -C "你的GitHub注册账号的邮箱"
    

    会出现以下内容:

    Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/jkx/.ssh/id_rsa):
    /Users/jkx/.ssh/id_rsa already exists.
    Overwrite (y/n)? y     # 输入 y
    Enter passphrase (empty for no passphrase):      # 提示输入,不要输入直接enter
    Enter same passphrase again:
    Your identification has been saved in /Users/jkx/.ssh/id_rsa.
    Your public key has been saved in /Users/jkx/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:Etd+lKXMaVpk58VIDsJhzzWG4L6UVCkz3RRBIXrrxHU jkxruby@gmail.com
    The key's randomart image is:
    +---[RSA 2048]----+
    |         .=+*B&*.|
    |         +=@+&oo.|
    |      . . =+& + E|
    .........
    +----[SHA256]-----+
    
    1. 寻找 .ssh文件夹。 输入 cd .ssh/,打开,如下图:

    打开 id_rsa.pub,复制里面的SSH,然后在你的GitHub账号设置里新建一个 SSH Keys 。
    完成后,终端输入

    ssh -T git@github.com  # 测试用
    

    如果正常出现yes/no 选项,选择yes,当然我出现了报错ssh: connect to host github.com port 22: Operation timed out

    经过查找,找到原因,在 .ssh 文件夹中新建 config文件,里面的代码如下:

    Host github.com
    User git
    Hostname ssh.github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa
    Port 443
    
    1. 正式部署
      以上解决后,终端输入
      jkx@jkx ⮀ ~/Blog/blog ⮀npm install hexo-deployer-git --save

    打开文件 _config.yml,在最后添加:

    deploy:
      type: git
      repo: git@github.com:xxx/xxx.github.io.git   # 在你的repo里可以复制
      branch: master
    

    终端输入:hexo deploy,此时,打开你自己的网站,即可看到个人博客了。

    四、拓展

    以上完成了一个基础blog,如何让页面更好看呢?其实 hexo 上有很多好主题,找到一个主题,找到它的 GitHub,在终端clone
    git clone https://github.com/huweihuang/hexo-theme-huweihuang.git ./hexo-huweihuang

    相关文章

      网友评论

          本文标题:使用Hexo博客搭建的个人博客-macOS系统

          本文链接:https://www.haomeiwen.com/subject/nfgpyqtx.html