heox+github pages自建博客
heox官网: https://hexo.io/zh-cn/
博客预览:https://suesoft.github.io/
1.自建博客
# 1.全局安装脚手架hexo-cli
npm install hexo-cli -g
# 2.创建 myBlog 项目
hexo init myBlog # 此处失败的话需要挂梯子,解决1
cd myBlog
npm install
hexo server
解决1:
Step1: ping 一下 github.com。如果结果显示100%丢失,那么就是因为无法连接到GitHub导致。ping github.com
Step2: 从以下网站里面去获取能访问的ip,ping一下看能ping通不
站长工具网站、ipaddress、ip.cn查询网、DNS查询在线工具
Step3: 配置本地hosts(hosts在C:\Windows\System32\drivers\etc
下)# 13.114.40.48 是 Step2中获取的能 ping 通的ip地址 13.114.40.48 github.com
Step4: 刷新dns
ipconfig /flushdns
2. heox 发布到github pages上
- 创建github项目
登录github -> New -> Repository name(格式: 用户名.github.io) -> Description (填写描述) -> Public -> 创建
创建成功后,复制项目链接(git@github.com:xxx/xxx.github.io.git) - github配置公私钥
- 获取公私钥
# 确保安装了git, 打开git bash here,执行以下操作获取公私钥 ssh-keygen -t rsa -C "xx@xx.com" ls ~/.ssh cat ~/.ssh/id_rsa.pub # copy
- github添加ssh-key
个人中心,找到settings -> SSH and GPG keys -> New SSH key -> 粘贴公钥
验证是否配置成功:ssh -T git@github.com
- 获取公私钥
- 安装hexo-deployer-git并推送
网站: https://github.com/hexojs/hexo-deployer-git# 安装hexo-deployer-git npm install hexo-deployer-git --save # hexo generate hexo g # hexo deploy hexo d
3.保存源码
- 更改仓库的默认分支
可以新建一个source分支来保存源码
在仓库的主页面,通过Settings -> Branchs,可以看到Default branch的Tab,显示的默认分支是master,可以勾选source,然后update即可将默认分支设置为source - 将本地hexo目录与远程仓库关联
git remote add origin https://github.com/xxx/xxx.github.io.git
注:如果此处关联不成功,可以把source分支下载下来,然后复制里面的.git文件夹到blog下’
- 推送博客源码
添加.gitignore文件
推送.DS_Store Thumbs.db db.json *.log node_modules/ public/ .deploy*/
git add . git commit -m 'hexo blog source file' git push origin source
4.hexo-theme-next主题
配置文件:http://theme-next.iissnan.com/getting-started.html
- 更改主题hexo-theme-next
修改_config.yml文件cd myBlog # 之后的更新可以通过 git pull 来快速更新 git clone https://github.com/next-theme/hexo-theme-next themes/next
推送# Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ theme: next
hexo clean hexo server hexo g # hexo generate hexo d # hexo deploy
- 主题美化
参考: https://zhuanlan.zhihu.com/p/251383216
5.使用hexo新建、编辑并预览文章
参考: https://zhuanlan.zhihu.com/p/132823826
- 新建文章
hexo支持三种布局(layout):post(默认)、draft、page
# 默认使用post布局,然后自动在source\_posts目录生成一个text1.md文件
hexo n text1
# 指定布局
hexo n [layout_name] text1
创建草稿布局并推送到_posts目录下。可以使用 hexo --draft
命令可以查看已有草稿。
hexo n draft draft1
hexo publish draft1