首先,当然是nodejs以及git的安装了,还有gihub新建一个用户名.github.io的仓库,此处就不多说啦。hh
SSH绑定github
ssh-keygen -t rsa -C "email@qq.com"
将id_rsa.pub的公钥复制到github 头像那里 setting 的 SSH keys
ssh -T git@github.com测试是否ssh绑定成功
Hi qwtoe! You've successfully authenticated, but GitHub does not provide shell access.
hexo生成本地Blog
到blog文件下git bash here
hexo init初始化,将github的hexo拉到本地。
$ hexo init
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
INFO Install dependencies
NFO Start blogging with Hexo!
hexo s静态生成本地hexo页面,相当于打开本地服务器, 即本地预览。
$ hexo s
INFO Validating config
INFO Start processing
INFO Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.
发布
- 修改
_config.yml文件:
deploy:
type: git
repository: https://github.com/qwtoe/qwtoe.github.io.git
branch: main
respository的内容就是仓库Code下的HTTPS里的链接:
最后,到本地blog文件下git bash here
npm install hexo-deployer-git --savehexo clean# 清除缓存,网页正常情况下可以忽略此条命令hexo g# 生成页面hexo d# 上传github,多试几次
可以合并后两个命令为hexo g -d
成功后就可以在 用户名.github.io 访问 texo 的 hello world 页面 !
Done ! 以上 hexo 在 github 上部署的基本流程就完成了!
下阶段就可以学习如何写自己新的博客,并发布到github。
# 总结主要 hexo 命令
hexo n # 新建 md
hexo g -d # 生成静态网页并部署到 Github
or hexo -d g
- hexo常用命令笔记, from here。
hexo 文件目录结构
public存放的是生成的静态页面 source/_posts 存放的是我们写的文章 themes 下存放的的是博客的主题 _config.yml是博客全局配置文件 _config.landscape.yml是博客主题配置文件
可能出现的问题
-
如果在github新建READ.md后,
texo d后会覆盖掉github原本的READ.md,即READ.md会消失。解决办法
(1).在source目录下新建一个 READ.md 即可,这个 READ.md 在texo d后就相当于 github 原本的 READ.md 了
(2)._config.yml中设置skip_render: README.md让md文件不被转换成HTML
(3).texo g -d -
hexo更换主题后 报错: extends includes/layout.pug block content include includes/recent-posts.pug include includes/partial
解决办法: 执行
npm install --save hexo-renderer-jade hexo-generator-feed hexo-generator-sitemap hexo-browsersync hexo-generator-archive
再 hexo clean && hexo g && hexo s
3.npm安装包时报错: npm ERR! arg Argument starts with non-ascii dash, this is probably invalid: –save
解决办法: 因为安装命令是从其他地方复制过来的,现在将安装命令重新手敲一篇再执行就行。