Hexo部署github博客

逃离我推掉我的手 2022-05-14 06:39 456阅读 0赞

Hexo部署github博客

一、简介

使用github创建一个仓库为github.io就能变成一个使用域名能够访问的博客站点。然后我们通过Hexo创建文章,发布到github.io仓库,Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。Hexo能够快速生成博客和部署博客,使创建博客更加简单。

二、安装清单(Mac OS)






















安装环境 安装原因
git 给github上传文章
Node.js Hexo基于Node.js开发
Hexo 生成博客静态页面

三、创建github.io网站

1)点击New repository

2)输入Repository name,必需为username.github.io格式。username替换为用户名

3)点击按钮Create repository

4)进入仓库username.github.io,点击setting,找到GitHub Pages模块

5)点击choose a theme选择一个页面主题

6)访问https://username.github.io就可以访问博客网站了

四、安装git

下载安装:http://sourceforge.net/projects/git-osx-installer/

验证是否安装成功:

  1. ~ git version
  2. git version 2.15.0

五、安装Node.js

下载安装:https://nodejs.org/en/

验证是否安装成功:

  1. ~ node -v
  2. v8.9.4

六、安装Hexo

安装命令: npm install -g hexo-cli

验证是否安装成功:

  1. ~ hexo -v
  2. hexo-cli: 1.1.0
  3. os: Darwin 17.3.0 darwin x64
  4. http_parser: 2.7.0
  5. node: 8.9.4
  6. v8: 6.1.534.50
  7. uv: 1.15.0
  8. zlib: 1.2.11
  9. ares: 1.10.1-DEV
  10. modules: 57
  11. nghttp2: 1.25.0
  12. openssl: 1.0.2n
  13. icu: 59.1
  14. unicode: 9.0
  15. cldr: 31.0.1
  16. tz: 2017b

七、创建本地博文服务

  1. 然后创建一个空文件夹, 比如:hexo-blog
  2. 进入hexo-blog目录
  3. 执行hexo init初始化博客站点,如果最后一行显示Start blogging with Hexo!,代表创建成功
  4. 执行hexo server 启动博文站点
  5. 访问http://localhost:4000就能打开博文了
  6. Ctrl+C关闭服务器

    ➜ ~ mkdir hexo-blog
    ➜ ~ cd hexo-blog
    ➜ hexo-blog hexo init
    INFO Cloning hexo-starter to ~/hexo-blog
    Cloning into ‘/Users/zhengyong/hexo-blog’…
    remote: Counting objects: 68, done.
    remote: Total 68 (delta 0), reused 0 (delta 0), pack-reused 67
    Unpacking objects: 100% (68/68), done.
    Submodule ‘themes/landscape’ (https://github.com/hexojs/hexo-theme-landscape.git) registered for path ‘themes/landscape’
    Cloning into ‘/Users/zhengyong/hexo-blog/themes/landscape’…
    remote: Counting objects: 838, done.
    remote: Compressing objects: 100% (6/6), done.
    remote: Total 838 (delta 1), reused 3 (delta 0), pack-reused 832
    Receiving objects: 100% (838/838), 2.55 MiB | 90.00 KiB/s, done.
    Resolving deltas: 100% (441/441), done.
    Submodule path ‘themes/landscape’: checked out ‘73a23c51f8487cfcd7c6deec96ccc7543960d350’
    INFO Install dependencies
    npm WARN deprecated titlecase@1.1.2: no longer maintained
    npm WARN deprecated postinstall-build@5.0.3: postinstall-build’s behavior is now built into npm! You should migrate off of postinstall-build and use the new prepare lifecycle script with npm 5.0.0 or greater. > fsevents@1.2.4 install /Users/zhengyong/hexo-blog/node_modules/fsevents > node install [fsevents] Success: “/Users/zhengyong/hexo-blog/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node” already installed Pass —update-binary to reinstall or —build-from-source to recompile > nunjucks@3.1.3 postinstall /Users/zhengyong/hexo-blog/node_modules/nunjucks > node postinstall-build.js src npm notice created a lockfile as package-lock.json. You should commit this file. added 464 packages in 28.659s INFO Start blogging with Hexo! ➜ hexo-blog hexo server INFO Start processing INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop. ^CINFO Good bye

七、Hexo关联github

1)进入hexo-blog根目录

2)安装npm install hexo-deployer-git --save,用Hexo发布博文

3)打开hexo-blog根目录下的_config.yml,拉倒最下面, 修改Deployment方式如下:

  1. # Deployment
  2. ## Docs: http://hexo.io/docs/deployment.html
  3. deploy:
  4. type: git
  5. repository: https://github.com/username/username.github.io
  6. branch: master

4)进入hexo-blog根目录执行如下命令(参考:https://hexo.io/zh-cn/docs/commands),第一次上传可能会让你输入git的用户名和密码

  1. hexo clean
  2. hexo generate
  3. hexo deploy

5)如果成功,就可以打开 http://username.github.io,username替换成自己用户名

八、使用Hexo创建和发布文章

1) 进入hexo-blog根目录

2) 创建文章命令:hexo new "文章标题"

  1. blog hexo new "Hexo部署github博客"
  2. INFO Created: ~/Documents/GitHub/hexo-blog/source/_posts/Hexo部署github博客.md

3) 打开编辑Hexo部署github博客.md文件进行Markdown编辑

  1. open ~/Documents/GitHub/hexo-blog/source/_posts/Hexo部署github博客.md`

4)发布文章:hexo d -g

  1. blog hexo d -g
  2. INFO Start processing
  3. INFO Files loaded in 922 ms
  4. INFO Generated: index.html
  5. INFO Generated: archives/2018/09/index.html
  6. INFO Generated: archives/index.html
  7. INFO Generated: 2018/09/03/hello-world/index.html
  8. INFO Generated: archives/2018/index.html
  9. INFO Generated: 2018/09/03/my-first-hexo-blog/index.html
  10. INFO Generated: fonts/iconfont.8c627f.woff
  11. INFO Generated: fonts/iconfont.45d7ee.svg
  12. INFO Generated: fonts/iconfont.16acc2.ttf
  13. INFO Generated: fonts/default-skin.b257fa.svg
  14. INFO Generated: fonts/tooltip.4004ff.svg
  15. INFO Generated: img/default-skin.png
  16. INFO Generated: img/scrollbar_arrow.png
  17. INFO Generated: img/preloader.gif
  18. INFO Generated: fonts/iconfont.b322fa.eot
  19. INFO Generated: slider.e37972.js
  20. INFO Generated: mobile.992cbe.js
  21. INFO Generated: main.0cf68a.js
  22. INFO Generated: main.0cf68a.css
  23. INFO Generated: 2018/09/04/Hexo部署github博客/index.html
  24. INFO 20 files generated in 475 ms
  25. INFO Deploying: git
  26. INFO Clearing .deploy_git folder...
  27. INFO Copying files from public folder...
  28. INFO Copying files from extend dirs...
  29. warning: CRLF will be replaced by LF in fonts/tooltip.4004ff.svg.
  30. The file will have its original line endings in your working directory.
  31. [master d1c205f] Site updated: 2018-09-04 11:11:08
  32. 6 files changed, 835 insertions(+)
  33. create mode 100644 2018/09/04/Hexo部署github博客/index.html
  34. To https://github.com/zyongjava/zyongjava.github.io
  35. 3f0aab7..d1c205f HEAD -> master
  36. Branch 'master' set up to track remote branch 'master' from 'https://github.com/zyongjava/zyongjava.github.io'.
  37. INFO Deploy done: git

九、参考文献

  1. https://www.jianshu.com/p/863f3f2d1733
  2. https://hexo.io/zh-cn/docs/commands

十、示列博客

移步:https://zyongjava.github.io/

发表评论

表情:
评论列表 (有 0 条评论,456人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Hexo Github 搭建

    ![配图][alejandro-escamilla-9.jpg] 前言 在 搬砖 的过程中,浏览了许多 别人写的博客后,自己也萌生了写博客的念头。 其一是为了系统的整

    相关 搭建静态hexo+github

      经过一段时间的折腾,第一个静态博客终于建了起来。相比wordpress的庞大臃肿,博主更喜欢hexo这个轻量级的博客框架。在这里记录下整个搭建过程,希望对大家也能够有所帮助