其实相关的教程网上有不少不少,不过就是不少不少,并且技术大神们每一个人都写得不同啊喂,为何我明明就是一步一步按照教程来的仍是有那么多乱七八糟的错?...因此我决定写此篇记录一下我搭建博客的过程以及我踩过的一些坑...但愿给和我同样的技术小白提供一些帮助。而后,感谢给我提供帮助的各位大神(后面会贴出 参考资料)html
不作过多介绍了,快速开始node
依次安装git
一、Node.jsgithub
二、Gitnpm
访问https://github.com/ 右上角signup浏览器
uername 最好都用小写,由于最后创建的博客地址是:http://username.github.io;邮箱十分重要,GitHub 上不少通知都是经过邮箱的。bash
Repository 名字应该是http://username.github.io。好比个人username 就是kkl1210hexo
其余的能够选择添加一些描述也能够选择默认什么也不添加 ,点击creat repositoryssh
开始--全部应用--找到git bash布局
ssh keys就是用来使本地git 项目与github联系
首先要检查本身电脑上现有的 SSH key:
$ cd ~/. ssh
若是显示“No such file or directory”,说明这是你第一次使用 git
$ ssh-keygen -t rsa -C "邮件地址@youremail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/your_user_directory/.ssh/id_rsa):<回车就好>
【提示1】这里的邮箱地址,输入注册 Github 的邮箱地址;
【提示2】「-C」的是大写的「C」
而后系统会要你输入密码:
Enter passphrase (empty for no passphrase):<设置密码>
Enter same passphrase again:<再次输入密码>
在回车中会提示你输入一个密码,这个密码会在你提交项目时使用,若是为空的话提交项目时则不用输入。这个设置是防止别人往你的项目里提交内容。
注意:输入密码的时候没有输入痕迹的,不要觉得什么也没有输入。
最后看到这样的界面,就成功设置ssh key了:
在本地文件夹找到id_rsa.pub文件,看上面的图片第四行的位置告诉你存在哪里了
没找到的勾选一下文件扩展名 隐藏的项目
.ssh文件夹里记事本打开这个文件复制所有内容到
github相应位置。不要着急...(记得期末考试复习几率论看汤家凤老师的视频时老师的口头禅...)
你的github主页
点击头像后边的箭头(为何我每次想要上传头像都没反应呢?但愿有知道的小伙伴能看到告诉我一下)
Title最好写,随便写。网上有说不写title也有可能后期出现乱七八糟的错误
Key部分就是放刚才复制的内容啦 点击Add SSH key
git bash 里
输入如下代码 不要改任何一个字 我就是自做聪明觉得表明的是本身注册时候的邮箱而后...
$ ssh -T git@github.com
若是获得如下反馈
The authenticity of host 'GitHub.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)
输入yes回车
Enter passphrase for key '/c/Users/lenovo/.ssh/id_rsa':
输入刚才设置的密码回车
如今已经能够经过 SSH 连接到 GitHub 啦!固然还须要完善一些我的信息:
$ git config --global user.name "wuyalan"//输入注册时的username
$ git config --global user.email "alan.wyl@foxmail.com"//填写注册邮箱
GitHub 也是用这些信息来作权限的处理,输入下面的代码进行我的信息的设置,把名称和邮箱替换成你本身的,名字必须是你的真名,而不是GitHub的昵称。
本机已成功链接到 github。
若有问题,请从新设置。常见错误请参考:
Connecting to GitHub with SSHError: Permission denied (publickey)
利用npm命令安装hexo
$ cd
$ npm install -g hexo
1. 建立独立博客项目文件夹
安装完成后,关掉前面那个 Git Bash 窗口。在本地建立一个与 Repository 中博客项目同名的文件夹(如E:\http://username.github.io)在文件夹上点击鼠标右键,选择 Git bash here;
【提示】在进行博客搭建工做时,每次使用命令都要在 H:\http://username.github.io 目录下。
执行下面的指令,Hexo 就会自动在 H:\http://username.github.io 文件夹创建独立博客所须要的全部文件啦!
$ hexo init
2. 安装依赖包
$ npm install
3. 确保git部署
$ npm install hexo-deployer-git --save
4.本地查看
如今已经搭建好本地的 Hexo 博客了,执行完下面的命令就能够到浏览器输入 localhost:4000 查看到啦
$ hexo g
$ hexo s
hexo g 每次进行相应改动都要hexo g 生成一下
hexo s 启动服务预览
5. 用Hexo克隆主题
执行完 hexo init 命令后会给一个默认的主题:landscape
你能够到官网找你喜欢的主题进行下载 hexo themes 知乎:有哪些好看的 Hexo 主题?
找到它所在的 Github Repository (怎么找,我喜欢的那个,刚好博主放了他的github地址,emmm)
找到以后经过git命令下载
在主题的repository点击clone 复制一下那个地址
$ git clone +复制的地址+themes/archer
后面就是clone以后放到你本地的博客文件夹themes文件夹下 名字纹archer的文件 我下载的是archer主题~(有喜欢一样的小伙伴在个性化本身主题的时候欢迎来交流一下呀~真的是技术小白~还没研究清楚要怎么改,不过主题做者也会在readme说明的,细心看就是)
6. 修改整站配置文件
本身把 http://blog.io 中文件都点开看一遍,主要配置文件是 _config.yml ,能够用记事本打开,推荐使用 sublime 或者nodepad++打开。
修订清单以下,文档内有详细注释,可按注释逐个修订
blog.io/_posts/2015-03-02-how-to-write.md
这里贴一份网上看到的 能够复制替换原来的 可是替换以前最好备份 可能会出错
那要么你就对照着看一下改就好
# Hexo Configuration
## Docs: http://zespia.tw/hexo/docs/configure.html
## Source: https://github.com/tommy351/hexo/
# Site 这里的配置,哪项配置反映在哪里,能够参考个人博客
title: My Blog #博客名
subtitle: to be continued... #副标题
description: My blog #给搜索引擎看的,对网站的描述,能够自定义
author: Yourname #做者,在博客底部能够看到
email: yourname@yourmail.com #你的联系邮箱
language: zh-CN #中文。若是不填则默认英文
# URL #这项暂不配置,绑定域名后,欲建立sitemap.xml须要配置该项
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://yoursite.com
root: /
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
# Writing 文章布局、写做格式的定义,不修改
new_post_name: :title.md # File name of new posts
default_layout: post
auto_spacing: false # Add spaces between asian characters and western characters
titlecase: false # Transform title into titlecase
max_open_file: 100
filename_case: 0
highlight:
enable: true
backtick_code_block: true
line_number: true
tab_replace:
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Archives 默认值为2,这里都修改成1,相应页面就只会列出标题,而非全文
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1
# Server 不修改
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
logger: false
logger_format:
# 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-M-D
time_format: H:mm:ss
# Pagination 每页显示文章数,能够自定义,贴主设置的是10
## Set per_page to 0 to disable pagination
per_page: 10
pagination_dir: page
# Disqus Disqus插件,咱们会替换成“多说”,不修改
disqus_shortname:
# Extensions 这里配置站点所用主题和插件,暂时默认
## Plugins: https://github.com/tommy351/hexo/wiki/Plugins
## Themes: https://github.com/tommy351/hexo/wiki/Themes
theme: landscape
exclude_generator:
plugins:
- hexo-generator-feed
- hexo-generator-sitemap
# Deployment 站点部署到github要配置
## Docs: http://zespia.tw/hexo/docs/deploy.html
deploy:
type: git
repository:
branch: master
7. 启用新下载的主题
在刚打开的的_config.yml 文件中,找到“# Extensions”,把默认主题 landscape 修改成刚刚下载下来的主题名:
【提示】http://username.github.io 里有两个 config.yml 文件,一个在根目录,一个在 theme 下,如今修改的是在根目录下的。
8. 更新主题
git bash 里执行
$ cd themes/主题名
$ git pull
9. 本地查看调试
每次修改都要hexo g 生成一下
$ hexo g #生成
$ hexo s #启动本地服务,进行文章预览调试,退出服务用Ctrl+c
浏览器输入
localhost:4000 预览效果
进入 Github 我的主页中的 Repository,复制新建的独立博客项目:http://username.github.io 的 SSH 码
打开 H:\username.github.io_config.yml,把刚刚复制的 SSH 码粘贴到“repository:”后面,别忘了冒号后要空一格。
deploy:
type: git
repository: git@github.com:username/username.github.io.git
branch: master
再次确保安装好 hexo-deployer-git
,不然会报 ERROR Deployer not found: git 的错误。
npm install hexo-deployer-git --save
【提示】每次修改本地文件后,须要 hexo g 才能保存。每次使用命令时,都要在你的博客文件夹目录下
$ hexo g
$ hexo d
(ps:我在第一次hexo d 的时候出现了错误,具体错误提示忘了,缘由是我没有deploy 的权限
在repository的setting
(这里我有一点小疑惑 为何delete不了这个公钥呢,我想要delete是由于第一次设置时没有勾选 ..以下
emm里面的内容就是重复配置SSH key的步骤,记得勾选这个小框框,我就是没有勾选设置以后仍是没有deploy成功
)
由于我看到的教程里大多数没有讲这一部分,因此我也不肯定这一步是否必须,若是有遇到相同问题的小伙伴能够参考
)
【提示】若是在配置 SSH key 时设置了密码,执行 hexo d 命令上传文件时须要输入密码进行确认,会出现一个小框框。
输入密码以后提示INFO Deploy done: git表示成功
在浏览器输入:
若是获得你想要的效果,那么恭喜你,博客已经搭建好啦!
容许你偷偷激动一下...哈哈哈