hexo+gitee
<div class="postTitle"><h1>hexo+gitee</h1>
</div>
<div id="cnblogs_post_body" class="blogpost-body cnblogs-markdown">
<div class="toc">
<div class="toc-container-header">目录</div>
<ul>
<li>Hexo安装
<ul>
<li>安装Nodejs</li>
<li>安装Git</li>
<li>安装Hexo</li>
<li>基本命令与文件目录</li>
</ul>
</li>
<li>发布到Gitee
<ul>
<li>Gitee配置信息</li>
<li>配置SSH公钥</li>
<li>安装deploy</li>
<li>提交md文件</li>
<li>配置Gitee Pages</li>
</ul>
</li>
<li>其他配置
<ul>
<li>配置主题</li>
<li>本地图片调用</li>
<li>安装站点地图插件</li>
<li>feed插件</li>
<li>wordcount问题</li>
<li>配置搜索功能</li>
</ul>
</li>
</ul>
</div>
<h2 id="hexo安装">Hexo安装</h2>
<h3 id="安装nodejs">安装Nodejs</h3>
<p>下载地址按操作系统选择,选择带LTS长期支持的版本,点击一步安装即可</p>
<h3 id="安装git">安装Git</h3>
<p>下载地址选择windows版本,linux系统使用yum安装</p>
<h3 id="安装hexo">安装Hexo</h3>
<p>按下win+r,输入cmd,</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment"># 创建blog目录
mkdir blog && cd blog
<span class="hljs-comment"># 检查npm nodejs
<span class="hljs-comment">#npm是nodejs的下载工具,国内网速慢,建议使用cnpm
npm -v
<span class="hljs-comment">#6.13.4
node -v
<span class="hljs-comment">#v12.14.0
<span class="hljs-comment">#安装并使用cnmp以提高速度
npm install -g cnpm --registry=https://registry.npm.taobao.org
<span class="hljs-comment">#安装hexo
cnpm install -g hexo-cli
<span class="hljs-comment">#验证hexo
hexo -v
<span class="hljs-comment">#以下为返回值,说明成功安装hexo
<span class="hljs-comment">#hexo: 4.2.0
<span class="hljs-comment">#hexo-cli: 3.1.0
<span class="hljs-comment">#os: Windows_NT 10.0.17763 win32 x64
<span class="hljs-comment">#node: 12.14.0
<span class="hljs-comment">#v8: 7.7.299.13-node.16
<span class="hljs-comment">#uv: 1.33.1
<span class="hljs-comment">#zlib: 1.2.11
<span class="hljs-comment">#brotli: 1.0.7
<span class="hljs-comment">#ares: 1.15.0
<span class="hljs-comment">#modules: 72
<span class="hljs-comment">#nghttp2: 1.39.2
<span class="hljs-comment">#napi: 5
<span class="hljs-comment">#llhttp: 1.1.4
<span class="hljs-comment">#http_parser: 2.8.0
<span class="hljs-comment">#openssl: 1.1.1d
<span class="hljs-comment">#cldr: 35.1
<span class="hljs-comment">#icu: 64.2
<span class="hljs-comment">#tz: 2019c
<span class="hljs-comment">#unicode: 12.1
<span class="hljs-comment">#初始化blog
hexo init
</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h3 id="基本命令与文件目录">基本命令与文件目录</h3>
<pre><code class="language-powershell hljs">hexo clean <span class="hljs-comment">#清理缓存文件
hexo g <span class="hljs-comment">#生成文件
hexo s <span class="hljs-comment">#运行本地服务器
hexo d <span class="hljs-comment">#上传到服务器
hexo new <span class="hljs-string">"name" <span class="hljs-comment">#新建文章
hexo new page <span class="hljs-string">"pagename" <span class="hljs-comment">#新建页面
hexo help <span class="hljs-comment">#查看帮助
hexo version <span class="hljs-comment">#查看版本信息
hexo deploy -g <span class="hljs-comment">#生成加部署
hexo server -g <span class="hljs-comment">#生成加预览
hexo n = hexo new
hexo g = hexo generate
hexo s = hexo server
hexo d = hexo deploy
hexo clean && hexo generate && hexo deploy
</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<pre><code class="language-powershell hljs"><DIR> .deploy_git
<span class="hljs-number">31,<span class="hljs-number">108 db.json
<DIR> node_modules <span class="hljs-comment">#为Hexo的插件目录,利用插件生成静态HTML文件
<span class="hljs-number">160,<span class="hljs-number">185 package-lock.json
<span class="hljs-number">726 package.json
<DIR> public
<DIR> scaffolds <span class="hljs-comment">#模板文件。可以添加模板使用
<DIR> source <span class="hljs-comment">#存放.md文件和图片资源
<DIR> themes <span class="hljs-comment">#存放主题目录
<span class="hljs-number">2,<span class="hljs-number">720 _config.yml <span class="hljs-comment">#全局配置文件
</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<p>启动Hexo,并在浏览器中打开</p>
<p>提示:在要已经创建好的blog目录下启动</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#启动服务
hexo s
<span class="hljs-comment">#使用powershell,打印输出
<span class="hljs-comment">#注意,使用完全powershell要退出,否则后面执行命令可能会出现错误,这里仅仅是为了显示web信息
curl http://localhost:<span class="hljs-number">4000
<span class="hljs-comment">#StatusCode : 200
<span class="hljs-comment">#StatusDescription : OK
<span class="hljs-comment">#Content : <!DOCTYPE html><html lang="zh_CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">...
<span class="hljs-comment">#...
</span></span></span></span></span></span></span></span></code></pre>
<h2 id="发布到gitee">发布到Gitee</h2>
<h3 id="gitee配置信息">Gitee配置信息</h3>
<p>创建Gitee个人用户,进入个人主页,在头像左侧,鼠标移动到加号上,显示出新建仓库,点击</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#仓库名称
blog
<span class="hljs-comment">#路径,注意:路径必须与你的用户名称相同,否则会创建博客失败
your_Gitee_name
<span class="hljs-comment">#是否开源
公开
<span class="hljs-comment">#点击创建
</span></span></span></span></code></pre>
<h3 id="配置ssh公钥">配置SSH公钥</h3>
<p>也可以通过用户名和密码,为减少每次提交都要手动输入,建议使用密钥</p>
<p>在blog目录下,鼠标右键 Git Bash Here,等待一个小黑窗口的出现</p>
<p>生成和添加公钥 ,查看公钥配置帮助信息</p>
<p>参考上以链接进行配置,以下是个人配置</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment"># 生成密钥对
ssh-keygen -t rsa -C <span class="hljs-string">"gaoanyu@gitee.com"
<span class="hljs-comment"># 查看公钥 ,需将路径修改为实际路径
cat ~/.ssh/id_rsa.pub
</span></span></span></code></pre>
<p>点击进入SSH公钥配置,打开配置界面,将公钥内容</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#测试连接
ssh -T git@gitee.com
<span class="hljs-comment">#返回结果
Hi xxxx! You<span class="hljs-string">'ve successfully authenticated, but GITEE.COM does not provide shell access.
</span></span></span></code></pre>
<h3 id="安装deploy">安装deploy</h3>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#安装推送插件
npm install hexo-deployer-git --save
</span></code></pre>
<p>配置文件</p>
<pre><code class="language-yml hljs yaml"><span class="hljs-comment">#配置blog目录下的_config.yml文件
<span class="hljs-comment">#注意格式
<span class="hljs-comment">#type:空格git
<span class="hljs-comment"># Deployment
<span class="hljs-comment">## Docs: https://hexo.io/docs/deployment.html
<span class="hljs-attr">deploy:
<span class="hljs-attr">type: <span class="hljs-string">git
<span class="hljs-attr">repo: <span class="hljs-string">git@gitee.com:gaoanyu/gaoanyu.git
<span class="hljs-attr">branch: <span class="hljs-string">master
</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h3 id="提交md文件">提交md文件</h3>
<p>编写markdown格式的文件,并复制到source/_posts目录下</p>
<p>注意:是纯文本文件</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#初次提交执行命令
hexo deploy
<span class="hljs-comment">#后续更新执行命令
hexo generate --deploy
<span class="hljs-comment">#出现以下信息,表示提交成功
<span class="hljs-comment">#Enumerating objects: 31, done.
<span class="hljs-comment">#Counting objects: 100% (31/31), done.
<span class="hljs-comment">#Delta compression using up to 4 threads
<span class="hljs-comment">#Compressing objects: 100% (12/12), done.
<span class="hljs-comment">#Writing objects: 100% (17/17), 6.42 KiB | 1.07 MiB/s, done.
<span class="hljs-comment">#Total 17 (delta 6), reused 0 (delta 0)
<span class="hljs-comment">#remote: Powered by GITEE.COM
<span class="hljs-comment">#To gitee.com:your_Gitee_name/your_Gitee_name.git
<span class="hljs-comment"># 3162911..73c8374HEAD -> master
</span></span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h3 id="配置gitee-pages">配置Gitee Pages</h3>
<p>进入创建好的配置仓库中,打开服务,点击会出Gitee Pages,JavaDoc,PHPDoc等,表示上一步提交的信息,已被gitee.com成功接收了。点击Gitee Pages,选择强制使用https,点击下方更新,点击确定</p>
<p>在浏览器中输入 https://your_Gitee_name.gitee.com 就会看到写好的博客</p>
<h2 id="其他配置">其他配置</h2>
<h3 id="配置主题">配置主题</h3>
<p>官方文档</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment"># 安装主题
git clone -b master https://github.com/Molunerfinn/hexo-theme-melody themes/melody
<span class="hljs-comment">#修改blog目录下的_config.yml文件
vim _config.yml
theme: melody
<span class="hljs-comment"># 安装页面渲染插件
npm install hexo-renderer-jade hexo-renderer-stylus --save
<span class="hljs-comment"># 复制主题配置文件
mkdir -p source/_data/
cp themes/melody/_config.yml source/_data/melody.yml
<span class="hljs-comment">#修改主题配置文件
local_search:
enable: true
labels:
trigger: auto
top_n_per_article: <span class="hljs-number">1
</span></span></span></span></span></span></code></pre>
<h3 id="本地图片调用">本地图片调用</h3>
<p>在source下新建目录img, 在进行调用时候通过url绝对路径本地调用</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#查看目录信息
dir source\img
<span class="hljs-number">15:<span class="hljs-number">56 <span class="hljs-number">1,<span class="hljs-number">184,<span class="hljs-number">411 shz.png
<span class="hljs-comment">#查看调用图片详情

<span class="hljs-comment">#查看本地调用图片源码信息
<p><img src=<span class="hljs-string">"/img/shz.png" alt=<span class="hljs-string">""></p>
<span class="hljs-comment">#查看gitee.com调用图片信息
https://gaoanyu.gitee.io/img/shz.png
</span></span></span></span></span></span></span></span></span></span></span></code></pre>
<h3 id="安装站点地图插件">安装站点地图插件</h3>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#安装站点地图插件
cnpm install hexo-generator-sitemap
<span class="hljs-comment">#修改_config.yml文件
<span class="hljs-comment">#Plugins:
Plugins:
- hexo-generator-sitemap
<span class="hljs-comment"># Search
search:
path: sitemap.xml
field: post
format: html
limit: <span class="hljs-number">10000
</span></span></span></span></span></code></pre>
<h3 id="feed插件">feed插件</h3>
<p>Rss的生成插件,可以在配置显示站点的RSS,文件路径\atom.xml</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#安装
cnpm install hexo-generator-feed
<span class="hljs-comment">#修改配置
<span class="hljs-comment">#Plugins:
Plugins:
- hexo-generator-sitemap
- hexo-generator-feed
<span class="hljs-comment">#Feed Atom
feed:
type: atom
path: atom.xml
limit: <span class="hljs-number">20
</span></span></span></span></span></code></pre>
<h3 id="wordcount问题">wordcount问题</h3>
<p>在文件夹themes\melody中找到_config.yml文件</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment"># 设置为true
<span class="hljs-comment"># Please see doc for more details: https://molunerfinn.com/hexo-theme-melody-doc/#/additional-package-support?id=word-counting
wordcount:
enable: true
</span></span></code></pre>
<h3 id="配置搜索功能">配置搜索功能</h3>
<p>搜索插件是基于站点地图的xml文件</p>
<p>在文件夹themes\melody中找到_config.yml文件</p>
<pre><code class="language-powershell hljs"><span class="hljs-comment">#安装搜索插件
cnpm install hexo-generator-searchdb --save
cnpm install hexo-generator-search --save
<span class="hljs-comment">#主题配置文件搜索项,设置为true
<span class="hljs-comment"># Local search
<span class="hljs-comment"># Please see doc for more details: https://molunerfinn.com/hexo-theme-melody-doc/#/third-party-support?id=local-search
<span class="hljs-comment"># ---------------
local_search:
enable: true
</span></span></span></span></span></code></pre>
</div><br><br>
来源:https://www.cnblogs.com/bgms/p/12864897.html
頁:
[1]