之前一直都是把一些东西记到有道云笔记里面,这几天心血来潮,想把笔记什么的都记录到博客里面,于是就遇上了hexo~~说实话,hexo也是挺方便的,写完就发布,而且样式挺好看的,最主要的还是免费,免费,免费~哈哈哈~打算把有道云部分笔记也移到这里来,方便查找和分享
注册Github账号
首先你得有一个github的账号,大家可自行到github官网去注册,注册成功之后登录github,新建一个代码仓库
安装node.js
作用:用来生成静态页面的
安装git
作用:把本地的hexo内容提交到github上去
安装配置hexo
- 创建一个目录用于存放hexo相关文件
mkdir blog
- 进入blog目录执行
npm install -g hexo
- 初始化hexo
hexo init
,至此,全部安装工作已经完成!blog就是你的博客根目录,所有的操作都在里面进行 - 新建一篇文章
hexo new "title"
,hexo会帮我们在_posts下生成相关md文件,当然你也可以直接自己新建md文件,用这个命令的好处是帮我们自动生成了时间 - 生成静态页面至public目录
hexo generate
或hexo g
- 开启预览访问端口(默认端口4000,’ctrl + c’关闭server)即可本地浏览内容啦~
hexo server
或hexo s
- 部署到Github
hexo deploy
或hexo d
到此为止,已经部署完毕,试试访问yourname.github.io看看你的博客吧~ (yourname是你github的用户名)
你还可以使用组合命令快速部署到Github:
hexo s -g
生成并本地预览hexo d -g
生成并上传
小技巧
hexo s -g
生成并本地预览hexo d -g
生成并上传- markdown默认情况下,生成的博文目录会显示全部的文章内容,可以在合适的位置加上
<!--more-->
不显示全部内容
配置文件
- 配置文件位于blog目录下面的_config.yml,我们只需要改几项常用的配置即可
1 | # 网站相关信息 |
更新于20170320
主题推荐及使用
- 本博客使用的是yilia主题,Yilia 是为 hexo 2.4+制作的主题。 崇尚简约优雅,以及极致的性能。
- 使用
git clone https://github.com/litten/hexo-theme-yilia.git themes/yilia
- 修改hexo根目录下的 _config.yml :
theme: yilia
- 更新
cd themes/yilia
git pull
- 配置
- 可参考主题作者的博客备份
添加多说评论
_config.yml中添加多说的配置(注意:_config.yml在根目录和主题根目录都会存在,主题目录下的文件信息将会覆盖根目录的文件信息)
1
2duoshuo: 你站点的short_name
duoshuo_shortname: 你站点的short_name修改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
21<% 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>
<% } %>