hexo+github搭建个人博客

windows环境下
准备工作

  1. 下载安装node.js并安装,默认安装npm
  2. 下载安装git和Git Bash

本地搭建hexo静态博客

  1. 新建一个文件夹,如myBlog
  2. 进入该文件夹,右键点击Git Bash Here
  3. 下载安装hexo:npm install hexo-cli -g
    • image.png
  4. 生成hexo模板:hexo init blog (初始化该文件夹)
  5. 进入blog文件夹:npm install
  6. 进入blog文件夹:hexo server(访问本地localhost:4000可以看到博客已经搭建成功)
  • image.png

将博客与github关联

  1. 在Github上创建名为xxx.github.io的仓库,xxx为自己github的用户名。
  2. 打开本地的myBlog的blog文件夹内的_config.yml配置文件,将其中的type设置为git
  • image.png
  1. 进入blog文件夹运行 npm install hexo-deployer-git --save
  • image.png
  1. hexo generate
  2. hexo deploy
  3. 进入xxx.github.io对应的 repo,打开 GitHub Pages 功能,如果已经打开了,就直接点击预览链接。也可打开浏览器,访问:https://qfstudy.github.io

编辑博客

  1. hexo new 博客标题
  2. 编辑\source_posts下对应的md文件
  • image.png
  1. hexo generate
  2. hexo deploy
    这时打开博客就看到自己新编辑的博客

更新文章

  1. 在blog目录下执行:hexo new “我的第一篇文章”,会在source/_posts文件夹内生成一个.md文件。
  2. 编辑该文件(遵循Markdown规则)
  3. 修改起始字段
  • title 文章的标题
  • date 创建日期 (文件的创建日期 )
  • updated 修改日期 ( 文件的修改日期)
  • comments 是否开启评论 true
  • tags 标签
  • categories 分类
  • permalink url中的名字(文件名)
  1. 编写正文内容(MakeDown)
  2. hexo clean 删除本地静态文件(Public目录),可不执行。
  3. hexo g 生成本地静态文件(Public目录)
  4. hexo deploy 将本地静态文件推送至github(hexo d)

上传源代码
注意(xxx.github.io)上保存的只是你的博客,并没有保存生成博客的程序代码,你需要再创建一个名为 blog-generator(可以随意命名) 的空仓库,用来保存 myBlog 里面的生成博客的程序代码。

  • image.png
  • image.png

以后每次hexo deploy 完之后,博客就会更新;然后你还要要 git add /git commit /git push 一下上传生成博客的程序代码,以防万一。


更换主题

  1. 进入Hexo的官网主题专栏
  2. github:https://github.com/hexojs/hexo/wiki/Themes
  3. 复制它的 SSH 地址或 HTTPS 地址,假设地址为 [email protected]:iissnan/hexo-theme-next.git
  4. cd themes
  5. git clone [email protected]:iissnan/hexo-theme-next.git
  6. cd ..
  7. 将 _config.yml 的第 75 行改为 theme: hexo-theme-next,保存
  8. hexo generate
  9. hexo deploy
  10. 等一分钟,然后刷新你的博客页面,你会看到一个新的外观。如果不喜欢这个主题,就回到第 1 步,重选一个主题。

next主题配置

  1. 更改社交链接,在主题文件夹的_config.yml中修改
    • image.png

参考
https://github.com/limedroid/HexoLearning

猜你喜欢

转载自www.cnblogs.com/qfstudy/p/8979589.html