使用 Hexo + Github 或 Gitee 搭建个人博客

朴灿烈づ我的快乐病毒、 2021-12-20 07:13 475阅读 0赞
  • Hexo 安装部署
  1. 安装 Node.js

    cURL方式:

    1. [root@node00 ~]# curl https://raw.github.com/creationix/nvm/v0.33.11/install.sh | sh
    2. % Total % Received % Xferd Average Speed Time Time Time Current
    3. Dload Upload Total Spent Left Speed
    4. 0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0

    wget方式:

    1. [root@node00 ~]# wget -qO- https://raw.github.com/creationix/nvm/v0.33.11/install.sh | sh
    2. => Downloading nvm from git to '/root/.nvm'
    3. => Cloning into '/root/.nvm'...
    4. remote: Enumerating objects: 267, done.
    5. remote: Counting objects: 100% (267/267), done.
    6. remote: Compressing objects: 100% (242/242), done.
    7. remote: Total 267 (delta 31), reused 80 (delta 15), pack-reused 0
    8. Receiving objects: 100% (267/267), 119.47 KiB | 0 bytes/s, done.
    9. Resolving deltas: 100% (31/31), done.
    10. => Compressing and cleaning up git repository
    11. => Appending nvm source string to /root/.bashrc
    12. => Appending bash_completion source string to /root/.bashrc
    13. => Close and reopen your terminal to start using nvm or run the following to use it now:
    14. export NVM_DIR="$HOME/.nvm"
    15. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    16. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

    重启系统,运行 nvm install stable 命令

    1. [root@node00 script]# nvm install stable
    2. -bash: nvm: command not found
    3. [root@node00 script]# reboot
    4. [root@node00 ~]# nvm install stable
    5. Downloading and installing node v12.5.0...
    6. Downloading https://nodejs.org/dist/v12.5.0/node-v12.5.0-linux-x64.tar.xz...
    7. nvm install stable
    8. ######################################################################## 100.0%
    9. Computing checksum with sha256sum
    10. Checksums matched!
    11. Now using node v12.5.0 (npm v6.9.0)
    12. Creating default alias: default -> stable (-> v12.5.0)
    13. [root@node00 ~]# nvm install stable
    14. v12.5.0 is already installed.
    15. Now using node v12.5.0 (npm v6.9.0)
  2. 安装 git

    1. [root@node00 ~]# yum -y install git
    2. [root@node00 ~]# git version
    3. git version 1.8.3.1
  3. 安装 Hexo

    1. [root@node00 ~]# npm install -g hexo-cli
    2. /root/.nvm/versions/node/v12.5.0/bin/hexo -> /root/.nvm/versions/node/v12.5.0/lib/node_modules/hexo-cli/bin/hexo
    3. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/hexo-cli/node_modules/fsevents):
    4. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    5. + hexo-cli@2.0.0
    6. added 187 packages from 432 contributors in 86.687s
  4. 建站初始化

    1. [root@node00 ~]# hexo init ~/blog
    2. INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
    3. Cloning into '/root/blog'...
    4. remote: Enumerating objects: 9, done.
    5. remote: Counting objects: 100% (9/9), done.
    6. remote: Compressing objects: 100% (7/7), done.
    7. remote: Total 77 (delta 4), reused 5 (delta 2), pack-reused 68
    8. Unpacking objects: 100% (77/77), done.
    9. Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
    10. Cloning into 'themes/landscape'...
    11. remote: Enumerating objects: 33, done.
    12. remote: Counting objects: 100% (33/33), done.
    13. remote: Compressing objects: 100% (29/29), done.
    14. remote: Total 929 (delta 12), reused 12 (delta 3), pack-reused 896
    15. Receiving objects: 100% (929/929), 2.56 MiB | 21.00 KiB/s, done.
    16. Resolving deltas: 100% (492/492), done.
    17. Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
    18. INFO Install dependencies
    19. npm WARN deprecated core-js@1.2.7: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
    20. npm notice created a lockfile as package-lock.json. You should commit this file.
    21. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    22. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    23. added 340 packages from 498 contributors and audited 6879 packages in 35.061s
    24. found 0 vulnerabilities
    25. INFO Start blogging with Hexo!
    26. [root@node00 ~]# cd blog/
    27. [root@node00 blog]# npm install
    28. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    29. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    30. audited 6879 packages in 4.298s
    31. found 0 vulnerabilities
  5. 生成静态文件

    1. # 或者使用 hexo g
    2. [root@node00 blog]# hexo generate
    3. INFO Start processing
    4. INFO Files loaded in 531 ms
    5. INFO Generated: index.html
    6. INFO Generated: archives/index.html
    7. INFO Generated: fancybox/blank.gif
    8. INFO Generated: fancybox/fancybox_loading.gif
    9. INFO Generated: fancybox/fancybox_loading@2x.gif
    10. INFO Generated: fancybox/fancybox_overlay.png
    11. INFO Generated: fancybox/fancybox_sprite@2x.png
    12. INFO Generated: archives/2019/06/index.html
    13. INFO Generated: js/script.js
    14. INFO Generated: fancybox/helpers/jquery.fancybox-buttons.css
    15. INFO Generated: fancybox/fancybox_sprite.png
    16. INFO Generated: fancybox/jquery.fancybox.css
    17. INFO Generated: fancybox/helpers/jquery.fancybox-buttons.js
    18. INFO Generated: fancybox/helpers/jquery.fancybox-media.js
    19. INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.css
    20. INFO Generated: fancybox/helpers/jquery.fancybox-thumbs.js
    21. INFO Generated: css/style.css
    22. INFO Generated: fancybox/jquery.fancybox.js
    23. INFO Generated: fancybox/jquery.fancybox.pack.js
    24. INFO Generated: archives/2019/index.html
    25. INFO Generated: css/fonts/FontAwesome.otf
    26. INFO Generated: css/fonts/fontawesome-webfont.svg
    27. INFO Generated: css/fonts/fontawesome-webfont.eot
    28. INFO Generated: css/fonts/fontawesome-webfont.woff
    29. INFO Generated: fancybox/helpers/fancybox_buttons.png
    30. INFO Generated: css/images/banner.jpg
    31. INFO Generated: css/fonts/fontawesome-webfont.ttf
    32. INFO Generated: 2019/06/28/hello-world/index.html
    33. INFO 28 files generated in 722 ms
  6. 启动服务器

    1. # 或者使用 hexo s
    2. [root@node00 blog]# hexo server
    3. INFO Start processing
    4. INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop

    在这里插入图片描述

  7. 安装主题

    下载主题到 blog/themes 目录下

    1. [root@node00 blog]# git clone https://github.com/iissnan/hexo-theme-next themes/next
    2. Cloning into 'themes/next'...
    3. remote: Enumerating objects: 12037, done.
    4. remote: Total 12037 (delta 0), reused 0 (delta 0), pack-reused 12037
    5. Receiving objects: 100% (12037/12037), 13.04 MiB | 18.00 KiB/s, done.
    6. Resolving deltas: 100% (6964/6964), done.

    修改配置

    1. # Extensions
    2. ## Plugins: https://hexo.io/plugins/
    3. ## Themes: https://hexo.io/themes/
    4. # 将 landscape 改为你想要的主题的目录名
    5. theme: landscape

    重新启动

    1. [root@node00 blog]# hexo && hexo g && hexo s
    2. Usage: hexo <command>
    3. Commands:
    4. clean Remove generated files and cache. config Get or set configurations. deploy Deploy your website. generate Generate static files. help Get help on a command. init Create a new Hexo folder. list List the information of the site migrate Migrate your site from other system to Hexo. new Create a new post. publish Moves a draft post from _drafts to _posts folder. render Render files with renderer plugins. server Start the server. version Display version information.
    5. Global Options:
    6. --config Specify config file instead of using _config.yml --cwd Specify the CWD --debug Display all verbose messages in the terminal --draft Display draft posts --safe Disable all plugins and scripts --silent Hide output on console
    7. For more help, you can use 'hexo help [command]' for the detailed information
    8. or you can check the docs: http://hexo.io/docs/
    9. INFO Start processing
    10. WARN ===============================================================
    11. WARN ========================= ATTENTION! ==========================
    12. WARN ===============================================================
    13. WARN NexT repository is moving here: https://github.com/theme-next
    14. WARN ===============================================================
    15. WARN It's rebase to v6.0.0 and future maintenance will resume there
    16. WARN ===============================================================
    17. INFO Files loaded in 1.14 s
    18. INFO Generated: 2019/06/28/hello-world/index.html
    19. INFO Generated: archives/index.html
    20. ...
    21. INFO Generated: lib/font-awesome/fonts/fontawesome-webfont.svg
    22. INFO 114 files generated in 1.27 s
    23. INFO Start processing
    24. WARN ===============================================================
    25. WARN ========================= ATTENTION! ==========================
    26. WARN ===============================================================
    27. WARN NexT repository is moving here: https://github.com/theme-next
    28. WARN ===============================================================
    29. WARN It's rebase to v6.0.0 and future maintenance will resume there
    30. WARN ===============================================================
    31. INFO Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.

    在这里插入图片描述

    • 利用 Github 搭建
  8. 创建 Github 仓库

    注意:
    Github 仅能使用一个同名仓库的代码托管一个静态站点。
    Github 中仓库名称: 用户名.github.io
    在这里插入图片描述

  9. 创建 index.html

    在这里插入图片描述
    在这里插入图片描述

  10. 配置 SSH Key

    生公钥

    1. [root@node00 ~]# git config --global user.name "charles"
    2. [root@node00 ~]# git config --global user.email "xxx@xxx.com"
    3. [root@node00 ~]# ssh-keygen -t rsa -C 'xxx@xxx.com'
    4. Generating public/private rsa key pair.
    5. Enter file in which to save the key (/root/.ssh/id_rsa):
    6. Enter passphrase (empty for no passphrase):
    7. Enter same passphrase again:
    8. Your identification has been saved in /root/.ssh/id_rsa.
    9. Your public key has been saved in /root/.ssh/id_rsa.pub.
    10. The key fingerprint is:
    11. SHA256:EhMneYuCf6cDv/V/LypXZES0OCMhMbWpvwJr9fV/TqQ xxx@xxx.com
    12. The key's randomart image is:
    13. +---[RSA 2048]----+
    14. | o.=oo oo |
    15. | .+.o + ... |
    16. | . oo .+ +.. |
    17. | . . .o.. . oo |
    18. | . .. S o .|
    19. | o o.o. . .o |
    20. | + *.... oE .|
    21. | *...o.. +..|
    22. | ..o .o+oo ==|
    23. +----[SHA256]-----+
    24. [root@node00 .ssh]# cat id_rsa.pub
    25. ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDMf6GdhyW6n/m5XDeWlyRTVV3u6fe1bmzHBaXcUtDLjYBngLaS4GgLjc8oDCByuZeOudpHktJA+8Y5QOENF6K08cQve2JozkgPi8RGPGG5uEYvDZdC/ZBGJU4cbxlOYKDQ/pzcgxSFC/Tp1IbpZy23U+s9K5M8C1PiLRzXpGiulOILnlwjeiRzD706dyCaS44AeFRwIgPxyGhN4r+jAKDogZY3KOFpwtfSgdgBE+LOZ/wpBeMZbOXMa54Z5G/CtgooaI9ge/mQRb4u64cRKzySTs8p/73s9EM/qaf/SEg4el7y45UaJ0EvzWbtfPG62QBQAQ4O6HWgHUwIM8K1TKCl xxx@xxx.com

    将 id_rsa.pub 的内容复制下面输入的公钥框中
    在这里插入图片描述
    在这里插入图片描述
    验证,如遇到 Permission denied (publickey),请参考 https://blog.csdn.net/weixin_43215250/article/details/90183005

    1. [root@node00 .ssh]# ssh -T git@github.com
    2. Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
  11. 部署到 Github

    _config.yml 配置

    1. .....
    2. # URL
    3. ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    4. url: https://Git-Charles.github.io
    5. root: /
    6. permalink: :year/:month/:day/:title/
    7. permalink_defaults:
    8. ..... # 省略部分内容
    9. # Deployment
    10. ## Docs: https://hexo.io/docs/deployment.html
    11. deploy:
    12. type: git
    13. repo: https://github.com/用户名/用户名.github.io.git
    14. branch: master

    安装自动部署发布工具:

    1. [root@node00 blog]# npm install hexo-deployer-git --save
    2. npm WARN babel-eslint@10.0.2 requires a peer of eslint@>= 4.12.1 but none is installed. You must install peer dependencies yourself.
    3. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    4. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    5. + hexo-deployer-git@1.0.0
    6. added 24 packages from 10 contributors and audited 9166 packages in 11.225s
    7. found 0 vulnerabilities

    发布

    1. [root@node00 blog]# hexo clean && hexo g && hexo d
    2. INFO Deleted database.
    3. INFO Deleted public folder.
    4. INFO Start processing
    5. WARN ===============================================================
    6. WARN ========================= ATTENTION! ==========================
    7. WARN ===============================================================
    8. WARN NexT repository is moving here: https://github.com/theme-next
    9. WARN ===============================================================
    10. WARN It's rebase to v6.0.0 and future maintenance will resume there
    11. WARN ===============================================================
    12. INFO Files loaded in 999 ms
    13. INFO Generated: index.html
    14. ....
    15. INFO Copying files from public folder...
    16. INFO Copying files from extend dirs...
    17. [master a99f33a] Site updated: 2019-06-29 09:46:25
    18. 1 file changed, 1 insertion(+), 1 deletion(-)
    19. Username for 'https://github.com': Git-Charles #输入 github 用户名
    20. Password for 'https://Git-Charles@github.com': #输入 github 密码
    21. Counting objects: 233, done.
    22. Compressing objects: 100% (187/187), done.
    23. Writing objects: 100% (233/233), 1.22 MiB | 205.00 KiB/s, done.
    24. Total 233 (delta 46), reused 0 (delta 0)
    25. remote: Resolving deltas: 100% (46/46), done.
    26. To https://github.com/Git-Charles/Git-Charles.github.io.git
    27. + 4a7fecb...a99f33a HEAD -> master (forced update)
    28. Branch master set up to track remote branch master from https://github.com/Git-Charles/Git-Charles.github.io.git.
    29. INFO Deploy done: git
  12. 访问博客

    输入网址:https://git-charles.github.io/在这里插入图片描述

    • 利用 Github 搭建
  13. 创建 Gitee 仓库
    在这里插入图片描述

  14. 创建 index.html
    在这里插入图片描述
    在这里插入图片描述
  15. 添加 SSH Key

    在这里插入图片描述
    验证

    1. [root@node00 ~]# ssh -T git@gitee.com
    2. Hi xxx! You've successfully authenticated, but GITEE.COM does not provide shell access.
  16. Gitee部署

    在这里插入图片描述
    在这里插入图片描述

  17. 部署到 Gitee

    _config.xml 配置

    1. .....
    2. # URL
    3. ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    4. url: https://lei_charles.gitee.io/blog/
    5. root: /blog/
    6. permalink: :year/:month/:day/:title/
    7. permalink_defaults:
    8. .....
    9. # Deployment
    10. ## Docs: https://hexo.io/docs/deployment.html
    11. deploy:
    12. type: git
    13. repo: https://gitee.com/lei_charles/blog.git
    14. branch: master

    发布

    1. [root@node00 blog]# hexo clean && hexo g && hexo d
    2. INFO Deleted database.
    3. INFO Deleted public folder.
    4. INFO Start processing
    5. WARN ===============================================================
    6. WARN ========================= ATTENTION! ==========================
    7. WARN ===============================================================
    8. WARN NexT repository is moving here: https://github.com/theme-next
    9. WARN ===============================================================
    10. WARN It's rebase to v6.0.0 and future maintenance will resume there
    11. WARN ===============================================================
    12. INFO Files loaded in 997 ms
    13. INFO Generated: index.html
    14. .....
    15. INFO 114 files generated in 1.3 s
    16. INFO Deploying: git
    17. INFO Clearing .deploy_git folder...
    18. INFO Copying files from public folder...
    19. INFO Copying files from extend dirs...
    20. [master 994b011] Site updated: 2019-06-29 10:05:19
    21. 6 files changed, 126 insertions(+), 126 deletions(-)
    22. Username for 'https://gitee.com': lei_charles@163.com
    23. Password for 'https://lei_charles@163.com@gitee.com':
    24. Counting objects: 237, done.
    25. Compressing objects: 100% (190/190), done.
    26. Writing objects: 100% (237/237), 1.22 MiB | 203.00 KiB/s, done.
    27. Total 237 (delta 48), reused 0 (delta 0)
    28. remote: Resolving deltas: 100% (48/48), done.
    29. remote: Powered By Gitee.com
    30. To https://gitee.com/lei_charles/blog.git
    31. + 6d73859...994b011 HEAD -> master (forced update)
    32. Branch master set up to track remote branch master from https://gitee.com/lei_charles/blog.git.
    33. INFO Deploy done: git
  18. 访问博客

    输入网址:https://lei\_charles.gitee.io/blog/

    在这里插入图片描述

    • 配置 404 页面
      在 ~/blog/source 目录下创建 404.html

      layout: false

      title: “404”

      <!DOCTYPE HTML>











    在这里插入图片描述

    • 添加字数统计和阅读时长
  19. 安装插件

    1. npm install hexo-wordcount --save

    查看安装的插件:

    1. hexo --debug
  20. 修改配置
    主题的配置文件

    1. # Post wordcount display settings
    2. # Dependencies: https://github.com/willin/hexo-wordcount
    3. post_wordcount:
    4. item_text: true
    5. # 单篇 字数统计
    6. wordcount: true
    7. # 单篇 阅读时长
    8. min2read: true
    9. # 网站 字数统计
    10. totalcount: true
    11. separated_meta: true

具体其他操作参考 Hexo 官网 : https://hexo.io/zh-cn/docs/

发表评论

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

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

相关阅读