如何使用现有的服务创建免费、好看的自建博客

如何使用现有的服务创建免费、好看的自建博客

楔子

​ 近期想把自己的这些年的学习、工作经验整理写成博客,同时督促自己养成写作的习惯,所以调查研究了一番后决定使用现有的服务自建博客站,希望自己能坚持下来吧。

​ 第一篇就将自己搭建这个自建博客站的方式记下来吧。

使用到的在线服务

环境依赖 (使用到的软件)

  1. Node (node: 12.18.2; npm: 6.14.8;)

    1
    2
    3
    4
    5
    6
    # 使用以下命令更换npm的国内源,加速下载
    npm config set registry https://registry.npm.taobao.org
    # 或者使用以下命令
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    # 查看现在使用的源
    npm config get registry
  2. Git (2.28.0)

  3. Hexo (hexo: 5.1.1; hexo-cli: 4.2.0;)

    1
    2
    # 在npm和git已经安装完毕的情况下运行以下指令进行安装
    npm install -g hexo-cli

创建博客项目并发布

  1. 创建本地项目 (前提是已经安装 npm、git、hexo-cli 工具)

    1
    2
    3
    4
    5
    6
    7
    mkdir hexo
    cd ./hexo
    hexo init
    # 创建一篇新的文章 (hexo new [layout] <title>) 默认3种 layout 分别为: post page draft
    hexo new post "hello-world"
    # 开启本地预览服务器,命令执行成功后在浏览器打开localhost:4000可以查看效果
    hexo server
  2. 注册在线服务账号 (Coding.net、Github),具体注册流程自行在对应的站点的教程进行

  3. 配置本地项目中的_config.yml文件中的Deployment 部分

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    # Deployment
    ## Docs: https://hexo.io/docs/one-command-deployment
    deploy:
    - type: git
    repo: git@e.coding.net:user/user/hexo.git
    branch: hexo
    - type: git
    repo: git@github.com:user/user.github.io.git
    branch: hexo
    - type: sftp
    host: www.example.com
    user: bodil
    # pass: <password>
    remotePath: /usr/share/nginx/html
    # port: 22
    privateKey: /Users/bodil/OneDrive/SSH/id_rsa
    # passphrase: [passphrase]
    # agent: [path/to/agent/socket]

    这样在执行hexo generate -d命令 (hexo g -d) 后,将会将会把写好的文章生成为 html 文件并发布到对应的远程仓库中。(我的配置中还包含 sftp 的发布项,意味着在发布时也会把生成好的文件发布到 sftp 的对应目录中)

其它

参考

  1. Hexo 官方文档
  2. Ayer中文说明
  3. Hexo部署个人博客到Github Page和Coding Page并绑定域名
  4. Hexo 双线部署到 Coding Pages 和 GitHub Pages 并实现全站 HTTPS
  5. 快速搭建 Hexo 个人博客
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!

请我喝杯咖啡吧~

支付宝
微信