hexo常用命令

hexo

1
2
3
npm install hexo -g #安装  
npm update hexo -g #升级
hexo init #初始化

简写

1
2
3
4
5
hexo n "我的博客" == hexo new "我的博客" #新建文章
hexo p == hexo publish
hexo g == hexo generate#生成
hexo s == hexo server #启动服务预览
hexo d == hexo deploy#部署

服务器

1
2
3
4
5
6
7
8
hexo server #Hexo 会监视文件变动并自动更新,您无须重启服务器。
hexo server -s #静态模式
hexo server -p 5000 #更改端口
hexo server -i 192.168.1.1 #自定义 IP

hexo clean #清除缓存 网页正常情况下可以忽略此条命令
hexo g #生成静态网页
hexo d #开始部署

监视文件变动

1
2
hexo generate #使用 Hexo 生成静态文件快速而且简单
hexo generate --watch #监视文件变动

完成后部署

两个命令的作用是相同的

1
2
3
4
5
hexo generate --deploy
hexo deploy --generate

hexo deploy -g
hexo server -g

草稿

1
hexo publish [layout] <title>

模版

1
2
3
4
5
6
7
8
9
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub

hexo new [layout] <title>
hexo new photo "My Gallery"
hexo new "Hello World" --lang tw
变量描述
layout描述
title标题
date文件建立日期
1
2
3
4
5
6
7
8
title: 使用Hexo搭建个人博客
layout: post
date: 2014-03-03 19:07:43
comments: true
categories: Blog
tags: [Hexo]
keywords: Hexo, Blog
description: 生命在于折腾,又把博客折腾到Hexo了。给Hexo点赞。

模版(Scaffold)

hexo new photo “My Gallery”

变量描述
layout布局
title标题
date文件建立日期

设置文章摘要

1
以上是文章摘要 <!--more--> 以下是余下全文 

写作

hexo new page

<br>hexo new post<title><p></p><table><thead><tr><th>变量</th><th>描述</th></tr></thead><tbody><tr><td>:title</td><td>标题</td></tr><tr><td>:year</td><td>建立的年份(4 位数)</td></tr><tr><td>:month</td><td>建立的月份(2 位数)</td></tr><tr><td>:i_month</td><td>建立的月份(去掉开头的零)</td></tr><tr><td>:day</td><td>建立的日期(2 位数)</td></tr><tr><td>:i_day</td><td>建立的日期(去掉开头的零)</td></tr></tbody></table><h2 id="推送到服务器上"><a class="markdownIt-Anchor" href="#推送到服务器上"></a> 推送到服务器上</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">hexo n #写文章</span><br><span class="line">hexo g #生成</span><br><span class="line">hexo d #部署 #可与hexo g合并为 hexo d -g</span><br></pre></td></tr></table></figure><h2 id="报错"><a class="markdownIt-Anchor" href="#报错"></a> 报错</h2><p>1.找不到git部署</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ERROR Deployer not found: git</span><br></pre></td></tr></table></figure><h2 id="解决方法"><a class="markdownIt-Anchor" href="#解决方法"></a> 解决方法</h2><p>npm install hexo-deployer-git --save</p><p>3.部署类型设置git<br>hexo 3.0 部署类型不再是github,_config.yml 中修改</p><h1 id="deployment"><a class="markdownIt-Anchor" href="#deployment"></a> Deployment</h1><h2 id="docs-httphexoiodocsdeploymenthtml"><a class="markdownIt-Anchor" href="#docs-httphexoiodocsdeploymenthtml"></a> Docs: <a target="_blank" rel="noopener" href="http://hexo.io/docs/deployment.html">http://hexo.io/docs/deployment.html</a></h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">deploy:</span><br><span class="line"> type: git</span><br><span class="line"> repository: git@***.github.com:***/***.github.io.git</span><br><span class="line"> branch: master</span><br></pre></td></tr></table></figure><ol start="4"><li>xcodebuild<br>xcode-select: error: tool ‘xcodebuild’ requires Xcode, but active developer directory ‘/Library/Developer/CommandLineTools’ is a command line tools instance</li></ol><p>npm install bcrypt</p><ol start="5"><li>RSS不显示</li></ol><p>安装RSS插件</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install hexo-generator-feed --save</span><br></pre></td></tr></table></figure><h3 id="开启rss功能"><a class="markdownIt-Anchor" href="#开启rss功能"></a> 开启RSS功能</h3><p>编辑hexo/_config.yml,添加如下代码:</p><p>rss: /atom.xml #rss地址 默认即可</p><h2 id="开启评论"><a class="markdownIt-Anchor" href="#开启评论"></a> 开启评论</h2><p>1.我使用多说代替自带的评论,在多说 网站注册 > 后台管理 > 添加新站点 > 工具 === 复制通用代码 里面有 short_name</p><ol><li><p>在根目录 _config.yml 添加一行 disqus_shortname: jslite 是在多说注册时产生的</p></li><li><p>复制到 themes\landscape\layout_partial\article.ejs<br>把</p></li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><% if (!index && post.comments && config.disqus_shortname){ %></span><br><span class="line"><section id="comments"></span><br><span class="line"><div id="disqus_thread"></span><br><span class="line"> <noscript>Please enable JavaScript to view the <a href="//disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript></span><br><span class="line"></div></span><br><span class="line"></section></span><br><span class="line"></span><br><span class="line"><% } %></span><br></pre></td></tr></table></figure><p>改为</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><% if (!index && post.comments && config.disqus_shortname){ %></span><br><span class="line"> <section id="comments"></span><br><span class="line"> <!-- 多说评论框 start --></span><br><span class="line"> <div class="ds-thread" data-thread-key="<%= post.layout %>-<%= post.slug %>" data-title="<%= post.title %>" data-url="<%= page.permalink %>"></div></span><br><span class="line"> <!-- 多说评论框 end --></span><br><span class="line"> <!-- 多说公共JS代码 start (一个网页只需插入一次) --></span><br><span class="line"> <script type="text/javascript"></span><br><span class="line"> var duoshuoQuery = {short_name:'<%= config.disqus_shortname %>'};</span><br><span class="line"> (function() {</span><br><span class="line"> var ds = document.createElement('script');</span><br><span class="line"> ds.type = 'text/javascript';ds.async = true;</span><br><span class="line"> ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';</span><br><span class="line"> ds.charset = 'UTF-8';</span><br><span class="line"> (document.getElementsByTagName('head')[0] </span><br><span class="line"> || document.getElementsByTagName('body')[0]).appendChild(ds);</span><br><span class="line"> })();</span><br><span class="line"> </script></span><br><span class="line"> <!-- 多说公共JS代码 end --></span><br><span class="line"> </section></span><br><span class="line"><% } %></span><br></pre></td></tr></table></figure>