一、hexo+github搭建个人博客的过程记录

前提:

1.新建一个github仓库

2.安装配置Node.js

3.安装配置Git

前提

步骤1.新建一个github仓库

  1. 打开github网站,(注册)登录账号,新建一个仓库;

注:==仓库名称要求,yourname.github.io;==

​ 勾选Initialize this repository with a README;

  1. 新建完成后打开仓库,点击右侧settings按钮,开启下面的GitHub Pages;
  2. Source保存为master branch,上面的链接是之后博客访问的链接

步骤2.安装Node.js

  1. 打开Node.js官网下载对应操作系统版本及位数的node.js

  2. 安装完成后可通过以下命令验证是否已配置成功(默认安装已自动配置环境变量)

    node -v
    npm -v

步骤3.安装git

  1. 打开Git官网下载对应操作系统版本及位数的git

  2. 安装完成后可通过一下命令验证是否配置成功(默认安装已自动配置环境变量,即选择use Git from the Windows Command Prompt)

    git --version
  3. 配置git

    1. 鼠标右键打开git bash here(以下命令都是在git bash下执行)

    2. 设置git的user name和email(第一次使用)

      git config --global user.name "yourname"
      git config --global user.email "youremail"
    3. 配置ssh

      #生成密钥,默认存储路径:C:\User\Administrator\.ssh
      ssh-keygen -t rsa -C"youremail"
      #添加密钥到ssh-agent
      eval "$(ssh-agent -s)"
      #添加生成的SSH key到ssh-agent
      ssh -add ~/.ssh/id_rsa
    4. 在github上添加ssh key.

      #步骤1
      登录github,点击头像下的settings
      #步骤2
      打开左侧的SSH and GPG keys
      #步骤3
      点击右侧的new SSH key
      #步骤4
      Title 自定义
      Key输入刚才生成的C:\User\Administrator\.ssh路径下的id_rsa.pub
    5. 验证ssh是否添加成功

      ssh -T [email protected]
    6. ssh-key配置失败解决方法

      首先,清除所有的key-pair
      ssh-add -D
      rm -r ~/.ssh
      删除你在github中的public-key
      
      重新生成ssh密钥对
      ssh-keygen -t rsa -C "[email protected]"
      
      接下来正常操作
      在github上添加公钥public-key:
      1、首先在你的终端运行 xclip -sel c ~/.ssh/id_rsa.pub将公钥内容复制到剪切板
      2、在github上添加公钥时,直接复制即可
      3、保存

小试牛刀

hexo+github设置

安装Hexo

  1. 找到一个合适的位置创建一个新的文件夹,必须是空的。实例文件夹:D:\Blog

  2. 打开cmd,进入新建的文件

    d:
    cd Blog
  3. 安装hexo

    npm install hexo -g
  4. 验证是否安装成功

    hexo -v

配置Hexo

  1. 初始化Blog文件夹

    hexo init
  2. 安装必要的组件

    npm install
  3. 生成目录结构

    hexo g
    #或
    hexo generate
  4. 开启hexo服务,预览界面

    hexo s
    #或
    hexo server
  5. 第一次访问

    访问:localhost:4000,可看到加载的页面。

Hexo联系Github

打开hexo配置文件;D:\Blog\_config.yml

文件末尾处配置:

repository:打开github仓库点击Clone or download,复制里面ssh对应的仓库地址;

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: [email protected]:username/username.github.io.git
  branch: master

猜你喜欢

转载自www.cnblogs.com/tassel/p/10961906.html