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

  • Hexo 安装部署
  1. 安装 Node.js

    cURL方式:

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

    wget方式:

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

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

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

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

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

    [root@node00 ~]# hexo init ~/blog
    INFO  Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
    Cloning into '/root/blog'...
    remote: Enumerating objects: 9, done.
    remote: Counting objects: 100% (9/9), done.
    remote: Compressing objects: 100% (7/7), done.
    remote: Total 77 (delta 4), reused 5 (delta 2), pack-reused 68
    Unpacking objects: 100% (77/77), done.
    Submodule 'themes/landscape' (https://github.com/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
    Cloning into 'themes/landscape'...
    remote: Enumerating objects: 33, done.
    remote: Counting objects: 100% (33/33), done.
    remote: Compressing objects: 100% (29/29), done.
    remote: Total 929 (delta 12), reused 12 (delta 3), pack-reused 896
    Receiving objects: 100% (929/929), 2.56 MiB | 21.00 KiB/s, done.
    Resolving deltas: 100% (492/492), done.
    Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
    INFO  Install dependencies
    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.
    npm notice created a lockfile as package-lock.json. You should commit this file.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    
    added 340 packages from 498 contributors and audited 6879 packages in 35.061s
    found 0 vulnerabilities
    
    INFO  Start blogging with Hexo!	
    
    [root@node00 ~]# cd blog/
    [root@node00 blog]# npm install
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    
    audited 6879 packages in 4.298s
    found 0 vulnerabilities
    
  5. 生成静态文件

    # 或者使用 hexo g
    [root@node00 blog]# hexo generate
    INFO  Start processing
    INFO  Files loaded in 531 ms
    INFO  Generated: index.html
    INFO  Generated: archives/index.html
    INFO  Generated: fancybox/blank.gif
    INFO  Generated: fancybox/fancybox_loading.gif
    INFO  Generated: fancybox/fancybox_loading@2x.gif
    INFO  Generated: fancybox/fancybox_overlay.png
    INFO  Generated: fancybox/fancybox_sprite@2x.png
    INFO  Generated: archives/2019/06/index.html
    INFO  Generated: js/script.js
    INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.css
    INFO  Generated: fancybox/fancybox_sprite.png
    INFO  Generated: fancybox/jquery.fancybox.css
    INFO  Generated: fancybox/helpers/jquery.fancybox-buttons.js
    INFO  Generated: fancybox/helpers/jquery.fancybox-media.js
    INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.css
    INFO  Generated: fancybox/helpers/jquery.fancybox-thumbs.js
    INFO  Generated: css/style.css
    INFO  Generated: fancybox/jquery.fancybox.js
    INFO  Generated: fancybox/jquery.fancybox.pack.js
    INFO  Generated: archives/2019/index.html
    INFO  Generated: css/fonts/FontAwesome.otf
    INFO  Generated: css/fonts/fontawesome-webfont.svg
    INFO  Generated: css/fonts/fontawesome-webfont.eot
    INFO  Generated: css/fonts/fontawesome-webfont.woff
    INFO  Generated: fancybox/helpers/fancybox_buttons.png
    INFO  Generated: css/images/banner.jpg
    INFO  Generated: css/fonts/fontawesome-webfont.ttf
    INFO  Generated: 2019/06/28/hello-world/index.html
    INFO  28 files generated in 722 ms
    
  6. 启动服务器

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

    在这里插入图片描述

  7. 安装主题

    下载主题到 blog/themes 目录下

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

    修改配置

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

    重新启动

    [root@node00 blog]# hexo && hexo g && hexo s
    Usage: hexo <command>
    
    Commands:
      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.
    Global Options:
      --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
    For more help, you can use 'hexo help [command]' for the detailed information
    or you can check the docs: http://hexo.io/docs/
    INFO  Start processing
    WARN  ===============================================================
    WARN  ========================= ATTENTION! ==========================
    WARN  ===============================================================
    WARN   NexT repository is moving here: https://github.com/theme-next 
    WARN  ===============================================================
    WARN   It's rebase to v6.0.0 and future maintenance will resume there
    WARN  ===============================================================
    INFO  Files loaded in 1.14 s
    INFO  Generated: 2019/06/28/hello-world/index.html
    INFO  Generated: archives/index.html
    ...
    INFO  Generated: lib/font-awesome/fonts/fontawesome-webfont.svg
    INFO  114 files generated in 1.27 s
    INFO  Start processing
    WARN  ===============================================================
    WARN  ========================= ATTENTION! ==========================
    WARN  ===============================================================
    WARN   NexT repository is moving here: https://github.com/theme-next 
    WARN  ===============================================================
    WARN   It's rebase to v6.0.0 and future maintenance will resume there
    WARN  ===============================================================
    INFO  Hexo is running at http://localhost:4000 . Press Ctrl+C to stop.
    

    在这里插入图片描述

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

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

  2. 创建 index.html

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

  3. 配置 SSH Key

    生公钥

    [root@node00 ~]# git config --global user.name "charles"
    [root@node00 ~]# git config --global user.email "xxx@xxx.com"
    [root@node00 ~]# ssh-keygen -t rsa -C 'xxx@xxx.com'
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa): 
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    SHA256:EhMneYuCf6cDv/V/LypXZES0OCMhMbWpvwJr9fV/TqQ xxx@xxx.com
    The key's randomart image is:
    +---[RSA 2048]----+
    |      o.=oo  oo  |
    |      .+.o + ... |
    |   .  oo .+ +..  |
    |  . . .o.. . oo  |
    |   . .. S    o  .|
    |    o o.o.  . .o |
    |     + *.... oE .|
    |      *...o.. +..|
    |     ..o .o+oo ==|
    +----[SHA256]-----+
    [root@node00 .ssh]# cat id_rsa.pub 
    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

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

    _config.yml 配置

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

    安装自动部署发布工具:

    [root@node00 blog]# npm install hexo-deployer-git --save
    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.
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
    
    + hexo-deployer-git@1.0.0
    added 24 packages from 10 contributors and audited 9166 packages in 11.225s
    found 0 vulnerabilities
    

    发布

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

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

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

  2. 创建 index.html
    在这里插入图片描述
    在这里插入图片描述

  3. 添加 SSH Key

    在这里插入图片描述
    验证

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

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

  5. 部署到 Gitee

    _config.xml 配置

    .....	
    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: https://lei_charles.gitee.io/blog/
    root: /blog/
    permalink: :year/:month/:day/:title/
    permalink_defaults:
    
    .....
    
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
      type: git
      repo: https://gitee.com/lei_charles/blog.git 
      branch: master
    

    发布

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

    输入网址:https://lei_charles.gitee.io/blog/

    在这里插入图片描述

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

    layout: false
    title: "404"
    ---
    <!DOCTYPE HTML>
    <html>
    <head>
       <meta http-equiv="content-type" content="text/html;charset=utf-8;">
       <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
       <meta name="robots" content="all">
       <meta name="robots" content="index,follow">
    </head>
    <body>
    <script type="text/javascript" src="//qzonestyle.gtimg.cn/qzone/hybrid/app/404/search_children.js" charset="utf-8" homePageUrl="http://lei_charles.gitee.io/blog/" homePageName="回到我的主页"></script>
    </body>
    </html>
    

    在这里插入图片描述

  • 添加字数统计和阅读时长

  1. 安装插件
    npm install hexo-wordcount --save
    
    查看安装的插件:
    hexo --debug
    
  2. 修改配置
    主题的配置文件
    # Post wordcount display settings
    # Dependencies: https://github.com/willin/hexo-wordcount
    post_wordcount:
      item_text: true
      # 单篇 字数统计
      wordcount: true
      # 单篇 阅读时长
      min2read: true
      # 网站 字数统计
      totalcount: true
      separated_meta: true
    

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

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值