如何从零搭建hexo个人博客网站

https://www.jianshu.com/p/adf65cbad393?utm_source=oschina-app

 

准备工作

  • github账号
  • node.js 环境搭建
  • git使用
  • markdown语法

环境搭建

本地环境: win10
node -v
# v8.11.1
npm -v
# 5.6.0
hexo -v
# hexo: 3.7.1
# hexo-cli: 1.1.0
git --version
# git version 2.18.0.windows.1

 

 

nodejs,git安装过程及github.io的创建参考其他文章,git需要配置到如下输出可正常使用

ssh -T git@github.com
> Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

hexo安装使用

  1. 切换淘宝源
    npm config set registry https://registry.npm.taobao.org
  2. 安装使用hexo-cil
npm install -g hexo-cli
hexo init <folder>
cd <folder>
npm install
hexo g
hexo s
# 浏览器输入localhost:4000 ,可看到最初的hexo网站
# 此处命令可使用git-bash。exe 输入

 

  1. 安装部署到github.io的依赖
    npm install –save hexo-deployer-git
  2. 修改配置文件部署到github.io
#修改项目下的_config.yml文件
deploy:
type: git
repo: git@github.com:diaoyongbao/diaoyongbao.github.io.git #修改成自己的项目地址
branch: master

 

  1. 部署项目,访问项目地址
    hexo deploy

next安装使用

  1. 安装
cd your-hexo-site
git clone https://github.com/iissnan/hexo-theme-next themes/next
  1. 修改项目的配置文件启用
    theme: next

开启更多功能

官方网站上已经记录了很多功能,下面记录几个没有的

  1. 自动更换背景图片
# 配置文件 themes
extsourcecss _customcustom.styl
body {
background:url(https://source.unsplash.com/random/1600x900);
background-repeat: no-repeat;
background-attachment:fixed;
background-position:50% 50%;
#repeat:是否重复出现
#attachment:定义背景图片随滚动轴的移动方式
#position:设置背景图像的起始位置
}

 

 

  1. 字数统计
# 配置文件:themes/_config.yml
post_wordcount:
item_text: true
wordcount: true
min2read: true
totalcount: false
separated_meta: true

 

 

  1. 添加社交图标
# 配置文件:themes/_config.yml
social:
GitHub: https://github.com/diaoyongbao || github
E-Mail: mailto:dyb6884@gmail.com || envelope

 

 

  1. 点击爱心效果
    浏览器输入:http://7u2ss1.com1.z0.glb.clouddn.com/love.js
    拷贝所有代码,在/themes/next/source/js/src里面新建love.js,然后在/themes/next/layou/_layout.swig文件末尾添加以下代码:
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>

 

 

下载链接及参考文章

原文地址:https://www.cnblogs.com/brady-wang/p/11303490.html