Hexo系列
2019年6月
25
个人博客对我而言是一个记录及分享的地方。
如今网易博客已经关闭,
虽然还有很多其他博客,
但哪里有拥有自己域名的博客来的更帅气呢?
环境要求
安装Hexo及代码提交托管需要以下两个条件,相关安装方式可自行百度
❥ Git
❥ Nodejs
搭建博客的必要条件
搭建博客两个必要条件:(Hexo 安装如上图)
博客框架+托管平台,这里框架我们采用Hexo,而平台大部分人会选择GitHub。这里我选择的是Gitee,属于国内的代码托管平台,相比于GitHub来说,访问速度更快,更稳定。
◆ ◆ ◆ ◆ ◆
Github注册:https://github.com/
Gitee : https://gitee.com/
博客搭建
安装hexo
PS D:\> npm install hexo-cli -g
C:\Users\A2Data\AppData\Roaming\npm\hexo -> C:\Users\A2Data\AppData\Roaming\npm\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":"win32","arch":"x64"})
+ hexo-cli@2.0.0
added 189 packages from 433 contributors in 7.388s
初始化Hexo
PS D:\> hexo init blog
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
Cloning into 'D:\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.
Checking connectivity... 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 | 419.00 KiB/s, done.
Resolving deltas: 100% (492/492), done.
Checking connectivity... done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
[32mINFO [39m 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":"win32","arch":"x64"})
added 343 packages from 499 contributors and audited 6780 packages in 28.382s
found 0 vulnerabilities
INFO Start blogging with Hexo!
获取博客主题
更多主题5G高速直达:https://hexo.io/themes/
PS D:\blog> git clone https://github.com/WeicMa/Hexo-Theme-Life.git themes-life
Cloning into 'themes-life'...
remote: Enumerating objects: 77, done.
remote: Total 77 (delta 0), reused 0 (delta 0), pack-reused 77
Unpacking objects: 100% (77/77), done.
Checking connectivity... done.
一
_config.yml对博客进行基础配置
_config.yml 可称为站点配置文件,可配置博客的名称,地址等基本信息
打开站点配置文件可找到对应的相关配置
◆ ◆ ◆ ◆ ◆
# Site
#博客名称
title: A2Data
#副标题
subtitle: 用行动去诠释一切!
#个人简介
description: 枭馮叔叔,数据分析
keywords:
#博主
author: JackFeng
#语言
language: zh-CN
#时区
timezone: # 默认电脑时间
#主题皮肤
theme: next
本地运行
编译命令:hexo g
启动命令:hexo s
$ hexo gINFO Start processingINFO Files loaded in 170 msINFO Generated: index.htmlINFO Generated: archives/2019/06/index.htmlINFO Generated: 2019/06/24/hello-world/index.htmlINFO Generated: archives/index.htmlINFO Generated: archives/2019/index.htmlINFO 5 files generated in 296 ms$ hexo sINFO Start processingINFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
访问http://localhost:4000/
即可看到博客效果
关于更多Hexo的设置可访问官网:https://hexo.io/zh-cn/docs/
博客部署
访问 https://gitee.com/
,申请注册账号,码云类似国内版的GitHub。
填写项目名称,然后创建项目,创建完成后,在项目中复制项目地址。
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: '这里填写你自己的项目地址'
root: '这里写项目名称'
permalink: :year/:month/:day/:title/
permalink_defaults:
注意:冒号后面一定要有空格,否则不能正确识别。
安装自动部署发布工具:npm install hexo-deployer-git --save
发布命令:hexo clean && hexo g && hexo d
首次发布需要在shell中输入账号和密码。
项目的服务中选择Pages选项
选择 master分支,点击 部署/更新
稍等一会儿博客就发布成功啦,访问博客地址:https://a2data.gitee.io/
,就可以问在线博客啦!!!
如果博客的样式不对,则需要在_config.yml
中配置下博客地址和路径:
url: https://a2data.gitee.io/
root: /
修改完成后,再执行命令hexo clean && hexo g && hexo d
就可更新到Gitee再次发布。
在 Hexo 博客中 出现 LF will be replaced by CRLF 的原因以及它的解决方式。
出现的原因
1. windows中的换行符为 CRLF,而在Linux下的换行符为LF,所以在执行add . 时出现提示
2. CRLF和LF是两种不同的换行格式,git工作区默认为CRLF来作为换行符,
所以当我们项目文件里有用的地方使用LF作为换行符,这个时候我们再继续git add
或者git commit的时候就会弹出警告,
当最终push到远程仓库的时候git会统一格式全部转化为用CRLF作为换行符
解决方式
1. 这个只是一个警告,我们直接忽略就好。git config core.autocrlf false2. git config –global core.autocrlf false //禁用自动转换
◆ ◆ ◆ ◆ ◆
测试本地是没问题。码云上还有点问题。下篇解决。
可以将写好的文章直接放在/Hexo/source/_posts
目录下,即可访问,支持markdown语法。