网站首页 文章专栏 将博客从jekyll迁移到hexo
将博客从jekyll迁移到hexo
创建于:2018-11-19 02:00:00 更新于:2024-05-10 21:10:09 羽瀚尘 1045
博客 博客,hexo,jekyll

背景

大概是在2017年年末,当我看到大多数编程相关问题都是在博客中得到解决的,才想到要搭建个人博客。在解决问题的时候想到要分享到博客上,就会格外仔细,面对复杂问题时也会更有勇气。

无奈自己鉴赏水平低下,很多前端页面设计不好,奇丑无比。某天在观摩了朋友的主页后被惊艳到了,原来hexo的next可以这么美。于是就萌生了将博客迁移到hexo的想法。

迁移指南

这里可以找到各种博客系统迁移到hexo的详细步骤。

我原来的博客系统是jekyll,只需要复制粘贴即可。把_posts文件夹内的所有文件复制到source/_posts文件夹,并在_config.yml中修改new_post_name参数。

new_post_name: :year-:month-:day-:title.md

你也可以在new_post_name中加入/用来表示文件夹。

开始

具体怎么迁移呢?首先需要安装hexo及其依赖,我使用的是docker所以没有这个问题。

接着,在根目录运行如下命令

NOTE: 执行hexo init会清除git本地仓库

hexo init 
npm install

一些新文件就生成了,原来的post不会受影响。

一些指南

参考配置完成基本的网站设置。

参看next主题完成主题安装、设置、第三方接入。

在应用指南中碰到的问题

文章访问计数遇坑

以下适用于于选择valine评论系统的情况。

主题配置中可以找到如下内容:

leancloud_visitors:
  enable: false  
  appid:  # your leancloud application appid
  appkey: # your leancloud application appkey
  # Dependencies: https://github.com/theme-next/hexo-leancloud-counter-security
  # If you don't care about security in lc counter and just want to use it directly
  # (without hexo-leancloud-counter-security plugin), set the `security` to `false`.
  security: false 
  betterPerformance: false

但实际上,配置其为 true并不能正常显示文章阅读量。debug之后发现是在前端js执行时没有正确获取appid,修bug可能需要花很长时间。

正确的做法是在comments中将visitor设置为true,整站流量使用不蒜子来统计,见增加全站访问计数一节。配置如下:

valine:
  enable: true # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version.
  appid:   # your leancloud application appid
  appkey:  # your leancloud application appkey
  notify: false # mail notifier , https://github.com/xCss/Valine/wiki
  verify: false # Verification code
  placeholder: 无需注册,说点什么吧 # comment box placeholder
  avatar: mm # gravatar style
  guest_info: nick,mail,link # custom comment header
  pageSize: 10 # pagination size
  visitor: true # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html

增加全站访问计数

主题配置按照如下修改:

busuanzi_count:
  enable: true 
  total_visitors: true
  total_visitors_icon: user
  total_views: true
  total_views_icon: eye
  post_views: false 
  post_views_icon: eye

更多配置

阅读排行

这篇博客中的步骤来即可,无坑。

在线聊天

这篇博客中的步骤来即可,无坑。

文章字数与阅读时间

参考 github,安装npm插件

npm install hexo-symbols-count-time --save
  1. 先在站点配置中做如下更改:

如果没有类似选项,需要自行加上

symbols_count_time:
  symbols: true
  time: true
  total_symbols: true
  total_time: true
  1. 然后在主题配置中做如下修改:
symbols_count_time:
  separated_meta: true
  item_text_post: true
  item_text_total: true 
  awl: 4
  wpm: 275

返回顶部箭头部分的滚动百分比

在这个issue里。

主题配置中做如下修改:

# Scroll percent label in b2t button
scrollpercent: true

增加原创版权声明

在文件 next\_config.yml中,做如下修改:

creative_commons:
  license: by-nc-sa
  sidebar: true
  post: true 

部署

习惯使用jeyll了,对hexo的部署方式有点不太理解。记录如下。

部署流程

网站配置文件中写好自己的git仓库后,就可以运行如下命令将网站部署到github上:

hexo g
hexo d

观察log输出可以看出,首先生成静态文件输出到public文件夹,然后复制到.deploy_git文件夹,接着上传到仓库。即上传到仓库的文件是一个完整的静态网站,这与jekyll有很大区别.

同时部署到github和coding

站点配置_config.yml中的deploy做如下修改即可:

deploy:
  type: git 
  repository:
      github: <your repo address>
      coding: <your repo address> 
  branch: "master" #published
  message: "message"  #leave this blank