Hexo blog + spfk theme + LiveRe Comments + Github pages

motivation

New to Blog, feel very fresh, choose a free space to write.

Github is a gathering place for the world's programmer, to write their own code to share with each other to enhance the others, but also upgrade themselves.
Let us talk about the benefits of Github pages serve to build the blog:

  • free
  • free
  • free

Let me say Hexo advantage of:

  • Generate pure static pages, access speed
  • No database, easy migration
  • free

Comments on selected systems LiveRe:

  • Gangster level disqus comment system in the wall (silence for a while), you need to vpn
  • Say, NetEase has been lying cloud
  • Sohu Chatteris required domain name for the record, how could I have a free domain name, it is simply ignored
  • Native comment system? ? ? hexo no database, how to get. . .
  • gitment is github, and did not understand
  • Friends of the words, not on the landing

Looks around, LiveRe still available, although more bug, poor network connection. We love toss, you will find better.

Install Git Bash

I have a windows environment, so download windows version and install it.

  • download link
  • Download exe, after opening all the way to the next just fine
  • After installation, open gitbash

  • Can not find gitbash junior partner, the space will be able to see right

  • Git or find the folder in all programs

  • View the currently installed version
git version

Installation NodeJs

Hexo is based on a static blog nodeJS environment, inside npm useful tool ah, so honestly this stuff installed it

  • Download (Description: LTS for long-term support version, Current is the current latest version)
  • Installation steps: After downloading anyway, good msi file, double-click to open the installation, but also all the way next, but remember that this step is selected in the Setup Custom Add to PATH, so you do not have to go on the computer to configure the environment variables, and Bahrain in the press win + rthe shortcut key to bring up the run, then enter cmd OK, enter the path you can see the node is configured on the inside (environment variable), do not ask their own degree of your mother, right in cmd.
node -v

Installation hexo

After installing the software above two, behind the things we do not need to manually download their own, because with gitbash in npm tools to complete.

  • 首先需要找个地方来存放你的blog,在电脑的某个地方创建文件夹。
  • 在gitbash中用cd进入该文件中,并执行命令,默认安装在c盘下,想修改安装路径的小伙伴,请自行百度。
npm i -g hexo
  • 安装后查看版本,命令:
hexo -v

  • 随后我们进行blog的初始化,命令:
hexo init

  • 说明一下各个文件的作用:
    • node_modules:是依赖包
    • public:存放的是生成的页面
    • scaffolds:命令生成文章等的模板
    • source:用命令创建的各种文章
    • themes:主题
    • _config.yml:整个博客的配置
    • db.json:source解析所得到的
    • package.json:项目所需模块项目的配置信息
  • 到这一步,架子算是搭好了,剩下的就是一些个性化的配置了

搭桥到github

把创建好的blog项目部署到github上并用github page

  • 首先需要有github账号,如果没有,请自行百度,注册很简单。
  • 有了账号,并登陆后创建一个repo,名称为yourname.github.io,其中yourname是你github的名称,操作如下:

  • 点击Create repository即可
  • 回到gitbash中,配置github账户信息(YourNameYourEmail填写你们自己的)
git config --global user.name "YourName"
git config --global user.email "YourEmail"
  • 创建ssh
  • 在gitbash中输入以下命令,需要输入密码,生成ssh密钥。然后进入C:\Users\用户名.ssh,进入此文件夹,找到id_rsa.pub文件,查看里面的内容
ssh-keygen -t rsa -C "youremail"
  • 登陆github:


  • 点击New SSH key

  • title随便起,key值填入id_rsa.pub文件内的内容,点击Add SSH key即可
  • 在gitbash中校验是否添加成功,命令:
ssh -T [email protected]

把blog关联到github中

  • 打开blog项目,修改_config.yml文件中的一些配置,在文档字下面添加下面的代码,冒号后面有一个英文的空格,
deploy:
    type: git
    repo: [email protected]:YourgithubName/YourgithubName.github.io.git
    branch: master
  • 回到gitbash中,进入你的本地blog目录,执行下面命令:
hexo clean
hexo g
hexo s

注:hexo 3.0把服务器独立成个别模块,需要单独安装:

npm i hexo-server
  • 打开浏览器,输入:http://localhost:4000
  • 你就可以看到hexo自带主题的页面了

部署到github

  • 先安装插件,只有安装这个,才能部署到github中
npm install hexo-deployer-git --save
  • 执行命令:
hexo clean
hexo g
hexo s

hexo d的时候,会让输入生成ssh时候输入的密码。

  • 部署成功后,访问http://yourgithubname.github.io,就可以看见了

修改主题为spfk

  • hexo默认的是主题是landscape,我用的是spfk的主题。
  • 在gitbash中进入你的blog所在的文件夹,输入以下命令
git clone https://github.com/luuman/hexo-theme-spfk.git themes/spfk
  • 下载完成后,修改blog下的_confing.yml文件,将theme属性修改成spfk,改成其他主题,操作类似
  • 如果主题需要更新的话,在gitbash中,进入主题所在文件夹,在blog\themes中,名字对应的文件
git pull
  • 更换完后,重新加载和部署即可

添加LiveRe评论系统

  • 首先进入LiveRe
  • 进行注册,注册完成
  • 点击安装,选择City版,喜欢付费的小伙伴,可以选择Premium版,点击现在安装
  • 根据自身的需求进行一些设置
  • 绑定网址,生成代码
  • 在管理界面左侧找到代码管理,把一般网站里的代码粘贴出来,命名为livere.ejs
  • 放到blog\themes\spfk\layout\_partial\comments

  • 由于spfk主题下没有LiveRe评论系统的,所以要手动进行添加
  • 打开文件hexo\themes\spfk\layout\_partial下的article.ejs文件

  • 找到if (!index && post.comments){这里添加以下代码
<%  if (theme.livere.on) { %>
    <%- partial('comments/livere') %>
<% } %>

  • 打开spfk主题配置文件hexo\themes\spfk下的_config.yml添加以下代码,Yourid的值时LiveRe代码中的data-uid的值
livere:
    on: true
    livere_uid: Yourid

  • 由于主题中还有其他的评论系统,把其他评论系统全部注释掉即可

最后

  • 执行编译和部署命令,将整合过后的项目部署到github上
  • 自己的小博客大功告成

打完收工

Guess you like

Origin www.cnblogs.com/snmlm/p/11598261.html