0%

重新搭建博客

重新搭建博客,hexo版本太低无法使用。升级过程中重新搭建。

重新搭建博客

版本

hexo: 5.4.0

node: 12.22.1

npm: 7.16.0

重搭步骤

备份simpleai.github.io文件夹

删除simpleai.github.io文件夹内的文件

卸载node.js

安装12.22.1node.js

simpleai.github.io文件夹进入git的bash命令

安装hexo

1
2
3
4
npm install -g hexo-cli
hexo init
npm install
npm install hexo-asset-image --save

测试博客效果

1
hexo server

下载next主题,解压到themes文件夹中,重命名为next

1
2
# next换了地址
https://github.com/theme-next/hexo-theme-next

修改主题

1
2
3
4
5
6
# hexo 的 _config.yml
theme: next

# next 的_config.yml
# scheme: Muse
scheme: Gemini # 修改主题样式

修改hexo首页信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Site
title: Go after
subtitle:
description: 技术融于生活
keywords:
author: 追逐
language: zh-CN # 解决菜单栏乱码 next的_config.yml配置tags后
timezone:

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: http://blog.xiaoruiit.com

index_generator:
path: ''
per_page: 5 # 每一页显示几条
order_by: -date

菜单栏

分类、标签、关于

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ hexo new page categories
$ hexo new page tags
$ hexo new page about
# 修改 source下的各个文件下的index.md文件内容
---
title: categories
date: 2021-06-11 06:53:07
type: "categories" categories文件夹添加本行。其他两个类似
---
# 修改next 下_config.yml
menu:
home: / || fa fa-home
about: /about/ || fa fa-user
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat

搜索

1
npm install hexo-generator-searchdb --save

hexo配置文件<blog_root>/_config.yml添加:

1
2
3
4
5
6
# Configration for Theme-Next
search:
path: search.xml
field: post
format: html
limit: 20

修改hexo-next配置文件 <next_root>/_config.yml

1
2
local_search:
enable: true

底部协议,评论,文字统计和阅读时长,阅读次数统计

协议

1
2
3
4
5
6
# next config.yml
creative_commons:
license: by-nc-sa 4.0
sidebar: true # 开启
post: true # 开启
language:

来必力评论

1
2
# next的config.yml
livere_uid: MTAyMC8******8xMjI0MA==

文字统计和阅读时长

1
npm install hexo-symbols-count-time --save

阅读次数统计

1
2
3
4
5
6
7
# leancloud
# leancloud原应用停用,实名认证+手机号验证+发帖请求解封1天后可用
# next的 config.yml
leancloud_visitors:
enable: true
app_id: S5VAuYJ1Iwl*************-gzGzoHsz
app_key: 4uuo************gWjGat

去除站点统计次数、时间

\themes\next\layout_partials\footer.swig

删除错误统计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{%- if config.symbols_count_time.total_symbols %}
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-chart-area"></i>
</span>
{%- if theme.symbols_count_time.item_text_total %}
<span class="post-meta-item-text">{{ __('symbols_count_time.count_total') + __('symbol.colon') }}</span>
{%- endif %}
<span title="{{ __('symbols_count_time.count_total') }}">{{ symbolsCountTotal(site) }}</span>
{%- endif %}

{%- if config.symbols_count_time.total_time %}
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-coffee"></i>
</span>
{%- if theme.symbols_count_time.item_text_total %}
<span class="post-meta-item-text">{{ __('symbols_count_time.time_total') }} &asymp;</span>
{%- endif %}
<span title="{{ __('symbols_count_time.time_total') }}">{{ symbolsTimeTotal(site, config.symbols_count_time.awl, config.symbols_count_time.wpm, __('symbols_count_time.time_minutes')) }}</span>
{%- endif %}

文章访问次数统计leancloud

  1. 申请账号

  2. 创建应用

  3. 域名绑定(2021.10.1之后不绑定可能不再提供服务)

    1. leancloud配置,配置域名后会检查备案信息,需等待

      image-20210829181327021

    2. 域名解析

      阿里云:

      image-20210829183606728

      leancloud显示

      image-20210829183709552

  4. next的_config.yml 设置

    1
    2
    3
    4
    leancloud_visitors:
    enable: true
    app_id: S5VA*****************zGzoHsz
    app_key: 4u*********************WjGat

打赏

next _config.yml 配置文件

1
2
3
4
5
6
7
8
9
reward_settings:
# If true, reward will be displayed in every article by default.
enable: true
animation: false
#comment: Donate comment here.

reward:
wechatpay: /images/wechatpay.png
alipay: /images/alipay.png

图片放到 /themes/next/source/images 下

hexo部署

建立ssh

1
2
3
4
5
6
7
8
9
ssh-keygen -t rsa -b 4096 -C "simpleintelligence@qq.com" #生成key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa # 将key放到本地电脑
clip < ~/.ssh/id_rsa.pub # 复制ssh key

# 登录 Github 帐号,依次点击自己的头像,Settings,SSH and GPG keys,New SSH key 或者 Add SSH key, 在 Title 这里输入 Key 的label,比如 your_name - PC,然后在 Key 里面把 SSH Key 粘贴进去,点击 Add SSH key 大功告成。

# 测试
ssh -T git@github.com # 输入enter+yes,看到 Hi simpleai! You've successfully authenticated...

source文件夹下添加一个文件CNAME

内容为

1
blog.xiaoruiit.com

安装hexo-deployer-git插件

1
npm install hexo-deployer-git --save

修改_config.yml参数

1
2
3
4
deploy:
type: git
repo: https://github.com/simpleai/simpleai.github.io.git
branch: master

部署报错spawn failed

解决1:刪除博客文件夹下的.deploy_git,重启电脑。重新执行hexo d

解決2:可能是分支代码冲突,参考:https://www.jianshu.com/p/504fdfb31081,未测试。

常用命令

1
2
3
4
5
6
7
8
9
10
11
$ hexo clean # 清除缓存文件 (db.json) 和已生成的静态文件 (public)。 在某些情况(尤其是更换主题后),站点的更改无论如何也不生效
$ hexo generate # 生成静态文件,该命令可以简写为 $ hexo g
$ hexo server # 启动服务器,http://localhost:4000/
$ hexo deploy # 部署网站,推送到github。该命令可以简写为 $ hexo d您可能需要运行该命令

$ hexo init [folder] # 新建一个网站。如果没有设置 folder ,Hexo 默认在目前的文件夹建立网站
$ hexo new [layout] <title> # 新建一篇文章。如果没有设置 layout ,默认使用 _config.yml 中的 default_layout 参数代替
$ hexo render <file1> [file2] ... # 渲染文件
$ hexo list <type> # 列出网站资料
$ hexo publish [layout] # <filename> 发表草稿
$ hexo version # 显示 Hexo 版本