Ubuntu下github pages+hexo搭建自己的博客

hexo 是一个基于Node.js的静态博客程序,可以方便的生成静态网页托管在github上.Hexo简单优雅, 而且风格多变, 适合搭建个人博客,而且支持多平台的搭建.
平台
Ubuntu14.04

安装hexo

安装node.js

使用nvm安装node.js:
cURL:

curl https://raw.github.com/creationix/nvm/master/install.sh | sh

Wget:

wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

安装完后,用nvm安装node.js.

nvm install 4

安装hexo

npm install -g hexo-cli

开始写博客

建立博客

$mkdir ~/blog
$hexo init ~/blog #初始化博客
$cd ~/blog
$hexo generate     #生成博客
$hexo server   #运行本地服务

在浏览器输入http://localhost:4000就可以看到效果.

写文章

配置完后,就可以写markdown文章了,进入博客目录,

$hexo new "postname"   #文章名字是postname

博文会自动生成在博客目录下source/_posts/postName.md

#文件自动生成格式:
title: "It Starts with iGaze: Visual Attention Driven Networkingwith Smart Glasses"  #博文题目
date: 2014-11-21 11:25:38      #生成时间
tags: Paper                    #标签, 多个标签使用格式[Paper1, Paper2, Paper3,...]
---

如果不想博文在首页全部显示, 并能出现阅读全文按钮效果, 需要在你想在首页显示的部分下添加

将博客托管在github上

生成github ssh公钥

1.检查是否已安装ssh,如果没有则安装
2.检查是否存在ssh公钥.

$cd ~/.ssh

3.生成ssh公钥

$ ssh-keygen -t rsa -C "your_email@youremail.com" 

生成了~/.ssh目录.
输入github密码

Enter passphrase (empty for no passphrase): [Type a passphrase] 
Enter same passphrase again: [Type passphrase again]
Your identification has been saved in /home/you/.ssh/id_rsa. 
# Your public key has been saved in /home/you/.ssh/id_rsa.pub.
# The key fingerprint is: ...

4.将公钥添加到github
打开github,找到账户里面添加SSH,把~/.ssh/idrsa.pub的内容复制到key里面。
5.测试是否生效
使用下面的命令测试

$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

Hi username! 
You've successfully authenticated, but GitHub does not provide shell access.

成功.

将博客部署到github

1.安装部署到git的插件:

npm install hexo-deployer-git --save

2.修改~/blog/_config.yml文件:

# Deployment  
## Docs: http://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: git@github.com:goodluckcwl/goodluckcwl.github.io.git  
  branch: master   #部署分支,一般使用master主分支

执行:

$hexo deploy

打开你的github个人博客.

修改主题

在hexo官网下载主题,修改~/blog/_config.yml文件.


数学公式显示

数学公式显示使用Mathjax引擎,可以下载插件hexo-math.

公式显示错误

Markdown 里使用 Mathjax 有一个很大的缺点,会把两个_按照Markdown的语法解释.
该冲突主要是由于对 \ 和 _ 的转义造成的。找到 marked.js脚本文件, 通常在:/blog/node_modules/hexo-renderer-marked/node_modules/marked/lib/markd.js,先复制一份保存,再修改:

escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,

改为

escape: /^\\([`*\[\]()#+\-.!_>])/,

再将

return '<em>' + text + '</em>';

改为:

return '_' + text + '_';

取消markdown转义,这样数学公式就显示正确了.

Markdown编辑器

haroopad

转载于:https://www.cnblogs.com/goodluckcwl/p/5686093.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值