centos7搭建hexo+nods.j个人博客

这里首先提供三个链接地址,当你创建完成博客后,对一个很low的界面会抱怨的,作为一个视觉党,这简直是不能忍受的,所以这里推荐一个有着超级详细的教程的主题,里面有详细的设置。后面的设置都是和主题有关的,小编在这里只是写出来怎么搭建博客,和怎么上传到github上。

hexo的官方地址: https://hexo.io/
github的官方地址:https://github.com/
github-theme-next主题界面https://github.com/iissnan/hexo-theme-next

mkdir /app/blog
# 创建一个单独属于blog的文件夹,名字自己随便
cd /app/blog
wget  https://nodejs.org/dist/v6.11.1/node-v6.11.1-linux-x64.tar.xz
# 从网上下载最新班的node.js软件,这个是必须的环境
tar Jxvf node-v6.11.1-linux-x64.tar.xz
# 解压`node-v6.11.1-linux-x64.tar.xz`文件
mv node-v6.11.1-linux-x64 node
# 修改一下名字名字太长写的麻烦

修改全局变量,加入全局变量文件中

vim /etc/profile
export PATH=$PATH:/app/blog/node/bin
# 这个随便添加到哪里都行,一般我都加到最后
source /etc/profile
# 重新加载环境配置文件
# 创建目录
mkdir hexo
# 切换目录
cd hexo

安装Git(已安装可跳过)

yum install git-core

安装 Hexo

npm install -g hexo-cli
初始化 Hexo
hexo init 初始化安装

假如错误的话,这里提供解决方案

npm install
hexo init(不过这里会提示你文件夹不是空的,所以你需要把原来的文件夹删除,重新创建)

启动hexo

[root@VinnyWang testgithub.io]# hexo server
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.

这里我们不关闭终端,我们直接点击打开链接,一个你将来的博客界面就会出现了,假如失败的话,重头来,最简单的办法,要不然就排错,错误很多,这里就不一一写出来了。

到了这里,我们就是把环境搭建成功了,到时候吧本地的升值同步到github上就好了。但是这里我们先不需要着急,我们刚才生成的只不过是hexo为我们提供的模板网页,里边还是会有很多信息需要修改的,下面我们进入配置文件进行修改,最主要我们修改的地方有两个地方,一个是开头一个是结尾。

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site     # 站点信息
title: Hexo   # 标题
subtitle:   # 副标题
description:  # 站点描述,这个地方会被搜索引擎收录
author: John Doe   #  作者,可以把John Doe改成自己
language:     # 语言类型,看你选择什么主题,里面会有设置的,一般情况下写   zh-CN
timezone:   # 时区  有的主题文件会有需要的

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com  # 网址
root: /  # 根目录,这个地方在你准备同步到网上时候,修改成你的库名字,比如我的是vinnywang.github.io就写这个名字
permalink: :year/:month/:day/:title/ # 文章的链接格式
permalink_defaults: # 默认链接

# Directory
source_dir: source # 源文件生成目录
public_dir: public # 生成网页文件目录
tag_dir: tags # 标签目录
archive_dir: archives # 存档目录
category_dir: categories # 分类目录
code_dir: downloads/code 
i18n_dir: :lang
skip_render:

# Writing
new_post_name: :title.md # File name of new posts # 新标题
default_layout: post # 默认的模板post、page、photo、draft(文章、页面、照片、草稿)
titlecase: false # Transform title into titlecase # 标题是否转换为大写
external_link: true # Open external links in new tab # 新的tab打开页面
filename_case: 0 
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight: # 语法高亮
  enable: true # 是否启用
  line_number: true # 显示行号
  auto_detect: false 
  tab_replace:
  
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date
  
# Category & Tag # 分类标签
default_category: uncategorized # 默认
category_map:
tag_map:
# Archives
2: 开启分页
1: 禁用分页
0: 全部禁用
archive: 2
category: 2
tag: 2

# Date / Time format  # 日期时间格式
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD # 默认设置的格式
time_format: HH:mm:ss 

# Pagination # 分页
## Set per_page to 0 to disable pagination
per_page: 10 # 每页为10篇文章
pagination_dir: page 

# Extensions # 扩展插件
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape # 主题 装机完成之后,默认为landscape

# Deployment # 开发后面部署到github上时会使用到,不要填错了
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type:  git
  repo:git@github.com:mocorochio/micorochio.github.io.git # 这个是填你自己生成的库的链接地址
  branch: master
  message: '站点更新:{{now("YYYY-MM-DD HH/mm/ss")} 

上面的repo可能会有很多人不知道怎么填写,这里给个地址,是红色箭头所指的网址。

image
[root@VinnyWang testgithub.io]# git config --global user.email "20843205@qq.com" 

输入你的email账号,和你注册时候的email相同,不要填错了

[root@VinnyWang testgithub.io]# git config --global user.name "vinnywan"

这里填上你的用户名,和你注册时候的一样哦

[root@VinnyWang testgithub.io]# less  ~/.ssh/id_rsa.pub
/root/.ssh/id_rsa.pub: No such file or directory

这个地方是检查你有没有key文件,有的话略过下边的操作。

[root@VinnyWang testgithub.io]# ssh-keygen -t rsa -C 20843205@qq.com

这个操作是生成key文件,假如你们有的话,需要生成,一路回车就好了。

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
64:a7:2d:64:97:a9:27:51:9d:22:c1:07:a8:74:8d:ac 20843205@qq.com
The key's randomart image is:
+--[ RSA 2048]----+
|     . =oo.. .        |
|    . = +.ooo         |
|   . +  *o=.          |
|    E  = B            |
|        S o           |
|         +            |
|                      |
|                      |
|                      |
+-----------------+
vim /root/.ssh/id_rsa.pub

然后把这个文件上的全部复制出来,等下有用。
现在我们本地的环境已经搭建完成了,但是我们还没有同步到网上,所以这个地方我们需要创建一个github账号,最上面提供的有github的官方网址,点击进去就好了。
创建用户账户就不用我教了吧,按照提示一步一步做下去就好了。但是这里先提前说下,不要乱填,用户名不要起的太奇葩,后面还要用到。这里只是给提供一些创建账号之后的步骤。但你登录github账号之后是这个样子的。

登陆之后界面

我们点击 start a project之后会弹出这个界面

创建库

这个上面我用红色箭头指出来的千万不要乱写,格式是:用户名.github.io写完之后,直接点击最下面的 create repository
创建完成库了,我们需要吧本地的文件同步到github上,但是同步的话,怎么认证呢?这个时候就需要用到,我们之前生成的key文件了。

image

按照顺序点击,反正也点不错。之后还有一个界面。

image

按照顺序填写,记得一定要选择sshkey不要用另外一个。把我们上面生成的key里面的内容复制到中间的空白处,随便给个名字就好了。

好了上面的我们做完了,现在就需要将本地和网络上同步起来

git init 
git add . # 将本地文件添加到缓冲区中
git commit -m "提交文件" # 给想要提交的动作一个名字 引号内部内容随便
git remote add origin https://github.com/vinnywan.github.io
指明你远程的库是什么
git push -u origin master
将缓冲区添加的文件同步到库中,速度看网速了。

这个时候可能会出现一些问题,所以这里提供了两个解决的办法
1.使用强制push的方法:

git push -u origin master -f

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。
2.push前先将远程repository修改pull下来

git pull origin master
git push -u origin maste

这里给些常用的命令:

git add *#跟踪新文件
git rm -f * #强制删除所有文件
git commit#提交更新
git commit -m "注释文本" #添加注释
git commit -a #跳过使用暂存区域,把所有已经跟踪过的文件暂存起来一并提交
git commit --amend #修改最后一次提交
git push origin "resposbilty"
hexo g # 部署
hexo d # 提交

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值