hexo结合git搭建blog基础

背景

如何不用花钱(服务器,域名)就能拥有自己的blog?gitpage+hexo,实现你的愿望

准备工作

  1. 自行安装git客户端
  2. 自行注册git账户
  3. 自行安装npm、node.js

操作步骤

建库

新建一个名为(你的用户名.github.io)的仓库,比如说,如果你的github用户名是username,那么你就新建username.github.io的仓库
访问地址就是 http://username.github.io

配置SSH key

cd ~/. ssh #检查本机已存在的ssh密钥
//提示:No such file or directory 说明你是第一次使用git。
ssh-keygen -t rsa -C "邮件地址"
//回车会生成一个文件在用户目录下,找到.ssh\id_rsa.pub文件,打开并复制里面的内容
//打开你的github主页,进入个人设置 -> SSH and GPG keys -> New SSH key:
//将刚复制的内容粘贴到key那里,title随意,保存。
//测试效果
ssh -T [email protected] # 注意邮箱地址不用改
//Are you sure you want to continue connecting (yes/no)?输入yes
//出现hi  XXXXXX即成功
//继续配置个人信息
git config --global user.name "xxx"// 你的github用户名,非昵称
git config --global user.email  "[email protected]"// 填写你的github注册邮箱

hexo安装配置及使用

//安装
npm install -g hexo 
//初始化
//新建一个名为hexo的文件夹(名字随意),比如我的是D:\hexo
cd /d/hexo/
hexo init
//public下根据.md生成html文件
hexo g 
//启动本地服务
hexo s
//更换默认主题(hexo支持N多主题,具体请查看对应文档,yilia和next两款不错)
git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia

更改站点配置文件_config.yml,启用yilia主题

//将landscape改为yilia
theme: yilia
//执行清理
hexo clean
//重新生成
hexo g

更改站点配置文件中的git配置

//此处针对hexo 3,不排除高版本再改变
deploy:
  type: git
  repository: [email protected]:username/username.github.io.git
  branch: master

安装hexo-deployer-git否则报错Deployer not found: github

npm install hexo-deployer-git --save

提交至git

hexo d

常用hexo命令

hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help  # 查看帮助
hexo version  #查看Hexo的版本
//简写
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
//组合
hexo s -g #生成并本地预览
hexo d -g #生成并上传

关于写文章

推荐使用sublime + markdown插件 或 atom或vscode
方便调试md文档
关于mardown语法请自行学习(很简单)

猜你喜欢

转载自blog.csdn.net/MrCoderStack/article/details/88547850
今日推荐