利用GitHub和Hexo搭建一个博客

简单搭建一个免费博客

环境要求

  • Node.js
  • Git
  • 最好再下载个文本编辑器vscode,hbuiderx之类的

直接官网下载一路下一步即可

创建Hexo

  • 在D盘创建一个名为Hexo的文件夹
  • win+R打开cmd

image-20210822144700799

  • 先输入D:
  • 然后输入cd D:/Hexo

image-20210822145532043

使用Npm安装Hexo

npm config set registry http://mirrors.cloud.tencent.com/npm/
npm install -g hexo

image-20210821171155691

  • 安装好测试下

  • hexo
    

image-20210821171325910

初始化Hexo

hexo init

image-20210821171425927

构建Hexo

hexo g

image-20210821171652058

启动服务器

hexo s

出现错误的话就执行

npm install hexo-server --save

在执行

hexo s

image-20210821171945621

然后浏览器访问

http://localhost:4000

部署到GitHub

  • 打开GitHub

  • 注册账号

  • 设置git

  • 在桌面鼠标右键 -> Git Bash Here,设置用户名和邮箱

  • git config --global user.name "GitHub 用户名"
    git config --global user.email "GitHub 邮箱"
    
  • 1629617786444

  • 创建密钥

  • ssh-keygen -t ed25519 -C "GitHub 邮箱"
    
  • 然后一路回车

  • 添加密匙

  • 进入 [C:\Users\用户名.ssh] 目录(要勾选显示“隐藏的项目”),用记事本打开公钥 id_rsa.pub 文件并复制里面的内容。

  • 登录GitHub找到设置

  • image-20210822154507271

  • 找到ssh

  • image-20210822154844348

  • 点击 New SSH keyTitle 随便取个名字,粘贴复制的 id_rsa.pub 内容到 Key 中,点击 Add SSH key 完成添加。

  • 打开 Git Bash,输入 ssh -T git@github.com 出现 “Are you sure……”,输入 yes 回车确认。

  • 显示 “Hi xxx! You've successfully……” 即连接成功。

  • 建个仓库

image-20210822150720934

创建一个和你用户名相同的仓库,后面加.github.io,只有这样,将来要部署到GitHub page的时候,才会被识别,也就是xxxx.github.io,其中xxx就是你注册GitHub的用户名。点击Create repository

image-20210822151732662

选择复制SSH

image-20210822154326413

本地安装hexo-deployer-git

image-20210821172806180

image-20210821181754956

打开hexo目录下的_config.yml文件修改repo就是复制的ssh地址,不行的话试试https地址branch如果建仓库时显示的是main就填main默认master

image-20210821181656572

部署

  • hexo d

image-20210821181627208

这就可以访问了地址是用户名.github.io

写博客

hexo new "New"

在Hexo目录下的source-_posts文件夹内,就会出现刚刚创建的文章:New.md

写完之后

hexo clean
hexo g
hexo d

md是Markdown文件

Hexo常见命令

 hexo g #生成
 hexo s #开启本地预览服务 http://localhost:4000
 hexo clean #清理public内容
 hexo new "FileName" #新建文章
 hexo d #上传到Github
 hexo help  # 查看帮助
 hexo version  #查看Hexo的版本

欢迎访问我的小站

Ding's Blog (jeffding99.github.io)

可导不一定可微 - dss (ding99.top)

posted @ 2021-08-22 16:17  丁帅帅dss  阅读(57)  评论(0)    收藏  举报