hexo搭建个人 博客
-
前期工具安装
-
GitHub存储库配置文件
-
新建一个名字为username.github.io的仓库,仓库不会立刻生效,需要一端时间
-
配置ssh key:
-
$ cd ~/. ssh #检查本机已存在的ssh密钥
-
如果没有这个文件那么使用*ssh-keygen -t rsa -C “邮件地址”*然后三次回车,会产生一个.ssh\id_rsa.pub文件,复制里面内容,打开github,添加新的ssh key
-
ssh -T git@github.com这句话进行连接,填写yes即可
-
同时还需要配置对你GitHub进行绑定
$ git config --global user.name "liuxianan"// 你的github用户名,非昵称 $ git config --global user.email "xxx@qq.com"// 填写你的github注册邮箱
-
-
-
hexo使用
- 很多命令既可以用Windows的cmd来完成,也可以使用git bash来完成,但是部分命令会有一些问题,为避免不必要的问题,建议全部使用git bash来执行;
- hexo不同版本差别比较大,网上很多文章的配置信息都是基于2.x的,所以注意不要被误导;
- hexo有2种
_config.yml
文件,一个是根目录下的全局的_config.yml
,一个是各个theme
下的; - 安装命令:npm install -g hexo
- 初始化,选定储存文件夹,进入文件夹中,执行hexo init即可自动下载
- 执行语句:hexo g 生成目录结构
- 启动服务: hexo s 启动服务,打开本地预览服务,打开服务器访问 http://localhost:4000 即可看到你内容,如果没有内容,一般是端口占用,解决端口冲突参考文章
- 修改主题,自己可以去网上下载,我一般是这个主题,使用git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia下载
- 修改
_config.yml
中的theme: landscape
改为theme: yilia
,然后重新执行hexo g
来重新生成 - 如果出现一些莫名其妙的问题,可以先执行
hexo clean
来清理一下public的内容,然后再来重新生成和发布。
-
发布
-
注意,冒号后面必须要有个空格
-
配置_config.yml中有关disploy中的部分
deploy: type: git repository: git@github.com:liuxianan/liuxianan.github.io.git branch: master
-
执行hexo d进行部署,在这之前,下载插件npm install hexo-deployer-git
-
成功即可
-
-
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 #生成并上传
-
写文章:在我们hexo根目录下,执行命令:hexo new '博客内容’ 打开文件即可
-
错误集锦
1.关于错误:ssh: Could not resolve hostname github.com: Name or service not known.fatal: Could not read from remote repository.: 我这里只是说一种原因,就是更新不及时,别着急等一会就好