注册github
创建仓库
settings -> Repositories
输入名称 EugeniaWu.github.io //注意格式,要与github用户相同
本地本地新建项目路径
按照命令初始化,
1 2 3 4 5 6
| $ echo "# eugeniawu.github.io" >> README.md $ git init $ git add README.md $ git commit -m "first commit" $ git remote add origin git@github.com:EugeniaWu/eugeniawu.github.io.git $ git push -u origin master
|
提示
Permanently added the RSA host key for IP address ‘192.30.253.112’ to the list of known hosts.
Permission denied (publickey).
1
| $ sudo ssh-keygen -t rsa -C "xxx@xxx.com" //注册github邮箱
|
Enter passphrase (empty for no passphrase): //输入密码
Enter same passphrase again: //输入密码
1
| $ pbcopy < ~/.ssh/id_rsa.pub //通过命令复制生成的ssh key
|
通过settings -> SSH and GPG keys
new SSH key
粘贴ssh key
再次提交
1
| $ git push origin master
|
使用hexo创建blog
Hexo 是一个简单地、轻量地、基于Node的一个静态博客框架,可以方便的生成静态网页托管在github和Heroku上.
在myGithub目录下,执行命令安装Hexo
1
| $ sudo npm install -g hexo
|
初始化hexo
1 2 3
| $ hexo generate $ hexo server
|
配置发布github
//修改配置文件需要重新执行命令查看,下面是简写形式
1
| hexo clean && hexo g && hexo s
|
增加评论功能
将最底部的deploy配置修改:
1 2 3 4 5
| deploy: type: git repo: https://[github账户名]:[密码]@github.com/EugeniaWu/eugeniawu.github.io.git branch: master
|
然后执行命令
1
| $ npm install hexo-deployer-git --save
|
通过命令,将静态网页提交到github
1 2 3
| $ hexo clean $ hexo generate $ hexo deploy
|
一些常用命令:
1 2
| $ hexo new "postName" $ hexo new page "pageName"
|
文章内容采用markdown格式。
注意:
[remote rejected] HEAD -> master (cannot lock ref ‘refs/heads/master’
解决
fetch 改变的是 remotes 里面相应分支的 commit id。
git fetch 并没更改本地仓库的代码,git pull会更改,拉下来并merge
//使用duoshuo做评论
注册多说帐号 http://duoshuo.com/
主题是landscape
1
| $ vim themes/landscape/layout/_partial/article.ejs
|
找到下面代码
1 2 3 4 5 6 7
| <% if (!index && post.comments && config.disqus_shortname){ %> <section id="comments"> <div id="disqus_thread"> <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> </div> </section> <% } %>
|
替换成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <% if (!index && post.comments && config.duoshuo_shortname){ %> <section id="comments"> <!-- 多说评论框 start --> <div class="ds-thread" data-thread-key="<%= post.layout %>-<%= post.slug %>" data-title="<%= post.title %>" data-url="<%= page.permalink %>"></div> <!-- 多说评论框 end --> <!-- 多说公共JS代码 start (一个网页只需插入一次) --> <script type="text/javascript"> var duoshuoQuery = {short_name:'<%= config.duoshuo_shortname %>'}; (function() { var ds = document.createElement('script'); ds.type = 'text/javascript';ds.async = true; ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js'; ds.charset = 'UTF-8'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ds); })(); </script> <!-- 多说公共JS代码 end --> </section> <% } %>
|
到根目录myGithub
在文件底部新增
duoshuo_shortname: eugeniawu //刚刚注册duoshuo的域名
注意
Port 4000 has been used. Try other port instead.
1 2
| $ lsof -i:4000 $ kill -9 [PID] //PID填入值
|