Hexo Github:个人博客网站搭建完全教程(看这篇就够了)

时间: 2022-07-27 08:41:51 浏览次数:275

个人博客网站搭建完全教程(看这篇就够了)阅读须知

注意,这篇文章篇幅较长,主要针对新手,每一步很详细,所以可能会显得比较啰嗦,建议基础比较好小伙伴根据右侧目录选择自己感兴趣的部分跳着看,不要文章没看,上来先喷一下!谢谢( ⊙ o ⊙ )。教程内容随意复制使用,引用的话请加一个参考链接,谢谢!

博客开源

倒腾了一两周总算把个人博客网站完善了,目前这个版本使用应该是够了,当然还有一些优化项和功能增加后续在慢慢更新,为了回馈开源,今天准备把我自己修改完善的blog网站源代码开源。这不是生成后的网页文件,是您可以直接使用的源码,您只需要把博客相关信息换成您自己的就可以部署了,对于新手或者不懂编程的小伙伴来说,简直是福音,极大简化了您构建博客的工作量和复杂度,每个人都可以下载并修改成自己喜欢样式!如果你有修改想法,欢迎PR!最后,我们还是给这个开源小项目取个名字吧,就叫hexo-blog-fly吧,怎么样?<<<<<源代码下载>>>>>

本博客基于Hexo框架搭建,用到hexo-theme-matery主题,并在此基础之上做了很多修改,修复了一些bug,增加了一些新的特性和功能,博客地址:https://shw2018.github.io,博客演示:sunhwee.com。

简单使用方法:

star本项目仓库o安装Git, 安装nodeJS你可以直接fork一份源码到你的仓库,clone到本地在本地博客仓库运行npm i命令安装依赖包修改配置信息,改成自己的信息运行命令hexo clean(清除生成文件),hexo g(生成网页),hexo s(本地预览),hexo d(部署)

更多详情教程,强烈推荐看我写的:Hexo+Github博客搭建完全教程

有什么问题可以在文章最后评论区留言和讨论,当然,欢迎文章最后打赏投币,请博主一杯冰阔乐,笑~

最后,如果项目和教程对你有所帮助或者你看见了还算比较喜欢,欢迎给我github项目仓库点个star,谢谢您!

前言

去年在博客园注册了自己的第一个博客,当时初衷就是想拿来作为自己的在线笔记本,做做学习记录,分享一些学到的东西,使用第三方提供的博客服务其实也挺方便,现在市面上提供类似服务的博客网站也很多,如CSDN,博客园,简书等平台,可以直接在上面发表,用户交互做的好,写的文章百度也能搜索的到。但是缺点是比较不自由,会受到平台的各种限制和恶心的广告,个性化不足。而自己购买域名和服务器,搭建博客的成本实在是太高了,不光是说这些购买成本,单单是花力气去自己搭这么一个网站,还要定期的维护它,对于我们大多数人来说,也是没有这样的精力和时间。那么,我们能不能自己定制一个自己喜欢的个性化博客,同时也不用付出太高的成本啦?

这就引出了第三种选择,基于开源框架搭建博客,然后直接在github page平台上托管我们的博客。这样就可以安心的来写作,又不需要定期维护,基于这个想法,今年8月初的时候开始搭建第一个属于自己的独立博客,前后断续弄了近一周,到现在稍微有点模样了。我想可能有很多小伙伴应该也想过搭建一个自己的博客,当然,网上也有一堆详细教程。写这篇博客的目的大概有两个,第一个是当做自己的搭建记录,方便以后自己随时查看提示修改,第二个是稍稍总结一下具体的搭建步骤以及一些支持个性化定制的博客源码修改的教程,稍稍分享一下这些修改经验,当然,更多的一些个性化操作需要你自己以后在这个基础上慢慢去摸索,有些写的不太好的地方还希望看到的小伙伴多多包涵。

博客初步的页面效果可以看一下我的博客:sunhwee.com,欢迎大家支持。

本博客基于Hexo,所以首先要了解一下我们搭建博客所要用到的框架。Hexo是高效的静态网站生成框架,它基于Node.js,快速,简单且功能强大,是搭建博客的首选框架。大家可以进入hexo官网进行详细查看,因为Hexo的创建者是台湾人,对中文的支持很友好,可以选择中文进行查看。通过Hexo,你可以直接使用Markdown语法来撰写博客。相信很多小伙伴写工程都写过README.md文件吧,对,就是这个格式的!写完后只需两三条命令即可将生成的网页上传到github或者coding等代码管理托管平台,然后别人就可以浏览你的博客网页啦。是不是很简单?你无需关心网页源代码的具体生成细节,只需要用心写好你的博客文章内容就行了。

简单总结:Hexo, 产品成熟,使用简单,功能强大,有丰富的各种插件资源;但,像发布后台、站内搜索,评论系统类似诉求,虽然有对应的工具,但也需要自己折腾下,后续我们一步一步介绍。

教程大致分三个部分,

第一部分:hexo的初级搭建还有部署到github page上,以及个人域名的绑定。第二部分:hexo的基本配置,更换主题,实现多终端工作,以及在coding page部署实现国内外分流第三部分:hexo添加各种功能,包括搜索的SEO,阅读量统计,访问量统计和评论系统等。第一部分 搭建

hexo的初级搭建还有部署到github page上,以及个人域名的绑定。

Hexo搭建步骤1.安装Git2.安装Node.js3.安装Hexo4.GitHub创建个人仓库5.生成SSH添加到GitHub6.将hexo部署到GitHub7.设置个人域名8.发布文章1. 安装Git

为了把本地的网页文件上传到github上面去,需要用到工具———Git[下载地址]。Git是目前世界上最先进的分布式版本控制系统,可以有效、高速的处理从很小到非常大的项目版本管理。Git非常强大,建议每个人都去了解一下。廖雪峰老师的Git教程写的非常好,大家可以看一下。Git教程

windows:到git官网上下载.exe文件,Download git,安装选项还是全部默认,只不过最后一步添加路径时选择Use Git from the Windows Command Prompt,这样我们就可以直接在命令提示符里打开git了。

顺便说一下,windows在git安装完后,就可以直接使用git bash来敲命令行了,不用自带的cmd,cmd有点难用。

linux:对linux来说实在是太简单了,因为最早的git就是在linux上编写的,只需要一行代码

sudo apt-getinstall git

安装完成后在命令提示符中输入git --version来查看一下版本验证是否安装成功。

2. 安装nodejs

Hexo是基于node.js编写的,所以需要安装一下node.js和里面的npm工具。

windows:下载稳定版或者最新版都可以Node.js,安装选项全部默认,一路点击Next。最后安装好之后,按Win+R打开命令提示符,输入node -v和npm -v,如果出现版本号,那么就安装成功了。

linux:命令行安装:

sudo apt-getinstallnodejs sudo apt-getinstallnpm

不过不推荐命令行安装,有时候有问题,建议直接到官网去下载编译好的压缩文件,如下所示:

然后解压到你指定的文件夹即可,比如我解压到我系统的/home/shw/MySoftwares目录下了,如图:

注意本压缩包是.tar.xz格式的,需要两次解压

配置一下环境变量

sudovim /etc/profile

复制下面两行到刚打开的profile文件最底部(注意node的安装地址/home/shw/MySoftwares/node-v12.8.0-linux-x64换成自己的):

exportNODE_HOME=/home/shw/MySoftwares/node-v12.8.0-linux-x64exportPATH=$PATH:$NODE_HOME/bin

保存后退出,再执行下面命令将环境变量生效:

source/etc/profile

将目录软链接到全局环境下(命令后面的/usr/local/bin/node是固定的)

sudo ln -s /home/shw/MySoftwares/node-v12.8.0-linux-x64/node /usr/local/bin/node sudo ln -s /home/shw/MySoftwares/node-v12.8.0-linux-x64/npm /usr/local/bin/npm

这样安装好了以后使用npm安装的包(比如:ionic serve),使用包的命令时可能会提示找不到命令,没关系,在用户目录下终端执行下面命令(固定写法):

echo-e"export PATH=$(npm prefix -g)/bin:$PATH">> ~/.bashrc &&source~/.bashrc

这样我们在所有用户下,都可以使用npm,也可以使用npm安装的包的命令。成功地将nodejs安装并配置到全局环境下。

安装完后,打开命令行终端,输入:

node-vnpm-v

检查一下有没有安装成功

添加国内镜像源

如果没有梯子的话,可以使用阿里的国内镜像进行加速。

npmconfig set registry https://registry.npm.taobao.org3. 安装Hexo

前面git和nodejs安装好后,就可以安装hexo了,你可以先创建一个文件夹MyBlog,用来存放自己的博客文件,然后cd到这个文件夹下(或者在这个文件夹下直接右键git bash打开)。

比如我的博客文件都存放在D:\Study\MyBlog目录下。

在该目录下右键点击Git Bash Here,打开git的控制台窗口,以后我们所有的操作都在git控制台进行,就不用Windows自带的cmd了。

定位到该目录下,输入npm install -g hexo-cli安装Hexo。可能会有几个报错,无视它就行。

npminstall -g hexo-cli

安装完后输入hexo -v验证是否安装成功。

至此hexo就安装完了。

接下来初始化一下hexo,即初始化我们的网站,输入hexo init初始化文件夹

hexoinitMyBlog

这个MyBlog可以自己取什么名字都行,然后,接着输入npm install安装必备的组件。

cdMyBlog //进入这个MyBlog文件夹npminstall

新建完成后,指定文件夹MyBlog目录下载:

node_modules:依赖包public:存放生成的页面scaffolds:生成文章的一些模板source:用来存放你的文章themes:主题**_config.yml:博客的配置文件**

这样本地的网站配置也弄好了,输入hexo g生成静态网页,然后输入hexo s打开本地服务器,

hexoghexoserver(或者简写:hexo s))

然后浏览器打开http://localhost:4000/,就可以看到我们的博客啦,效果如下:

按ctrl+c关闭本地服务器。

4. 注册Github账号创建个人仓库

接下来就去注册一个github账号,用来存放我们的网站。大多数小伙伴应该都有了吧,作为一个合格的程序猿(媛)还是要有一个的。

打开https://github.com/,新建一个项目仓库New repository,如下所示:

然后如下图所示,输入自己的项目名字,后面一定要加.github.io后缀,README初始化也要勾上。

要创建一个和你用户名相同的仓库,后面加.http://github.io,只有这样,将来要部署到GitHub page的时候,才会被识别,也就是http://xxxx.github.io,其中xxx就是你注册GitHub的用户名。例如我的:http://shw2018.github.io

5. 生成SSH添加到GitHub

生成SSH添加到GitHub,连接Github与本地。右键打开git bash,然后输入下面命令:

git config --globaluser.name"yourname"git config --globaluser.email"youremail"

这里的yourname输入你的GitHub用户名,youremail输入你GitHub的邮箱。这样GitHub才能知道你是不是对应它的账户。例如我的:

git config --globaluser.name"shw2018"git config --globaluser.email"hwsun@std.uestc.edu.cn"

可以用以下两条,检查一下你有没有输对

gitconfiguser.namegitconfiguser.email

然后创建SSH,一路回车

ssh,简单来讲,就是一个秘钥,其中,id_rsa是你这台电脑的私人秘钥,不能给别人看的,id_rsa.pub是公共秘钥,可以随便给别人看。把这个公钥放在GitHub上,这样当你链接GitHub自己的账户时,它就会根据公钥匹配你的私钥,当能够相互匹配时,才能够顺利的通过git上传你的文件到GitHub上。

ssh-keygen -t rsa -C"youremail"

这个时候它会告诉你已经生成了.ssh的文件夹。在你的电脑中找到这个文件夹。或者git bash中输入

cat ~/.ssh/id_rsa.pub

将输出的内容复制到框中,点击确定保存。

打开github,在头像下面点击settings,再点击SSH and GPG keys,新建一个SSH,名字随便取一个都可以,把你的id_rsa.pub里面的信息复制进去。如图:

在git bash输入ssh -T git@github.com,如果如下图所示,出现你的用户名,那就成功了。

6. 将hexo部署到GitHub

这一步,我们就可以将hexo和GitHub关联起来,也就是将hexo生成的文章部署到GitHub上,打开博客根目录下的_config.yml文件,这是博客的配置文件,在这里你可以修改与博客配置相关的各种信息。

修改最后一行的配置:

deploy:type: gitrepository:https://github.com/shw2018/shw2018.github.iobranch: master

repository修改为你自己的github项目地址即可,就是部署时,告诉工具,将生成网页通过git方式上传到你对应的链接仓库中。

这个时候需要先安装deploy-git,也就是部署的命令,这样你才能用命令部署到GitHub。

npminstallhexo-deployer-git--save

然后

hexocleanhexogeneratehexodeploy

其中hexo clean清除了你之前生成的东西,也可以不加。hexo generate顾名思义,生成静态文章,可以用hexo g缩写 ,hexo deploy部署文章,可以用hexo d缩写

注意deploy时可能要你输入username和password。

得到下图就说明部署成功了,过一会儿就可以在http://yourname.github.io 这个网站看到你的博客了!!

7. 设置个人域名

不过,这一步不是必要的,如果目前还不想买域名可以先跳过,继续看后面的,以后想买域名了在还看这块

首先你得购买一个专属域名,xx云都能买,看你个人喜好了。

这篇以腾讯云为例,腾讯云官网购买:

然后实名认证后进入腾讯云控制台,点云解析进去,找到你刚买的域名,点进去添加两条解析记录,如下图所示:

然后打开你的github博客项目,点击settings,拉到下面Custom domain处,填上你自己的域名,保存:

这时候你的项目根目录应该会出现一个名为CNAME的文件了。如果没有的话,打开你本地博客/source目录,我的是D:\Study\MyBlog\source,新建CNAME文件,注意没有后缀。然后在里面写上你的域名,保存。最后运行hexo g、hexo d上传到github。

过不了多久,再打开你的浏览器,输入你自己的专属域名,就可以看到搭建的网站啦!

8. 写文章、发布文章

首先在博客根目录下右键打开git bash,安装一个扩展npm i hexo-deployer-git。

然后输入hexo new post "article title",新建一篇文章。

然后打开D:\Study\MyBlog\source\_posts的目录,可以发现下面多了一个文件夹和一个.md文件,一个用来存放你的图片等数据,另一个就是你的文章文件啦。你可以会直接在vscode里面编写markdown文件,可以实时预览,也可以用用其他编辑md文件的软件的工具编写。编写完markdown文件后,根目录下输入hexo g生成静态网页,然后输入hexo s可以本地预览效果,最后输入hexo d上传到github上。这时打开你的github.io主页就能看到发布的文章啦。

到这儿基本第一部分就完成了,已经完整搭建起一个比较简陋的个人博客了,接下来我们就可以对我们的博客进行个性化定制了。

第二部分 定制

我们要定制自己的博客的话,首先就要来了解一下Hexo博客的一些目录和文件的作用,以及如何平滑更换漂亮的主题模板并加入自己的定制源代码实现个性化定制

1. Hexo相关目录文件1.1 博客目录构成介绍

从上图可以看出,博客的目录结构如下:

-node_modules-public-scaffolds-source-_data-_posts-about-archives-categories-friends-tags-themes

node_modules是node.js各种库的目录,public是生成的网页文件目录,scaffolds里面就三个文件,存储着新文章和新页面的初始设置,source是我们最常用到的一个目录,里面存放着文章、各类页面、图像等文件,themes存放着主题文件,一般也用不到。

我们平时写文章只需要关注source/_posts这个文件夹就行了。

1.2 hexo基本配置

在文件根目录下的_config.yml,就是整个hexo框架的配置文件了。可以在里面修改大部分的配置。详细可参考官方的配置描述。

1.2.1 网站

参数描述title网站标题subtitle网站副标题description网站描述author您的名字language网站使用的语言timezone网站时区。Hexo默认使用您电脑的时区。时区列表。比如说:America/New_York, Japan, 和UTC。

在这里,你需要把url改成你的网站域名

permalink,也就是你生成某个文章时的那个链接格式。

比如我新建一个文章叫temp.md,那么这个时候他自动生成的地址就是http://yoursite.com/2018/09/05/temp。

以下是官方给出的示例,关于链接的变量还有很多,需要的可以去官网上查找 永久链接 。

参数结果:year/:month/:day/:title/2019/08/10/hello-world:year-:month-:day-:title.html2019-08-10-hello-world.html:category/:titlefoo/bar/hello-world

再往下翻,中间这些都默认就好了。

theme: landscap

theme就是选择什么主题,也就是在themes这个文件夹下,在官网上有很多个主题,默认给你安装的是lanscape这个主题。当你需要更换主题时,在官网上下载,把主题的文件放在themes文件夹下,再修改这个主题参数就可以了。

1.2.3 Front-matter

Front-matter是md文件最上方以---分隔的区域,用于指定个别文件的变量,举例来说:

title:Hexo+Github博客搭建记录date:2019-08-1021:44:44

下是预先定义的参数,您可在模板中使用这些参数值并加以利用。

其中,分类和标签需要区别一下,分类具有顺序性和层次性,也就是说Foo,Bar不等于Bar,Foo;而标签没有顺序和层次。

---title:Hexo+Github博客搭建记录date:2019-08-1021:44:44author:洪卫img:/medias/banner/7.jpgcoverImg:/medias/banner/7.jpgtop:truecover:truetoc:truepassword:5f15b28ffe43f8be4f239bdd9b69af9d80dbafcb20a5f0df5d1677a120ae9110mathjax:truesummary:这是你自定义的文章摘要内容,如果这个属性有值,文章卡片摘要就显示这段文字,否则程序会自动截取文章的部分内容作为摘要tags:-Hexo-Github-博客categories:-软件安装与配置---1.2.4 layout(布局)

1.2.4.1 post

当你每一次使用代码

hexonewXXX

它其实默认使用的是post这个布局,也就是在source文件夹下的_post里面。

Hexo有三种默认布局:post、page和draft,它们分别对应不同的路径,而您自定义的其他布局和post相同,都将储存到source/_posts文件夹。

而new这个命令其实是:

hexonew[layout] </code></pre><p id="d079cda3-53dc-444e-98bc-63850dc5ae32">只不过这个<span id="e86ac8bc-b860-473a-9cca-c1a847371101"><span id="f74dbade-7364-48da-99e3-4605ac2365e2">layout</span></span>默认是<span id="dd010655-ecfe-400c-bc18-a9d09c1f8223"><span id="4a81f807-cddc-4779-a521-0a1d2a0e6edd">post</span></span>罢了。</p><p id="7e7da8d1-eff1-4bbf-b6e7-19bcc2675ae9"><strong id="4c5a7007-8239-4ef5-8b5d-f518da641fb7">1.2.4.2 page</strong></p><p id="19d1351b-4352-42fc-8ca2-54f59cf8f008">如果你想另起一页,那么可以使用</p><pre id="b414940a-ea5a-4251-9525-4998f15b95a9"><code id="e38a4ee4-ac5d-4035-b541-69ab0b283c34">hexo<span id="1a2c30dd-c1a2-4cd7-a231-564a4ed012b7">new</span>page newpage</code></pre><p id="21948078-cdd8-4590-b168-6e2d7bd3f71f">系统会自动给你在<span id="aafb0c44-2f55-4a73-b5d8-99c2054c3543"><span id="f72f20f2-6747-4573-8107-b2771644bfd6">source</span></span>文件夹下创建一个<span id="ea9f77c7-e14e-42ee-b10b-ec410085e389"><span id="2a844933-836b-4cb6-9004-6eefbde1b5b4">newpage</span></span>文件夹,以及<span id="b0e9c96a-a716-4634-9d15-0f942018f909"><span id="7c988bb3-2c59-4060-90bf-ec0fb0bbb2cf">newpage</span></span>文件夹中的<span id="5ec04eb6-cda1-446c-bbf3-757256d034d1"><span id="ecf83b7d-4251-4e4e-9916-ce5b7e3ef6d2">index.md</span></span>,这样你访问的<span id="455c1277-fcd4-4f01-91d1-fe49cfc5af1c"><span id="02dbb51a-d6f3-43e8-be91-ca73d9728431">newpage</span></span>对应的链接就是http://xxx.xxx/newpage</p><p id="26969733-41af-434e-a7e2-fd01d58cb57b"><strong id="15713309-b8e5-46a5-abd5-663f1c23160f">1.2.4.3 draft</strong></p><p id="3f0fa932-3873-4799-a088-1acfb39adbef"><span id="81dcd621-3110-4eb1-9472-ac5b6df8f3d0"><span id="f175cad0-0a08-4a50-b8dc-bc37ccd16585">draft</span></span>是草稿的意思,也就是你如果想写文章,又不希望被看到,那么可以</p><pre id="e1f8477c-920b-43a9-9f87-c23ccb24cbd9"><code id="50872aa1-0abf-4c5f-ab41-73ec87af3d66">hexo<span id="eb0d7e31-d474-433b-a497-e8e1d0f18d92">new</span>draft newdraft</code></pre><p id="c4dcadec-dd8f-4167-bb74-0ab487a90cb2">这样会在<span id="1ac92e3c-c68f-4786-a5e7-88734cbb8567"><span id="fd9e097e-4f6b-4c53-b411-ce1c6284802b">source/_draft</span></span>中新建一个<span id="fdf565e2-0b28-40ac-910b-dcae6a3451c4"><span id="777e524c-89d1-4089-9a17-d30ec6f95cb3">newdraft.md</span></span>文件,如果你的草稿文件写的过程中,想要预览一下,那么可以使用</p><pre id="9c8ff9d3-eb4a-4622-baaa-d9ceb6ee4844"><code id="0bdd0533-5a43-4f9e-bd50-039bfa5a4c9a">hexo server<span id="0d539cdc-b8d6-45a8-a8d8-c75ef4129eb6">--draft</span></code></pre><p id="f426d6a8-8584-4607-a050-a2023a0da519">在本地端口中开启服务预览。</p><p id="d4e866a9-33f6-4435-8c7a-6e3ce42abf46">如果你的草稿文件写完了,想要发表到<span id="6912d3ee-5880-45df-977a-be1b9aa9723f"><span id="8c571814-8006-419f-b170-ab0d8f4818d7">post</span></span>中,</p><pre id="6f000c24-dc6d-48c2-b8b7-c583e309adc4"><code id="142fcb80-581e-4341-ace7-13bd35172798"><span id="c2b354e8-28f4-4873-92c0-0e2608f3d581">hexo</span>publish draft newdraft</code></pre><p id="c6dbb6ed-008f-412a-8790-8d8f265ac7cc">就会自动把<span id="5d50fc7a-eada-4615-9bb5-f82e8d95844a"><span id="4ec01a29-3453-45f0-b670-13ad029508f6">newdraft.md</span></span>发送到<span id="71fa7d1a-b886-4c4b-8a64-ccc2f228c51c"><span id="17d227f3-6481-4a6a-a7e4-ccb5b621b18e">post</span></span>中。</p><h1 id="2d867380-7d6c-4e72-b191-d48196a47c98">2. 更换主题</h1><hr id="18388e95-fd96-4b4b-b9e0-964441928e9a"></hr><p id="b5bf924c-e0d5-415e-8d1f-20d4f004cf58">我们在了解<span id="7130a42e-5442-4020-a4c0-edbbb5e9d8c2"><span id="4671fc97-af3a-4ce8-818b-b056a6ea3c0d">Hexo</span></span>博客文件基础之后,知道主题文件就放在<span id="82be4c4f-a70f-4b01-8b3c-df9714f04efa"><span id="3e9bcf1a-bc4c-4855-81c8-158af8bbf6a4">themes</span></span>文件下,那么我们就可以去Hexo官网下载喜欢的主题,复制进去然后修改参数即可。网上大多数主题都是github排名第一的<span id="2d774c39-9ea4-4e93-bbdd-101df2f24fd4"><span id="f52a6d1a-1c86-41c5-8df1-640206b76a8c">Next</span></span>主题,但是我个人不是很喜欢,我在网上看到一个主题感觉还不错:hexo-theme-matery,地址在传送门。这个主题看着比较漂亮,并且响应式比较友好,点起来很舒服,功能也比较很多。</p><blockquote id="accd9ed5-d447-4e69-b5e9-24efb1809ebe"><p id="db5f46bb-5d8b-4671-ac4c-fd313c40cf91"><span id="f8576887-61d7-48bc-851b-4c4000dfc54d">当然,人各有异,这个主题风格也不一定是你喜欢,那么你也可以跟着这教程类似的方法替换成你喜欢的就行了。</span></p></blockquote><blockquote id="a4beea50-7547-4f32-90d5-0427b2e58b01"><p id="f4921ca3-83a3-40b0-9890-7abe7675ce51"><span id="d3f1aaf0-b33a-4b62-9b69-483039a07c46">特性:</span></p></blockquote><ul id="7187cd56-da22-4c24-95cc-d8ad5eea33db"><li id="daeb8b56-c428-4bc6-9e29-a8e04f132299">简单漂亮,文章内容美观易读</li><li id="6722a023-2597-49f7-8808-d24e1972e32f">Material Design 设计</li><li id="240d3483-d994-4d3c-bd02-3bdf9e1304bd">响应式设计,博客在桌面端、平板、手机等设备上均能很好的展现</li><li id="0e58dab8-e434-4ea6-b51b-0bb3dabd8aab">首页轮播文章及每天动态切换<span id="d94777a1-8950-4ece-90cb-54c4ccdd6f2c"><span id="6435d4da-f720-4ada-b4a4-f434a5e7550b">Banner</span></span>图片</li><li id="2304ec53-b9eb-4d1f-919f-8856e8755142">瀑布流式的博客文章列表(文章无特色图片时会有<span id="42de90f7-fc9f-45ca-a176-e0bf20bd79fd"><span id="3baf7544-e5f5-4c72-bab7-91a955e34dc3">24</span></span>张漂亮的图片代替)</li><li id="c9ab7b23-39de-4216-b266-90911c8078f2">时间轴式的归档页</li><li id="96d1403a-e038-4944-9afe-0daaec050a77"><strong id="dbc4947b-aeee-48c3-ada4-2d51f9d3a693">词云</strong>的标签页和<strong id="d035697e-a85f-47f5-a9dd-0aece9835323">雷达图</strong>的分类页</li><li id="26046f26-7690-40d9-8c35-72ec7296fce2">丰富的关于我页面(包括关于我、文章统计图、我的项目、我的技能、相册等)</li><li id="a812f9c0-c634-4619-b902-400a98ba22a5">可自定义的数据的友情链接页面</li><li id="d873bf51-1bde-4f90-8704-d1326823d593">支持文章置顶和文章打赏</li><li id="f63759e7-a5c8-45de-8bc5-d30604c116fb">支持<span id="1d170d15-93f1-43ab-9d1e-f64f960002c3"><span id="c6db1353-1c05-4e5b-907c-e2a627552448">MathJax</span></span></li><li id="7f83ffdb-5f37-483e-bfa7-80f58df23291"><span id="fc563a72-43ba-4d9d-9fef-00ef9c4edc6f"><span id="5bebba06-bd57-4b4d-bb6c-3b4149c2d48a">TOC</span></span>目录</li><li id="ab4dae0e-cb30-4ecf-bada-4c954bf4a444">可设置复制文章内容时追加版权信息</li><li id="e697ab3b-1d33-49cf-b4f8-706ce63c8b3f">可设置阅读文章时做密码验证</li><li id="623bd20c-a7f0-47f1-a224-2ac1ab1e1984">Gitalk、Gitment、Valine 和 Disqus 评论模块(推荐使用<span id="000f0359-f7d1-42ec-93c4-27adc43042eb"><span id="c376610f-27b2-48e9-809a-383a288792a4">Gitalk</span></span>)</li><li id="44678556-01c9-49ed-a4d1-1327b9225a67">集成了不蒜子统计、谷歌分析(<span id="5d386856-ef61-46ab-848f-e991beb93653"><span id="e8380407-61d7-48fc-861e-844913b7680e">Google Analytics</span></span>)和文章字数统计等功能</li><li id="3911c977-6a95-42f0-87e9-905a487bb5d0">支持在首页的音乐播放和视频播放功能</li></ul><p id="55420541-4174-4ac5-abc0-025b8d240b5c">他的介绍文档写得非常的详细,还有中英文两个版本。效果图如下:</p><p id="9a12be46-15b0-48ba-ae65-a41a61f57c52">首先先按照文档教程安装一遍主题,然后是可以正常打开的,如果你是一般使用的话,基本没啥问题了。不过有些地方有些地方可以根据你自己的习惯和喜好修改一下, 下面记录一下我这个博客修改了的一些地方。</p><h1 id="74f00798-523e-47d9-b996-17ccac867ab1">2.1 新建文章模板修改</h1><hr id="c02357ac-0560-471a-9f3e-6dfd9b15cbc6"></hr><p id="571cf9d0-3ccc-4042-80c7-8ab1c517823d">首先为了新建文章方便,我们可以修改一下文章模板,建议将<span id="b57c8cb2-ed04-4f6c-8685-a5348e8ff647"><span id="92682728-bd51-482a-a440-e583754b799b">/scaffolds/post.md</span></span>修改为如下代码:</p><pre id="609bf736-88c8-4542-a103-09dc5d094a8f"><code id="2c1ba3df-8b96-4590-abc5-576ae47aeb16"><span id="d5f17189-ee3e-4212-be2b-6e78ebfec313">---</span><span id="112d3bf1-708a-4fd4-a971-e74aaf11d36b">title:</span><span id="e13ed2dc-bd9a-43f4-bd0a-52bf326adc9d">{{</span><span id="61cbf8ab-4028-48f4-9135-a42b59b722be">title</span><span id="bd725c68-f517-4060-b719-dda9c1a9047c">}}</span><span id="1a225f3b-2b53-4cca-879e-3436ac997664">date:</span><span id="7d213b20-85f1-4d8a-b6c0-a2df338e539e">{{</span><span id="d3262d43-72cd-4ff8-aacf-d45f813887e9">date</span><span id="d7ef6e72-fdbb-47f8-9798-f1ae3bfb3a67">}}</span><span id="e869fd71-feb7-42d9-b3ad-aadece44ad13">author:</span><span id="57bf6981-8b33-45d6-afbd-e054e8ce9540">img:</span><span id="d7127db6-e1ee-467a-aaa6-0a2816bb44bf">coverImg:</span><span id="5eb0fde1-fdd7-47e6-8def-4f64015b0850">top:</span><span id="12f238fb-89a0-4b76-9d6b-84e235e3a4a4">false</span><span id="f3319830-77d1-4813-8b31-b8ea3ee4a6fb">cover:</span><span id="f189e4f3-46f6-4ae9-8171-51402f8bbb15">false</span><span id="58bc442c-9ab8-4adb-8ed3-ab0e2a4c1cd6">toc:</span><span id="26822146-acd1-4f50-a6e3-d836317fc473">true</span><span id="15c79136-c213-4a6f-9724-b6590be4f694">mathjax:</span><span id="7704b4ca-6329-4ecf-8767-a84f6eb0a5b4">false</span><span id="656e1576-260d-4ac3-a8f4-c4a746a4afe1">password:</span><span id="23352356-ca5a-49c6-93d7-281911318655">summary:</span><span id="c3e0e8a8-24e1-4d49-968e-f16d95a517ba">tags:</span><span id="dc7622e0-2ecf-415a-8aa6-080f491afc4c">categories:</span><span id="39dc372e-01c6-4792-b842-36e170c8167e">---</span></code></pre><p id="1cc2680b-7e2c-471b-9af1-4ed55997a682">这样新建文章后 一些<span id="29c353c6-2efe-4e52-ba30-525beacc2a7b"><span id="fc7544ad-03ab-432a-9840-bd07a6f95886">Front-matter</span></span>参数不用你自己补充了,修改对应信息就可以了。</p><h1 id="b5ce89c2-17cd-4c07-8f8b-d75dc063bfc9">2.2 添加404页面</h1><hr id="f08631be-b6d9-4b56-b9e1-d70dc23857c6"></hr><p id="ac22a4eb-d6eb-4939-b047-b856e0666119">原来的主题没有<span id="151dbf8e-bb90-451e-926c-16e3964119f8"><span id="429615bb-c54e-4711-be77-6b36b54afed3">404</span></span>页面,我们加一个。首先在<span id="e0966dd7-c5bb-4e76-a0bd-6a90e86ab4ed"><span id="5ae5483e-b9f6-4159-87b5-77213bd0daf5">/source/</span></span>目录下新建一个<span id="de22f5ea-88a7-4eb8-91bf-d2457ae083d7"><span id="003370ad-0eba-4209-8e6c-8f2934bb80e6">404.md</span></span>,内容如下:</p><pre id="4e994713-525d-4091-a685-d380dba61172"><code id="19a8fe9e-bec4-450f-b241-90b64ffe3f4d"><span id="82ca8a88-8acb-490d-8f63-368e83fca96f">title:</span><span id="5a9b1f10-2735-457b-8e3d-9746401ff3fa">404</span><span id="72be0488-1748-446a-9b05-e6cd1174749b">date:</span><span id="9ceebb69-12a6-48c7-bcca-b2d745cd2fb1">2019</span><span id="e953e62b-c55a-442e-b749-90aaaa7961e9">-08</span><span id="262d8330-fe04-4a77-a828-9d19554bccf1">-5</span><span id="56fd6b9f-5f44-4c2e-a542-97fea4118a4d">16</span><span id="13a65304-f7c5-4054-a151-d1f48fcebe41">:41:10</span><span id="18cabcb2-9414-4b07-86a6-fc0a5a230420">type:</span><span id="73405edb-4a10-44b0-8048-a06925051a81">"404"</span><span id="43500fcc-eef5-47b0-98b9-e0e71e0c7a7c">layout:</span><span id="9668f40a-67d8-4145-a3c5-88f8b3918e01">"404"</span><span id="c5aead50-7390-4a98-96c0-bc52958e61ab">description:</span><span id="dc7f998c-72c8-453c-83d2-bf1cee4ddb9e">"Oops~,我崩溃了!找不到你想要的页面 :("</span></code></pre><p id="3fdd680a-eff9-4a83-ad76-22a520b28956">然后在<span id="678cca8d-89fa-48d6-b8a4-955d17061220"><span id="a1eaf29f-98b2-4c87-99fc-8bcd658927b1">/themes/matery/layout/</span></span>目录下新建一个<span id="705e2f1d-dd7c-45dc-b27f-bcddd32a73f9"><span id="478cd2fb-132c-40eb-8e4f-77f635fda7ef">404.ejs</span></span>文件,内容如下:</p><pre id="d53035c8-e37f-40e0-adac-836d5ca35ed2"><code id="67e73041-39a9-473a-8e86-3a5622c10c44"><span id="5b5abec4-4240-4981-9e9b-65dc0ee26c48"><<span id="c1dc1b3d-1c6d-4841-8225-3388c8678930">style</span><span id="0c2cdcf3-5ffe-4ea3-b99e-6e2af6db8127">type</span>=<span id="a7522560-23f2-4d13-9fa3-4f9fedb97ceb">"text/css"</span>></span><span id="fe144622-fd0b-4337-8bae-769c97f0e47e"><span id="7ec6b194-7632-421c-b76d-89522e0a6f83">/* dont remove. */</span><span id="4d76631b-ce9a-48c9-adc0-adb6768edf2d">.about-cover</span>{<span id="348abf5b-e758-4b37-850f-a3d80e4350d6">height</span>:<span id="792185c7-80a0-40cb-b484-d7891d58ec32">75vh</span>; }</span><span id="172ca257-e948-485a-9f8c-29bfa0e82a28"></<span id="1a322c56-21ac-486f-912c-6dbd2154f54b">style</span>></span><span id="6fb66eb0-7b64-4c14-bcb9-92312b41cee7"><<span id="51dade4d-fc03-4311-86dd-870e7c0b0e5a">div</span><span id="145fcc60-5e78-4f92-9d0a-5b3501d1332d">class</span>=<span id="b96c1fa0-a9ce-42ad-b658-ca15d13ead16">"bg-cover pd-header about-cover"</span>></span><span id="14fddfde-6060-43ea-8cb6-35add7732816"><<span id="022e180f-1315-412d-bde5-a73faf1025d7">div</span><span id="2fb427f8-8161-49f2-a9c0-3254de912d41">class</span>=<span id="69a99826-eb55-44d1-957e-b5ae13ce0878">"container"</span>></span><span id="ad333f23-ccb2-4691-a3dc-1e3e6ad6f2b9"><<span id="5c011dc0-a29f-4545-907e-51a2b4acc06d">div</span><span id="dd0a80bc-fb87-48bc-8283-bf3180ef410f">class</span>=<span id="1144814e-39b5-4fe6-9284-12529b1156b9">"row"</span>></span><span id="559fd3c1-ddad-4861-a0fb-7df90d2e23f7"><<span id="e22070a3-398b-4f9b-8990-7feef28f917b">div</span><span id="390c7dc5-5421-4338-8d23-dcc6c4621279">class</span>=<span id="d9d4bfcf-956d-4816-acc9-ba7334d96d81">"col s10 offset-s1 m8 offset-m2 l8 offset-l2"</span>></span><span id="aa73312a-62b9-4387-8a0f-5aff2a492e24"><<span id="c254a724-c69c-443f-b80c-a79b54a86641">div</span><span id="5bba0dac-a64a-406c-b528-976bd3e83c53">class</span>=<span id="c0064fba-35b4-4067-95ff-96b327000d22">"brand"</span>></span><span id="be141866-68c7-47fb-9c21-b76597ce4c37"><<span id="437a244b-52a6-49c0-8e66-4301b66e252d">div</span><span id="2f839aa0-9c62-4279-b196-31c88170673b">class</span>=<span id="2dc7dff6-df51-4d18-a557-66fa23a22377">"title center-align"</span>></span>404<span id="7ece62e2-3512-45f7-a715-35966a424ce2"></<span id="4164be91-a191-41f2-a516-a66cc7f17fda">div</span>></span><span id="99a987aa-4fc3-451c-b3bf-fe3b80595ca9"><<span id="4c9c8a7b-973f-4a2f-a34b-fa5ce68b7281">div</span><span id="1d092ca9-8648-4b3c-a352-3ad529816e81">class</span>=<span id="58b33c29-74eb-40de-a1b0-f3e89c2768e7">"description center-align"</span>></span><span id="10055a00-351e-4af0-a058-a67efe52cf9f"><<span id="6a61135f-53bf-49e3-86cf-23719507bcf2">%=</span><span id="440d3652-0408-4a8c-acfa-d3ca534489dd">page.description</span>%></span><span id="f0872ebf-3181-4877-a4b3-9b75073d36a7"></<span id="0166da51-78ec-4fab-85ae-847387716b7b">div</span>></span><span id="bf289f3b-43bf-4af2-95de-5a28a46fd587"></<span id="94ea2f7c-fb00-49c3-9162-dd68f8d5c4e3">div</span>></span><span id="9fd3a13a-341b-44e6-a82d-f73b39705ca6"></<span id="1d4e2bee-96d1-4fc6-978e-66898a2dcab3">div</span>></span><span id="260706f8-31f8-46f9-84ed-8e0044531dc9"></<span id="9370b26a-bb48-4cab-9fec-687a59e6dac2">div</span>></span><span id="9fed2c3a-b088-4e2d-a49a-4ded6c4c0d32"></<span id="06602544-d778-48e1-8c92-5768410e87f7">div</span>></span><span id="df27bd9b-e317-40f9-ace0-a0e7906050a4"></<span id="8985fc4a-2dda-4e6a-89c4-36405d949102">div</span>></span><span id="c8698e0c-2492-4331-b596-293ebe5e2527"><<span id="77ded9e5-5f60-409a-9a75-604547050c09">script</span>></span><span id="4df2f7b0-559c-4152-88c6-12969f026baa"><span id="67ee6208-98f0-4590-b0b4-c384d5354728">// 每天切换 banner 图. Switch banner image every day.</span>$(<span id="528b38a2-b564-4fa5-a722-38bfdef65ae8">.bg-cover</span>).css(<span id="5333b778-85b0-4cec-8640-72f28906126e">background-image</span>,<span id="865ef4bd-ff6b-4a55-a759-db0f0e4edb4c">url(/medias/banner/</span>+<span id="ddbf0ab4-82ed-4a36-ad01-77ebb7cc3e66">new</span><span id="df57c276-8424-4ee5-8ad7-2367b699483b">Date</span>().getDay() +<span id="d1ed33b8-9658-45fa-9ae7-f6282660b04c">.jpg)</span>);</span><span id="80cf2b48-921b-4c12-a959-a05decfaa736"></<span id="bf15c68f-2da6-43fc-85f6-54e556cae9fa">script</span>></span></code></pre><h1 id="b96f0d39-d220-4255-9f2d-b8ed05fa8ee8">2.3关于页面增加简历(可选)</h1><hr id="6d8fe216-ce99-4c3f-a074-01a57f06c96c"></hr><p id="a55ff28a-35af-4d8a-b19b-c1b8431fcfd3">修改<span id="a52e8ac4-70a0-43fd-b747-9db2b46a5701"><span id="cfd8cd3d-abf6-41d2-a7ff-222097456625"><span id="b64b2c8d-da57-4ae2-869e-54fe35be20c7">/themes/matery/layout/about.ejs</span></span></span>,找到<span id="b171ede9-5aee-4d59-8f3a-5b13aa89dd03"><span id="abf9910b-cd4c-4f84-8524-b2b215bbbc36"><div class="card"></span></span>标签,然后找到它对应的<span id="9885303f-08c6-42d5-a544-11dd63fdca95"><span id="ece66d72-2de7-4d15-8393-f2d6faa145f0"></div></span></span>标签,接在后面新增一个<span id="6866a584-aab1-49b2-b156-3d49cd54f027"><span id="5c5134b1-bb90-464d-8ff0-c952dc96da6c">card</span></span>,语句如下:</p><pre id="d2a33a4c-5595-4e86-a4a9-537d326cec18"><code id="08d1d0fb-49f0-4487-ada7-09d5d95af3c2"><div<span id="97bcd285-285b-499e-bcde-6fd825160177"><span id="a006790a-d656-4a07-9e17-7fa2436f111b">class</span></span>=<span id="bc7a99b9-af08-4440-9bdd-56d22b4c5911">"card"</span>><span id="2f03216a-ee14-4178-bc43-aca3b9e73c4f"><span id="a6c1c84b-bbe9-48ac-afbe-bf79c4552668"><<span id="62510465-78c8-4069-a3a6-c93c05895eda">div</span><span id="bac2267e-846c-4368-a177-bbbac7a1a6d4">class</span>=<span id="aec8202c-e8eb-46eb-bb85-628f6b1cf5dd">"card-content"</span>></span><span id="a6a20409-5bbf-4093-865b-c8f91acddfc3"><<span id="d269901d-3fb6-4672-8f73-d8578093073e">div</span><span id="97a92548-3a38-45c4-87a1-33f482a522db">class</span>=<span id="47a8494f-4af9-4cc0-8b11-c64e16c14d6f">"card-content article-card-content"</span>></span><span id="205c2f86-50a6-4ed3-935a-d99b8c04b9e0"><<span id="00836787-4280-4944-9a7b-b80e100a8e22">div</span><span id="cd13cef3-fa2e-440a-b59b-d97b7d4f84fa">class</span>=<span id="fb97cfb1-b628-4b4b-a173-cf6f89eccd1f">"title center-align"</span><span id="b853b770-11f2-4ae3-bffd-5acfb4feccc2">data-aos</span>=<span id="c35e710b-77eb-4515-b89c-0f39012b3791">"zoom-in-up"</span>></span><span id="f5fbeec5-7548-4d30-870f-6b3e534a71be"><<span id="d0ee1866-a163-42fc-ae03-10f17df1ef40">i</span><span id="d943a8d9-81a1-4bd7-9049-359de8c0ea74">class</span>=<span id="27f85a91-dd46-4357-bba5-82e819fcfcb8">"fa fa-address-book"</span>></span><span id="20ce53a0-fc92-44d0-bd01-74a078537eda"></<span id="5b18765d-0733-4aad-803a-ace237bea94d">i</span>></span><span id="ab87b4bf-7a9a-42be-8cc7-eccc7a191af9"><<span id="ea68a622-8c16-49a0-8d68-673a8f2c997c">%-</span><span id="7086258b-b408-4789-bdc9-baad1834a1a4">__</span>(<span id="eb516af6-7117-4022-8036-ba634bc7c54b">myCV</span>) %></span><span id="fc0cd5d2-9552-4926-b617-767c0db66b0d"></<span id="2a30e243-34e8-44ff-853d-94ddd1b980aa">div</span>></span><span id="8157ab1a-98fd-435f-be52-32626da5fb41"><<span id="0b3b075f-3a76-464f-b0bc-674a1de042e4">div</span><span id="920e15bb-1c24-4fda-97d9-47b0d44ed1b9">id</span>=<span id="5c4c99bf-b357-4ede-bfb5-4853de5b9b9a">"articleContent"</span><span id="59bd5f4c-5d99-44df-8711-761a7539bc58">data-aos</span>=<span id="73fbe8ea-e70f-4ceb-ad46-2a0007a750c0">"fade-up"</span>></span><span id="b42457fc-6760-4ef3-9814-19b4c7603c10"><<span id="3d26ac59-7595-4654-9bd8-67178ddd64e3">%-</span><span id="68b053fa-f6d8-4e13-a2f7-f34a5698311d">page.content</span>%></span><span id="bddc668a-3b70-4702-9873-309c339ba422"></<span id="8c383440-dd21-420e-ae0b-cb33e502e467">div</span>></span><span id="c3bdba35-99a8-450a-ab40-28291fd9f2a4"></<span id="82cee7f0-6c7f-4214-a350-2da7b506eb72">div</span>></span><span id="5fe6ad0f-5be6-4afe-b5d0-0289704932c0"></<span id="873efa3b-9f96-40b6-b19b-093f78c949a3">div</span>></span></span><span id="24298dc6-0a60-4619-bef1-bb20f77a6ac1"><span id="1ee1679d-a401-4f8f-ae23-3b4f2a3dc334"></<span id="fdd22413-1e97-40d1-bb1f-a0b6b622a0ee">div</span>></span></span></code></pre><p id="a8913d25-9546-4fd0-8a5b-b8c3b1e8da3e">这样就会多出一张<span id="3cfce2ca-9081-4666-be42-7ce25406c528"><span id="7b1d9fa8-b2ce-4d0c-b1cd-f966087d0c0b">card</span></span>,然后可以在<span id="333c2c56-8024-4512-9b44-b3f203ebed17"><span id="f4fe9f34-b973-4312-9ab0-ba39101b2f50">/source/about/index.md</span></span>下面写上你的简历了,当然这里的位置随你自己设置,你也可以把简历作为第一个<span id="2fb6a784-d4f4-475d-997c-be367e9eb91a"><span id="688c9089-eca6-4125-80a2-5fc5d8f54f3e">card</span></span>。</p><h1 id="86d2c792-7287-47c9-8c6e-d2fa38b46940">2.4 数学公式渲染和代码高亮</h1><hr id="6d442dbf-33d8-4a1d-a387-f34e082937f9"></hr><p id="973d7f06-ab29-4c79-bc90-e1a2fc5b6e46"><strong id="bfc4aa45-a34a-490d-bdec-e0982fcf917f">2.4.1 解决mathjax与代码高亮的冲突</strong></p><p id="132803ac-80e1-46bb-a180-2339b8afbf47">如果你按照教程安装了代码高亮插件<span id="c07d5f22-08b2-467a-aa32-edbfdd6adc08"><span id="663c87fd-6b83-4bab-974a-a6531893b07d">hexo-prism-plugin</span></span>,单独使用是没有问题的,但如果你又使用了<span id="fbf7cb5e-bc8c-44ff-bcec-08a8fd486aab"><span id="9618d977-9ac3-4242-a472-b6d877842c5b">mathjax</span></span>,并且按照网上教程,安装<span id="1e124d50-e575-4093-8a52-8da0c2243ddb"><span id="27b07b50-2e20-4d9d-af3b-231d2b856266">kramed</span></span>插件并修改了<span id="968b4b47-6f20-4fce-abb9-dd408554f89f"><span id="a0d38c2f-fffe-40fc-a114-9038d6b8cc4e">js</span></span>文件里的正则表达式(为了解决<span id="7e677e7b-0a87-4071-b7c4-a94f4449144a"><span id="526891eb-a5f7-4c93-af15-6c922cd1dfde">markdown</span></span>和<span id="5c297f45-91c7-4ade-9318-65cfb7770ef9"><span id="3738ea0a-19a8-4bc3-a0af-e61b5732648b">mathjax</span></span>的语法冲突),那你的代码就无法高亮了。解决方法很简单,别用<span id="f5de334c-295b-4bb0-a567-38719963574f"><span id="965e3328-66a4-43b9-ade4-20aef5ad1e0b">kramed</span></span>插件了,还用原来自带的<span id="99a346c4-ded5-4a45-aed3-84bf7ff0df14"><span id="cdd8a44b-f8bc-4197-8fc5-ae04a7e123bf">marked</span></span>插件,直接改它的正则表达式就行了。</p><p id="4bc2c3e6-b771-4d1a-90d0-60f832a36e80"><strong id="a5169bae-fa52-47a5-9ee8-1b3d93c0af4e">2.4.2 加数学公式显示</strong></p><p id="86463b1c-26e6-4301-9411-223161e3d998">打开<span id="65a83a5d-fc65-4b06-afa4-bbcd53abbbf7"><span id="41172910-82d6-4356-853b-f0f033bf7991">/themes/matery/layout</span></span>中的<span id="48f06a6b-4f46-412b-94a2-b9f844134321"><span id="7338994d-34a9-4f62-89ba-be00310ab07c">post.ejs</span></span>文件,在最下方粘贴如下代码:</p><pre id="b1c35793-3493-478c-8536-1b683e18907c"><code id="2a7883c5-9e5d-44e3-8d44-c747fe1cc5d9"><span id="25a37119-3b63-4610-ad29-d2f78e428859"><<span id="0a34ae40-699c-47b6-9ab7-d632877ced7f">script</span><span id="a88cbfeb-0911-4b54-b7f7-4a393464facb">type</span>=<span id="61f383bd-a9e9-40b7-9a70-a8f7ade4c4e7">"text/javascript"</span><span id="947b2dfc-fec8-4ea5-92ab-10fccbc8714c">src</span>=<span id="ac235cd5-f70d-4f79-9577-b10ffdc7ef24">"http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"</span>></span><span id="cf2b32e3-6591-4aea-9f27-d7f68c4ed82f"></<span id="20bd695f-9394-4eff-afd9-1dbefdb7c077">script</span>></span></code></pre><p id="3f8e7ef0-401f-44b1-ba16-45dfa188c65a">由于<span id="5d088897-91a1-48ee-a247-79819c19c1cb"><span id="a311e406-acad-4d8d-a161-b4d32b028438">markdown</span></span>语法与<span id="303bfd85-9a9a-43d6-b08f-e12b8b62d321"><span id="9c73a050-8a45-4f31-b0f2-b69e19140a07">mathjax</span></span>语法存在冲突,所以还需要修改源文件。</p><p id="9194b616-f98b-4b69-8d37-d4f8506ce897">打开<span id="e933c4b8-8ddc-4f73-85fe-f523a60d4848"><span id="5e0414ae-19e3-4d00-afa9-8514764a424f">/node_modules/marked/lib</span></span>中的<span id="4149e016-05e9-46be-88d7-763907b34fc2"><span id="627aa9fa-0a0b-4efd-8513-e967806f7329">marked.js</span></span>文件,第539行的<span id="185ba812-1ae1-466e-ac84-afe7adbc0f92"><span id="5e2b098b-1bc5-4002-9ca9-e9b107053b1d">escape:</span></span>处替换成:</p><pre id="67c07eb4-a711-4228-bb34-7bc0c976290a"><code id="502bdeed-0ffb-44a3-8b4c-43d781711a23">escape: /^$[<span id="b6cb0535-a053-49e6-a98f-7bd86dac9b83">`*\[\</span>]()$+\-.!_>])/</code></pre><p id="d96d749a-045d-4708-b1c1-49836f141fee">第553行的<span id="6edbaaea-8d6c-4c82-a7df-9c5cc140c513"><span id="f0bfd592-d7b0-4fea-a58a-c63a56736b59">em:</span></span>处替换成:</p><pre id="b5a9875a-16ff-44bf-9f0c-4d3b95eaba68"><code id="d9f42eb7-5c9b-451e-b2d3-eb27394a5ac0">em: /^\<span id="fd2b2b6a-2e35-457f-85ca-9060a9afc8f3">*((?:\*</span>\<span id="230be4b6-2bc8-478e-8755-1b675b970263">*|[\s\S])+?)\*</span>(?!\*)/</code></pre><p id="d94e57d6-2e1e-4732-a965-edbee092ed55">这时在文章里写数学公式基本没有问题了,但是要注意:<strong id="26def030-02ad-4c01-8f70-9f47e5f84ed5">数学公式中如果出现了连续两个{,中间一定要加空格!</strong></p><p id="f9b74958-798f-4bf6-a0f6-6dde1e1bd4a3">举个例子:行内公式:y=f(x)y=f(x)代码:</p><pre id="6f48486b-2a9b-4f8f-be71-9ee9ffb3057b"><code id="a44abe30-0c8d-4e1e-ab62-ec6e86bc0476">$y = f(x)$</code></pre><p id="4d27b4b8-05ab-4eb7-a197-b951e75d66c9">行间公式:</p><p id="2e32cdec-9243-4f6e-8eff-68243b59717b">y=fg1(x)y=fg1(x)</p><p id="08c9a2d5-fc32-49ac-a188-1ffd88be3121">代码:</p><pre id="8540a485-314c-40c8-b32c-a59371095fd3"><code id="fb745898-8e1f-4c4b-8d61-c27a87d977b5">\\<span id="ebbc9316-9603-4ce6-8b8d-581dce182394">[y = {f_{ {g_1}}}(x)\\]</span></code></pre><blockquote id="f99a8779-6b8f-4e4b-95ef-aa2928cdd17e"><p id="22973c4c-d115-432e-8a55-0c1f2d637d3e"><span id="6784a881-83da-4ef8-99d6-d8a46db942d7">注意上面花括号之间有空格!</span></p></blockquote><h1 id="bf2cbaf3-9024-4f4f-b9e0-89602822ad3d">2.5 增加建站时间</h1><hr id="7e9f4aad-a45b-432e-8c57-c8ba44cc746a"></hr><p id="7928cf14-faf5-4bb8-a181-8617b30ba546">修改<span id="86f6a8cc-33ea-49c4-8d96-c46cd90f8d12"><span id="38ca5c53-59e0-469f-ac2f-2f0c1fee23e2"><span id="7ec21153-5b01-4fac-809f-99454730956a">/themes/matery/layout/_partial</span></span></span>中的<span id="b409e13c-305d-487f-a9e0-a5c494b0e95b"><span id="90f4fbca-1bcd-48bb-bd54-6bddeb257749">footer.ejs</span></span>,在最后加上:</p><pre id="4900a921-61b4-4982-9893-4ba7d5998c2a"><code id="0fb47117-97da-48b2-afcf-8f39f91450dc"><span id="539e5643-d35e-4edb-9033-b58238cf66f4"><<span id="37351161-bf1c-4db1-965d-76987008c364">script</span><span id="54e8bf9d-1027-4479-a6b6-e8283c5b20e1">language</span>=<span id="807fc2a2-3bdc-4f99-b000-9bffdb3d8113">javascript</span>></span><span id="f9e97eb1-9932-4f0e-9b1b-9f00e50cfc6e"><span id="a0cbf7fc-acb9-4894-afb7-6992ab37bcd7"><span id="2154db89-7434-4453-aba2-e999a59457c9">function</span><span id="4f479754-d895-4e5d-9e91-359e63af0e0e">siteTime</span>()</span>{<span id="b79a4331-e55c-4b64-993f-e3a6a3abf892">window</span>.setTimeout(<span id="b7eaeaf2-3c54-4b2d-ab13-8ccfb7419095">"siteTime()"</span>,<span id="9acf763e-7fbc-429b-8ec1-b85feb990448">1000</span>);<span id="f192bc94-1231-4ca3-999e-9caf1f116610">var</span>seconds =<span id="804341f5-15c9-4efc-b090-f641167a0f8b">1000</span>;<span id="97f9ef69-e0e5-4761-a6a7-51e49b60d0b7">var</span>minutes = seconds *<span id="720defb3-9b96-4399-91b2-dba1b1f9c96a">60</span>;<span id="b9b9ec01-4941-4807-99e9-8a2ac5cee3b8">var</span>hours = minutes *<span id="1c299861-761a-4635-9108-b8a5eab3136a">60</span>;<span id="b511cf83-27ad-40e3-ad79-5aa07e5cebed">var</span>days = hours *<span id="1f734379-aaa2-41cf-ad60-63c8ffa4cb23">24</span>;<span id="f2762df6-9d09-4ea6-9de1-ac1ffb82f466">var</span>years = days *<span id="373a2003-a61d-448f-a2d8-b049eb4cfc7a">365</span>;<span id="ee6e1603-0f7f-42f3-abf0-ea7d9ffa4fc2">var</span>today =<span id="b749cc87-da06-4b25-85a8-ec65f85fd90c">new</span><span id="4f03ecbd-21b1-44d0-a2ce-d29ba7714e46">Date</span>();<span id="62e631a5-804a-46b9-83a9-436d7c4c0652">var</span>todayYear = today.getFullYear();<span id="9eab9253-d260-4ded-b10b-4adb00cce541">var</span>todayMonth = today.getMonth() +<span id="60613c7a-bcf1-4b50-9811-3964298d39c5">1</span>;<span id="da64ffb9-2bc4-4bfe-9b12-8794a80a4c04">var</span>todayDate = today.getDate();<span id="26699eeb-3982-4cbc-b783-eb3284c5fc49">var</span>todayHour = today.getHours();<span id="e1348522-2d15-44a8-b8e5-1f4ace99126a">var</span>todayMinute = today.getMinutes();<span id="e896210e-4d31-4690-b067-3be4d9757fe6">var</span>todaySecond = today.getSeconds();<span id="81e6ae8a-ceb1-423c-86df-8a4a5137b3a2">/* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳) year - 作为date对象的年份,为4位年份值 month - 0-11之间的整数,做为date对象的月份 day - 1-31之间的整数,做为date对象的天数 hours - 0(午夜24点)-23之间的整数,做为date对象的小时数 minutes - 0-59之间的整数,做为date对象的分钟数 seconds - 0-59之间的整数,做为date对象的秒数 microseconds - 0-999之间的整数,做为date对象的毫秒数 */</span><span id="93b6f2d5-750e-4684-a585-1ecbfd6f215e">var</span>t1 =<span id="43ac0f58-0103-4fe3-905e-eeb349118824">Date</span>.UTC(<span id="f977dc14-a809-439b-ac2e-739ef8b0316f">2017</span>,<span id="1d83e188-619b-4fda-8547-6414a6df8902">09</span>,<span id="9748fb1c-adec-4272-9aa5-93941cb78b41">11</span>,<span id="2876e704-dc90-4360-b9a0-e85dc49a6197">00</span>,<span id="2fd882b1-d043-4f23-97cf-6d505c8f6c89">00</span>,<span id="3d03e805-6cb1-4186-b8a7-0337680c17f9">00</span>);<span id="53b21d36-6bdd-49d8-aa2f-41d121cd1ade">//北京时间2018-2-13 00:00:00</span><span id="6dd5fc0c-2874-4601-9804-18d6886d0fdb">var</span>t2 =<span id="f5567f35-51e6-4b5c-92d0-f86f18e1ee27">Date</span>.UTC(todayYear, todayMonth, todayDate, todayHour, todayMinute, todaySecond);<span id="39d71a5c-dfee-4337-963a-cf4f7f0770e2">var</span>diff = t2 - t1;<span id="7495e224-2de0-4291-9555-944098ab7ef2">var</span>diffYears =<span id="eac69d5d-a364-469e-a5ad-1aaa66fbfd3c">Math</span>.floor(diff / years);<span id="f07e2c37-85a5-494e-a44e-89cf14789472">var</span>diffDays =<span id="94ceac07-0756-4c3c-a694-b5f605b5854a">Math</span>.floor((diff / days) - diffYears *<span id="591c1652-5f31-41db-a51e-52360cdb6ca7">365</span>);<span id="ce27df57-e0a8-4d7d-8c2b-babc9d022120">var</span>diffHours =<span id="8d3b54e7-4f67-4e44-b5c2-e0b54fa4939b">Math</span>.floor((diff - (diffYears *<span id="595f42c9-bd62-4973-8e0b-ca72deed8564">365</span>+ diffDays) * days) / hours);<span id="3ce8d8d0-2517-460a-9954-4adf38dbeaee">var</span>diffMinutes =<span id="9e91b15c-94ad-4644-9f32-3234367eb7a7">Math</span>.floor((diff - (diffYears *<span id="1cacd149-7feb-4dd1-a622-33254463e678">365</span>+ diffDays) * days - diffHours * hours) / minutes);<span id="04b6c4b7-8ed5-4f9f-a3ac-e347855d7e95">var</span>diffSeconds =<span id="b610d6c8-9ab7-4e8e-b207-20379c1f5b83">Math</span>.floor((diff - (diffYears *<span id="16bbaf6e-d3d9-402e-8670-470da20a24fc">365</span>+ diffDays) * days - diffHours * hours - diffMinutes * minutes) / seconds);<span id="8f7bde32-2275-49fe-9367-5d44df004165">document</span>.getElementById(<span id="a0e5af23-5f03-41b7-872a-6622da5ccbae">"sitetime"</span>).innerHTML =<span id="3f4f7b39-18a1-4a02-80e6-60dc9a467800">"本站已运行 "</span>+diffYears+<span id="61be2f7b-7f73-43be-ac9c-9ff7408dc5e4">" 年 "</span>+diffDays +<span id="485bb99e-eff6-4fd6-ad94-eb57e28e720c">" 天 "</span>+ diffHours +<span id="b151dd93-b28f-45b7-beb6-771ef7425d18">" 小时 "</span>+ diffMinutes +<span id="5f080b8a-e9bf-4a12-8a36-ddf55ed31aa2">" 分钟 "</span>+ diffSeconds +<span id="c7151759-6665-448a-af62-929639833e3e">" 秒"</span>; }<span id="177f0fc1-b95c-4d8b-a0ee-d8ca734b67f1">/*因为建站时间还没有一年,就将之注释掉了。需要的可以取消*/</span>siteTime();</span><span id="cb61671e-49ba-4913-92ac-059e24f2d8d3"></<span id="13c038c6-b90a-4270-af1a-ec74381c61b9">script</span>></span></code></pre><p id="3f176506-eda5-4942-ac31-e8527c088a2f">然后在合适的地方(比如<span id="8abbabe6-e5fc-44e2-913d-983c8af705f9"><span id="1b537e2d-b536-4a38-b740-f13fff1cc585">copyright</span></span>声明后面)加上下面的代码就行了:</p><pre id="6bcf35e1-1240-4d18-a488-aa7f78ee5009"><code id="484cec0a-0d3e-46e9-83f4-72c0d32c849d"><span id="d7d59b02-e752-4ccd-9c97-7404b43dfb53"><<span id="7cf00c25-2b33-401c-9ae7-94d465b4a900">span</span><span id="1c40357b-883f-4ba9-802d-393f2f3f04d3">id</span>=<span id="532e2ab8-391a-405b-a241-4324919afe0d">"sitetime"</span>></span><span id="2d8cb400-0473-43ae-836f-9cef2d03e7d0"></<span id="853297ad-adf8-404d-af96-508c3c6c8cdd">span</span>></span></code></pre><h1 id="c52334b9-6977-4a07-8b15-2714cf3d8dd2">2.6 修改不蒜子初始化计数</h1><hr id="58dc7a99-4c2a-4143-80ef-de76ffdb0dba"></hr><p id="0490afe0-7718-474d-9a8d-c321606cce2e">因为不蒜子至今未开放注册,所以没办法在官网修改初始化,只能自己动手了。和上一条一样,我们在<span id="cad505fe-954c-4377-90f7-fba46ae6aa7a"><span id="056fc10a-8ca9-40b3-b0bb-f391c59e59d6"><span id="d75814c4-64c2-41d4-812c-82d0544b60ed">/themes/matery/layout/_partial</span></span></span>里的<span id="a1151dde-0722-47d1-96cb-b1636c8e1504"><span id="7739ce82-380d-4707-a6e7-824377f7ca4b">footer.ejs</span></span>文件最后加上:</p><pre id="0a8f7a42-7c6d-45b2-ab61-36734b55b77d"><code id="345b19a0-ef65-419a-894f-3d639e871899"><span id="1125bb88-af54-40aa-9311-775b4f7c4e8c"><<span id="d1c90978-f8a1-42e8-86fe-586986669c7e">script</span>></span><span id="7f1cde96-7350-424e-a681-d2350417b1b1">$(<span id="3c3ad223-c40d-48d0-839a-4daaa8ed251c">document</span>).ready(<span id="62c3cd01-e97a-41cb-a4f1-56306d57bec0"><span id="98d0e628-c632-4515-b8ac-2d1289e3de57">function</span>()</span>{<span id="70a073e4-87ce-42d2-9956-d13feacf97bc">var</span>int = setInterval(fixCount,<span id="0475574c-dc6d-4c21-958d-05dc07673038">50</span>);<span id="dc3870f5-71e4-4b41-90d0-9ac821911494">// 50ms周期检测函数</span><span id="67e115d8-8a7e-4337-878f-a048d377f0b1">var</span>pvcountOffset =<span id="5029991f-0bdc-4b70-bc43-bc60bc09da42">80000</span>;<span id="08b6bcf9-b419-4c8d-b857-f3d4d96f4f41">// 初始化首次数据</span><span id="b92bcb80-dac3-4d31-bafb-977d817883c0">var</span>uvcountOffset =<span id="57274459-30aa-4f13-a1e5-67ca58402910">20000</span>;<span id="590649ed-e254-499c-87f9-96dd903c15fd"><span id="8716c895-9d78-401c-b700-c872e6e6cfc3">function</span><span id="2328dad1-4167-4425-9abd-79ce82a7f5fd">fixCount</span>()</span>{<span id="87a21f06-aa14-4cf6-9882-9f346c1a4563">if</span>(<span id="0a136dc8-b4d8-404d-93d3-761268c09876">document</span>.getElementById(<span id="6ce95a27-0bac-472c-bf92-89c3525a3db4">"busuanzi_container_site_pv"</span>).style.display !=<span id="938be72a-4a13-49a0-af27-ed126bd0751d">"none"</span>) { $(<span id="0f2a477b-19cf-4cca-b28e-1976316c47a0">"busuanzi_value_site_pv"</span>).html(<span id="fdd1c0e5-b731-4342-be67-35a2517c6f43">parseInt</span>($(<span id="c5cbb3a0-be1f-4c87-9c65-401d9088b0b3">"busuanzi_value_site_pv"</span>).html()) + pvcountOffset); clearInterval(int); }<span id="f9c6a70e-a90e-4e8f-9362-c391d97f2089">if</span>($(<span id="f66f6003-f08d-4f75-8847-c010c8f8754c">"busuanzi_container_site_pv"</span>).css(<span id="a9e7f171-1df1-49d1-9e07-c9ec817747ed">"display"</span>) !=<span id="15efdf4b-f886-414f-b264-6346827a0286">"none"</span>) { $(<span id="ee5d62df-a6b0-4d31-a577-80e27c89e919">"busuanzi_value_site_uv"</span>).html(<span id="e516bc2f-7523-4872-9ee7-94bae9d38e93">parseInt</span>($(<span id="bf526a98-62bc-4d8b-b368-5fb27c9f296b">"busuanzi_value_site_uv"</span>).html()) + uvcountOffset);<span id="ecb77fd4-284b-40a8-8aae-163be3688960">// 加上初始数据</span>clearInterval(int);<span id="8ad9a400-9953-481a-bd35-dce7a008e2c4">// 停止检测</span>} } });</span><span id="24802900-eb9a-4efb-ad40-2a4d850ca72c"></<span id="0d81eb81-b22d-4478-a8f3-40f7502b3c07">script</span>></span></code></pre><p id="677ce69f-1d4f-4d51-9468-5aa773423408">然后把上面几行有段代码:</p><pre id="6b680b64-525a-4a45-8ee8-ca4e24054931"><code id="29ef2f09-10f7-4034-8d4b-5e06cc60e1aa"><span id="d5f1761d-3e6c-45e2-a319-aad49ae8f45d"><<span id="d7b4cf5d-60e9-4de9-9f0a-f7dae8477bd5">%</span><span id="b363462f-5825-4323-869a-a48b6b1e678b">if</span>(<span id="51995169-8f6f-44c5-b0c7-4ee7d5131515">theme.busuanziStatistics</span>&&<span id="1b09fe56-9dd1-4bde-9cf0-c3a3e44d37e4">theme.busuanziStatistics.totalTraffic</span>) { %></span><span id="91a9cb30-20b6-44bd-a10e-c9e4e6212d53"><<span id="88041ad4-c6d9-4ff8-97b0-c14c5c07fb33">span</span><span id="c90e5f71-eb94-447b-9f75-0438ffa22acf">id</span>=<span id="054bb1f7-5a4b-46db-95e7-fb855bc50c2d">"busuanzi_container_site_pv"</span>></span><span id="9cde4573-f11f-433d-89fd-54a90045e36c"><<span id="ea019cdd-698a-4a8c-8b23-098d918bcf95">i</span><span id="2ec830c7-5b78-4ec8-860c-f66624b1d481">class</span>=<span id="bd0d800e-4042-43a1-8192-6f61504b2991">"fa fa-heart-o"</span>></span><span id="ec3783fe-98b4-42a7-9425-d22733a0dc09"></<span id="61c53917-7d0f-4ed7-8696-c0c26a206a42">i</span>></span>本站总访问量<span id="db25d286-9801-4523-be0d-f41f51c1c8ae"><<span id="282ada29-2ecf-4266-a6ab-ee797e609e76">span</span><span id="4cb75fee-5708-4c55-85cb-6fc6a0550805">id</span>=<span id="f24c9087-0354-47e5-ad90-76cab67d1438">"busuanzi_value_site_pv"</span><span id="8d9f631a-5f8c-4241-afff-866ce2a9fa13">class</span>=<span id="48a30cfc-d901-4319-8e7f-03b693abe47e">"white-color"</span>></span><span id="f960f433-ea4f-42af-9d3d-4277f8f5208d"></<span id="9892558c-7d86-4bfc-b673-3400693c52e3">span</span>></span><span id="28de9a15-a033-4c04-a624-a27008d585d8"></<span id="de65fca5-9bb2-4d0b-a657-9a6a07198cb8">span</span>></span><span id="6bd8e754-1622-486e-8bdb-b07880bb052d"><<span id="4e2d91ee-9f63-4f23-b647-52e13a9a4e45">%</span>} %></span><span id="87636767-71bb-46ac-b6e4-3691c2c67209"><<span id="a111d69e-9fdd-4c49-a47b-25af1f2b2731">%</span><span id="687310d6-743c-4fea-b671-86336d04afaa">if</span>(<span id="b21b3ff1-8938-4656-ad32-fdcd6c0858fc">theme.busuanziStatistics</span>&&<span id="902e9a50-bb06-437c-954c-7e83aae86c85">theme.busuanziStatistics.totalNumberOfvisitors</span>) { %></span><span id="cfe754f2-d3c0-4808-bff3-3482d46a8da9"><<span id="a56356c9-8dec-4e73-933d-914a92e40422">span</span><span id="fe17bfe1-bef2-495c-801f-a7793bcb8c21">id</span>=<span id="c513dc90-2055-4519-a32a-a4ef8ef2ca45">"busuanzi_container_site_uv"</span>></span>人次, 访客数<span id="316c683a-6eed-47ec-b483-1d8e6bb94978"><<span id="1688dd70-7916-491a-b1ae-f22b66f6177c">span</span><span id="0b6f5c7d-5b41-4c4f-8ac7-61415da99648">id</span>=<span id="8296dfdf-99ea-4607-a36c-59d75c6fec0e">"busuanzi_value_site_uv"</span><span id="13cf10eb-cdc4-4eca-a8c9-0cf3b31aa630">class</span>=<span id="57062af0-3782-4e72-80e6-eb8cf328f016">"white-color"</span>></span><span id="a541b449-35f2-4dd9-bf4c-333445d1991e"></<span id="f302c3c3-6b21-478b-9453-e5d401ea0cff">span</span>></span>人.<span id="7a91ea20-d8e3-4861-b035-7971c6c1d5f3"></<span id="a285a012-250e-41c3-a8ef-af15380cdbd6">span</span>></span><span id="da26e5b1-e181-463d-ba37-18e3de5ab12e"><<span id="63a3d223-7b28-4404-b1c6-7d9cc44c534a">%</span>} %></span></code></pre><p id="30b4e288-4604-4063-a513-8a1885a7bbf2">修改为:</p><pre id="1dfae9ba-3a1d-4c28-8b68-08778240989e"><code id="8d294957-5dab-471d-b24f-f35a04912708"><span id="83e67a04-e40f-4633-aff0-507117c1ac88"><<span id="1b3eb651-2dba-4fdd-be06-9070d63f3c76">%</span><span id="5a44510c-0f83-4ef5-a76f-097eaf27a291">if</span>(<span id="81b0c67a-4b77-485d-a640-135aad3b0bf7">theme.busuanziStatistics</span>&&<span id="f36565bd-87d3-4b9b-9564-32d096d83faa">theme.busuanziStatistics.totalTraffic</span>) { %></span><span id="12e1902d-8e4d-4dc9-a30a-d43ed16a195d"><<span id="0a74aa34-5897-4324-8d97-a43a3b3c799d">span</span><span id="3cf8406b-5a2c-49fc-ab2e-fa6f5dc6d33e">id</span>=<span id="c89757a5-f5b8-45df-83e5-87795f45ff3e">"busuanzi_container_site_pv"</span><span id="387f0d37-b85e-471e-9ca8-8e2ca6414601">style</span>=<span id="cd9d7c33-a62a-4e2e-9483-e64890a17767">display:none</span>></span><span id="d6610587-c8b2-4d5b-8e57-ad07c51ecb0e"><<span id="713336c8-56c9-4731-aa43-ee7f06a21039">i</span><span id="50baf998-46a3-49bf-bbc9-0cba506b9b2d">class</span>=<span id="d47d8274-5a6e-41ca-9fbf-e84367d02804">"fa fa-heart-o"</span>></span><span id="c5c5707f-fd61-4945-8536-6123afb85967"></<span id="28b0e7eb-201c-4d5a-9967-8e558ef70b0c">i</span>></span>本站总访问量<span id="7d543daa-19ca-46de-91ed-3169f64c3dac"><<span id="68288db5-0ca4-49eb-88b1-a84c0a570f8d">span</span><span id="8dd09ee0-b420-49b6-aa26-d8ac144d2f12">id</span>=<span id="eb43a9db-b3cd-4321-a870-7ffe85e157ac">"busuanzi_value_site_pv"</span><span id="43f13ec7-9bb6-4555-8311-e9b05851a1f5">class</span>=<span id="6dd351a5-dcfd-4bbf-aec1-9d302b9526cb">"white-color"</span>></span><span id="19feb599-9012-4c12-bfb1-4afa90f0b35d"></<span id="fc2dce5b-128e-428c-b777-9e70739014ef">span</span>></span><span id="9c0fcce0-d9ad-4840-a4f9-6e2eb00627a3"></<span id="c034d93d-0676-440b-8c28-15ef727f821f">span</span>></span><span id="f7d9337b-b0ca-43e4-b8b2-fa433d50d5e7"><<span id="4a7f3b50-f893-47fe-b39e-7b0624728277">%</span>} %></span><span id="c5c699b2-35bd-4333-87c7-17f4ceeb0f81"><<span id="55ae60a6-84d6-4902-970c-5ac52a74e260">%</span><span id="839b5aca-bc20-46ee-863d-7e290920b65d">if</span>(<span id="601f4f7a-7ff0-4b53-9c4a-58cf30f5d0bf">theme.busuanziStatistics</span>&&<span id="0666b28a-908d-417b-8a0d-984813312012">theme.busuanziStatistics.totalNumberOfvisitors</span>) { %></span><span id="b2099211-ff4b-4c69-a1d5-6889ca244d51"><<span id="c6f2d9a1-0f21-446d-a7a3-23f3c606dc7d">span</span><span id="0c17fd6f-68cc-4172-8d0c-023d3872b444">id</span>=<span id="be3a7554-6f2d-4179-8631-201e3867c9a5">"busuanzi_container_site_uv"</span><span id="6b60a406-8684-4258-b488-09c495b46dfc">style</span>=<span id="2873599b-340a-4afd-b4d8-365e7765abf5">display:none</span>></span>人次, 访客数<span id="eed570dc-4527-4230-a348-381d93738fbe"><<span id="b4af7a8f-9745-40fc-b79f-117701d92ea5">span</span><span id="d81b3bcd-59b6-4ce9-b571-7971d9df17c4">id</span>=<span id="56d9334a-1872-469f-bcd2-1348b51e2770">"busuanzi_value_site_uv"</span><span id="c68212d5-4ede-49cb-ae19-de0fd2030228">class</span>=<span id="af8c3165-dea2-4ac7-b063-d9d833f5e898">"white-color"</span>></span><span id="294e8220-4b93-4c75-a08b-cec83f14cd05"></<span id="0a5c5d13-8725-43eb-bc9b-393583d4054d">span</span>></span>人.<span id="c78542d6-892e-4161-8e1f-b98e6796ffec"></<span id="53c1b729-827a-400d-a721-48d84968bff4">span</span>></span><span id="8b91fd91-07e9-4958-9f75-54730b9e2ed2"><<span id="40252a31-e997-4057-b496-add1b9a25d03">%</span>} %></span></code></pre><p id="0ea56045-fa1e-44e8-999b-14f85e84082b">其实就是增加了两个<span id="0a36173b-fa4c-4c2a-92a2-2b6552a254de"><span id="883cb68b-feff-452f-83f7-43bdc45d0939">style=display:none</span></span>而已。</p><h1 id="e6e5b967-a39a-49ab-944b-fcb82b9c8a7a">2.7 添加动漫人物</h1><hr id="01a39165-86a1-4501-8e8b-85fe0f206e0a"></hr><p id="0683130e-f443-4e38-b4e6-c933b1f9589d">其实三步就行了,不用像网上有些教程那么复杂。</p><p id="2714696e-1156-424e-98ab-b20d90dee82f"><strong id="d8b0e7c1-148c-4d3c-945c-992085206c0e">第一步:</strong></p><pre id="1b35e3ea-1cbf-4308-a1b9-5d9b39c83438"><code id="27d7c7d8-a813-4759-a3bd-04fd0099c060">npm<span id="40ed6d56-1260-4710-ac8f-720a74b6291a">install</span><span id="7f8d9d75-415d-4ead-8f0d-0306b0813551">--save hexo-helper-live2d</span></code></pre><p id="edc5a34c-2f46-4c7f-84da-158d9568656e"><strong id="ba41210e-6de9-49bf-aad3-d4344e04373d">第二步:</strong></p><pre id="72dd7df4-e564-4b7a-befd-a5004d7e5c7f"><code id="90d3ec75-4031-43d2-8836-491f9fa5f565">npm<span id="04017125-dabd-4465-8381-09ba07d6c8b8">install</span>live2d-widget-<span id="e5866ab6-024f-4199-9fcf-2d9735a4eef0">model</span>-shizuku</code></pre><blockquote id="63b478cf-507c-40a1-a2de-b08c513412bc"><p id="c63e9464-b58b-4e98-9995-f42a5bc23e34"><span id="d9fd6044-befc-4549-a241-32fe8a08a83a">这里的动漫模型可以改,只需要下载对应模型就行了,你可以官方仓库去看有哪些模型,下载你喜欢的就行。</span></p></blockquote><p id="760ca8da-654a-4592-8010-fff1352d2b0b"><strong id="04ca2d7d-ce68-432c-bdd5-e2351c2ebea6">第三步:</strong>在根目录配置文件中添加如下代码:</p><pre id="cc99ba44-52ae-44e6-8fde-f1e00f1953f4"><code id="54d73777-e507-4bee-83de-5f8e823c00d8"><span id="800d9854-0fbd-4405-b653-ec09be4da270">live2d:</span><span id="703a99b9-26ca-4a23-b658-c1188a0e9588">enable:</span><span id="a6f34b8d-d50e-49c3-91b6-591de9201ca1">true</span><span id="9db0f001-9808-4799-82ab-77bab80a01a9">scriptFrom:</span><span id="a66d9379-f095-4a32-a9e1-312b39ee71a4">local</span><span id="1c2978e5-12a7-4e9d-ad6c-9737fc23577b">pluginRootPath:</span><span id="e834bf0a-e46d-4720-88c6-d5cb2190b926">live2dw/</span><span id="7876a96b-ee45-4fdd-a12b-61be9297ea79">pluginJsPath:</span><span id="4de0f3ad-e4c6-470d-b45e-7ff7881bceb6">lib/</span><span id="2be8bfdd-f3f2-429a-9117-e53b56c260c2">pluginModelPath:</span><span id="194c3f93-0854-4fc7-9f23-3a235e42a719">assets/</span><span id="01e1b8e3-b211-4faf-95e8-db0172eee07a">tagMode:</span><span id="eff3f055-4ef6-48fe-9fc4-949f7746a535">false</span><span id="79278e63-6e86-46f5-949d-b25d0ea628c4">log:</span><span id="68ff47dc-2562-4ca8-88e6-1d5e14dbbc15">false</span><span id="bf6d5251-ff4a-467e-9ada-370f74d640bb">model:</span><span id="2c12c216-4fdf-48fc-b826-6e30693156a2">use:</span><span id="ee154992-5cf5-49f8-8f90-21f7226e2d78">live2d-widget-model-shizuku</span><span id="3a3ce279-3c22-4b42-9542-f1b2f576994c">display:</span><span id="69a19f01-9ccf-4490-b715-9148d3c9176c">position:</span><span id="5a92a0b6-34d4-4de1-8e13-59e948df5795">right</span><span id="818fd900-7043-47b9-b823-b186a5be97c2">width:</span><span id="1a67c600-633f-4e75-a699-e3f53114b718">150</span><span id="446ab467-7628-4508-b5fc-3dc14bcd7f99">height:</span><span id="3fd88590-46da-4a16-af50-70cafc153815">300</span><span id="8c5b481a-aeb1-4d05-986e-59bb36129ba4">mobile:</span><span id="642be238-c0cf-4296-a27f-fdf1a669e933">show:</span><span id="84079843-815a-4461-9907-0f2efd6a3a9b">false</span><span id="9712f2e6-5576-422a-a6a0-467d4f5d4fda">react:</span><span id="0664a651-1918-4307-81e2-0a019766dd78">opacity:</span><span id="97744fbf-b6e5-40ab-aadc-90e207a43d1d">0.7</span></code></pre><p id="21018dd0-a2d6-4a11-89ac-ea1120126d33">然后<span id="958449c5-3da3-49f1-a258-60175d196118"><span id="bdd5e07f-142d-4a5d-8e08-c2128752eb11">hexo g</span></span>在<span id="e79f1b6e-08fc-4dbd-9686-c19a54643c3d"><span id="ec4f7d5f-721e-4c46-8565-374e82082760">hexo s</span></span>就能预览出效果了,但是有个注意的地方,<strong id="cf61fb8e-b9ba-4b15-ac0b-74e3bf8b9e37">这个动漫人物最好不要和不蒜子同时使用</strong>,不然不蒜子会显示不出来。至于解决办法后续更新。</p><blockquote id="992f8689-6fcd-4367-8347-c04b9944a79b"><p id="e7dcc096-a3d9-4982-b0f5-33504cfb12cc"><strong id="bc7cdbb5-5d0a-48ba-8e9e-d067d0df4c29"><span id="f1e360ac-1474-49a5-b15a-787b1aa4f017">解决动漫人物和不蒜子不能同时使用的</span><span id="b02bebed-8171-4018-804e-cd231802a130"><span id="ee18cde4-ee28-4da6-b727-66610e2fa298">bug</span></span>(2019.08.11)</strong>:</p></blockquote><p id="32b195f8-5789-4f3a-8399-b79b7369b4bb">打开<span id="33887d2a-9505-4e4f-8298-d87a17cfdc58"><span id="e6891b2f-2a22-4742-bd70-a6879ca7674c">themes\matery\layout\_partial</span></span>中的<span id="e5833fe3-ef1d-49c6-a9b6-2d9c7481e15e"><span id="b9e55a1b-7fd1-4766-b794-1f556423b525">footer.ejs</span></span>,将本站总访问量和访客数的代码改为如下:</p><pre id="0557dc1a-02d6-456f-8a5d-24b5a1ba6610"><code id="2b87add5-c465-4ed4-90a1-f14628d19661"><%<span id="6bcc371d-cb7a-408b-a45f-661831dac15f">if</span>(theme.busuanziStatistics && theme.busuanziStatistics.totalTraffic) { %><span id="e465146c-69cb-4384-b677-6bb4d2e4128e"><span id="f1292274-754a-4cc4-b932-e89c557cceeb"><<span id="965fe204-03b4-4682-948b-0bcf63080e46">span</span><span id="f737995d-1e14-42c5-ac78-913a755f623d">id</span>=<span id="8c8026fb-2cd1-48f4-aafd-443ad87ffe01">"busuanzi_container_site_pv"</span><span id="a80715ed-58d7-4e37-983a-994851aacf9c">style</span>=<span id="3d85f2b5-8f73-4dc3-ac3c-d292def99d8f">display:none</span>></span><span id="0ce7db82-1653-4b64-85c0-34b1451ae36b"></<span id="ad3c9799-56d2-4792-9f76-e607ff55bf84">span</span>></span></span><span id="221d715c-1be3-4464-8a56-00a8ca3f2c2b"><span id="561fbb29-234b-4358-8922-34e7041048bd"><<span id="edef4328-67e6-4b00-b571-5525b22c81bc">i</span><span id="b7070966-bf34-4224-97e5-88a95118d0f1">class</span>=<span id="94835566-2604-4036-a12e-0921f93bf449">"fa fa-heart-o"</span>></span><span id="73cb0f71-a7de-4c66-b45f-18a889e79609"></<span id="50dda265-38ac-407c-a447-5fae36e7c7b0">i</span>></span></span>本站总访问量 <span id=<span id="3a21f64d-2b76-4d68-86ea-1e29a3c1a5d0">"busuanzi_value_site_pv"</span><span id="ca93084b-b1a5-443c-8cc1-4020a82ae11e"><span id="3bf4fe04-865c-493e-93b2-a7976a1dc131">class</span></span>=<span id="b58cd741-cd3d-4d2e-9d29-0bdf254e77d8">"white-color"</span>><span id="66b5b5f2-338e-466b-94be-bbbad5a6d53a"><span id="b802ce07-825f-4a85-9fb7-5c215de4729d"></<span id="19be9f0f-bb9b-4ebd-8c56-010a1c8c0775">span</span>></span></span><span id="97e11855-d8e9-450d-ae84-8e162ef8e897"><span id="9ba26e95-a2a1-496b-94cf-34ead0973aaf"><<span id="85168779-fb37-4247-a062-edb18d0220c9">%</span>} %></span><span id="a4e1c71d-1bbe-4f0c-af11-a89933a52af2"><<span id="1029af49-d714-4099-8348-302df742cc6f">%</span><span id="8c4de723-0686-457e-b9c3-990f22d60ead">if</span>(<span id="cad9f179-ce2d-4f73-ab14-ad75897f9ab1">theme.busuanziStatistics</span>&&<span id="0fa9d30c-c6c2-40e8-8cc8-abc6b7403f02">theme.busuanziStatistics.totalNumberOfvisitors</span>) { %></span><span id="2e689873-5ef6-46ce-9d61-5590bc633c40"><<span id="923a7429-a221-4422-be33-eccdbe91501d">span</span><span id="557b0722-d29e-4642-a070-b9b4d83710d2">id</span>=<span id="b401868a-0ce6-44ba-afbc-400b2acf5043">"busuanzi_container_site_uv"</span><span id="d935b045-e556-4a73-bf5e-f37b9ec73f23">style</span>=<span id="0777bee8-42a1-4d40-8bf8-a4c17db06b1c">display:none</span>></span><span id="9f4f54be-0a53-4e92-b8f6-d7c64b05a7df"></<span id="108956d4-65a4-42fb-a084-287c35ff451a">span</span>></span>人次, 访客数<span id="61bfa2c5-b382-403c-a988-7b05b8c369a2"><<span id="179a058d-f9d9-4a37-98a7-d2177a9e17f8">span</span><span id="713c46c1-4160-47cf-937c-c8f8d43ac61e">id</span>=<span id="519ee84d-382e-4003-af9b-a7ed0115bb42">"busuanzi_value_site_uv"</span><span id="7906322d-1421-4bbf-9fdd-87240d9f3cf2">class</span>=<span id="b77c4c02-b45a-49b1-9ef7-7964d0fe1a31">"white-color"</span>></span><span id="21a9ea0a-0513-4c14-b452-c1b3cf847a85"></<span id="d2d3e1c5-cbe0-474d-bf53-59df50b8b7e1">span</span>></span>人.<span id="77961a91-6dd4-46a8-b708-140aa84427d6"><<span id="f48bc345-229e-4159-ad82-516eb12ad598">%</span>} %></span></span></code></pre><p id="bace6d5f-a532-48d0-b7fa-1e72542b86e9">变化就在下面两句,将源代码对应字段后面的<span id="2db61d45-ec26-4748-8659-e0fbcd5ae064"><span id="bb985513-bf7a-4569-8b20-f1e471e0dfa4"></span></span></span>写在前面了。</p><pre id="6da8764b-a403-4c78-bcd1-cb91c8b07ee3"><code id="46f9cc4c-9e2c-40af-afbd-536771118de7"><span id="e39c6752-65d6-489f-b7c6-ba5c71a3bc29"><<span id="c81b68f1-0f56-4213-bf70-15de3e54e644">span</span><span id="bc85601a-50e8-4799-920c-a3adc18a2150">id</span>=<span id="e0f06b5e-77c9-4760-be8c-5ec0f661dde8">"busuanzi_container_site_pv"</span><span id="6554fd58-0a92-4fd1-b56b-0f1582e41db8">style</span>=<span id="2efeac90-7341-4e66-a2e3-a524d272e940">display:none</span>></span><span id="9f818f86-b6c0-4b65-b02c-9e194109a504"></<span id="e150737e-a5e1-41b2-845a-cfde18f47b7e">span</span>></span><span id="c6e23329-60f7-4ba8-a04a-09025ca7541d"><<span id="0d7dcbba-6578-413b-b34e-1cbaa049662e">span</span><span id="8b460163-6e30-4f76-bc01-85162fa135f2">id</span>=<span id="990dc407-8c61-458f-8b2b-16c28469e02f">"busuanzi_container_site_uv"</span><span id="fbc0c121-be59-4a62-89f4-3e4410e340bc">style</span>=<span id="cba697b6-e1af-4075-85b2-cd3748da9715">display:none</span>></span><span id="8fddee9e-a882-4b90-be0e-58e27b4d61fc"></<span id="c0f4e770-f9cb-4010-be28-84e077c9c2a6">span</span>></span></code></pre><blockquote id="16eeca5d-abf5-4ffc-b6a2-fc216605be89"><p id="07ada26f-77f5-4d1a-a795-e52391662ba3"><strong id="5cb1ab06-dc0f-49f4-8a9f-e553b8a00ce9"><span id="495ae0b9-f162-4006-914b-046e18b2571a">发现按照上面改了过后,又出现一个新</span><span id="eb7ee287-73d8-437a-acf7-1644d40c379f"><span id="002b1f13-2dd0-49bb-bfab-41c2dc553e00">bug</span></span>:文章头部的阅读次数不显示了,解决办法:(2019.08.11)</strong>:</p></blockquote><p id="fee3dd14-2edd-48ad-bcf9-2fa0cc723740">打开<span id="8046a5eb-444c-4e1b-9de4-4565e468f7cc"><span id="b4b88a6e-913d-4c1a-92cb-b0563ccba890">themes\matery\layout\_partial</span></span>中的<span id="0d8cba94-73df-4f1a-aac3-1df9af004a69"><span id="ee2c8992-f74f-4782-ab81-b1dde4bad031">post-detail.ejs</span></span>,找到对应代码字段:</p><pre id="5ba365f9-5a3f-4d40-abb2-9bf9587974a3"><code id="5b6a3b38-7dd9-4360-9001-4f8825524d14"><span id="df14034a-9a37-4155-9d85-a6c72ff1e760"><<span id="18dcda75-842f-435e-8839-33fa301e0937">%</span><span id="35623cc6-4b2b-404f-b087-640251085974">if</span>(<span id="3afdf445-c2e0-4cce-83e4-c57954242de6">theme.busuanziStatistics</span>&&<span id="5fe4c876-341c-4c9d-885a-3c67a3b16650">theme.busuanziStatistics.enable</span>) { %></span><span id="97a09f49-968d-4e95-a256-44649647596b"><<span id="feea8ba8-4d0f-49ed-81e9-0c605f2877a2">div</span><span id="54cdd091-5c5d-46de-8d2c-5a3da2c554fb">id</span>=<span id="0b569f2c-1721-4ac3-9537-8abb5a4a1b79">"busuanzi_container_page_pv"</span><span id="f3133447-20c9-4ffa-8a12-be63bcc5a1a0">class</span>=<span id="71c46e0a-92c0-4a77-9bd0-c5a33a34c9cc">"info-break-policy"</span>></span><span id="bba14453-ba5b-41d4-b513-fea98a0033d2"><<span id="616d6b27-6084-4928-ba0f-8c669b298c99">i</span><span id="6d338924-d996-4a3f-9d0d-615a3ec078cd">class</span>=<span id="4f7e6cd3-c437-49eb-b80c-dca718ade3da">"fa fa-eye fa-fw"</span>></span><span id="e0c17640-3042-4c01-ab2f-3623a2c34925"></<span id="fded0785-bf6e-44e5-a1d3-9d229e09bde4">i</span>></span><span id="8e407734-6f30-45f6-9344-2c5694c3563a"><<span id="215a2c8e-2443-4238-ba6f-b7f7c637fb30">%-</span><span id="93940620-b72b-4068-87e7-4112d231c994">__</span>(<span id="a8985fa4-bde3-4757-a8dd-066247c43e60">readCount</span>) %></span>:<span id="116a4969-1206-450c-a3a7-5e74ab3bf0bf"><<span id="162a506b-c577-404f-aa3f-ca6ae5089bf0">span</span><span id="83eee959-1439-4a25-90d7-f9afb72ada52">id</span>=<span id="c1028760-d0aa-466f-bf0e-f0ecb4c1bd56">"busuanzi_value_page_pv"</span>></span><span id="462d5514-9161-4dd3-a23f-00386ef424c5"></<span id="99d2cdb9-bb94-4949-95c5-9c04b841cb1b">span</span>></span><span id="46224c6d-b8e5-4373-986a-42aaeae97136"></<span id="0d07f069-3218-4878-8ba5-0e20b1f6f87e">div</span>></span><span id="96b00e8c-7acd-4d89-b2c7-4a34da7b4fc7"><<span id="81764d3d-fbdb-4e2b-b4a5-2810634ef634">%</span>} %></span></code></pre><p id="b8875609-cace-4b3d-a4cf-bc0cedd7cc34">修改为下面的就可以了:</p><pre id="83c085ff-5240-4492-bad8-f1e35c0c0d0c"><code id="a35b2a95-6793-4a19-bb30-22442b2a315c"><span id="d9929ee3-92e3-4456-ac8d-c44164dde43e"><<span id="defe6508-0e60-46b4-8234-5a0ca1b697ed">%</span><span id="a2e48476-d60e-4726-9912-a73ae526e536">if</span>(<span id="e7cc036c-0adb-4267-a17e-69101ea5ca51">theme.busuanziStatistics</span>&&<span id="d6e6896f-feb8-401d-a3f1-39c6e686177a">theme.busuanziStatistics.enable</span>) { %></span><span id="0322ad52-d5b9-41b7-be13-19db0be7d817"><<span id="4f614216-319e-44d3-8091-59ffb808926a">span</span><span id="ed4bbc1d-f318-4d07-a8b6-d5ea19ac88c3">id</span>=<span id="bce6a201-9567-4b42-be13-39ffc777eb8f">"busuanzi_container_site_pv"</span><span id="fb2bae14-1897-4896-a315-e709b6c234d7">style</span>=<span id="78d3e08b-399e-4cf5-9719-fd9ef6358746">display:none</span>></span><span id="a7f0353d-ba69-4a5e-8552-91f4386e43a2"></<span id="fe1f697c-d323-4d87-a69a-d3a99e1c6041">span</span>></span><span id="554d6cf9-6324-45d0-a69a-84d855b66e21"><<span id="120f7de5-45b7-41f2-8e04-9b1ce1bd9244">i</span><span id="747728ed-e0af-4e90-8702-7ec294b13832">class</span>=<span id="42656d19-5bc0-4dc2-8371-67cf371ca523">"fa fa-eye fa-fw"</span>></span><span id="f05147a9-9ea9-4ac3-9259-8f6e1f08826a"></<span id="462f5257-a096-48e0-8121-6aef0e8325c7">i</span>></span><span id="1f0a326d-066b-438e-857a-8d3770f850f9"><<span id="f38fb068-0758-4cc3-af11-afb89e2536c8">%-</span><span id="1b8e6a58-026b-447d-9e82-afdbd8830012">__</span>(<span id="f5a5d370-c7ce-477b-a049-551461918c8e">readCount</span>) %></span>:<span id="ccea6bcc-78d8-466c-863b-684839dfb16f"><<span id="7021f04e-a0e4-44e2-9ee2-203068ae5c37">span</span><span id="27d314ac-15f0-4051-a644-cb3e09749ace">id</span>=<span id="386b00ff-42de-4be0-a9de-e9130b4f5991">"busuanzi_value_page_pv"</span>></span><span id="aec930a9-7c51-4324-bb65-7f7cba6072e9"></<span id="eeba0715-268a-4c84-ad95-6757fd49a46b">span</span>></span><span id="f7789303-f6bd-4ba1-a993-ce64114f0d48"><<span id="eedc5e89-957b-4234-b157-9e3086085e1f">%</span>} %></span></code></pre><h1 id="615cd5f4-1b2d-4f0d-be5f-801021f99758">2.8 添加评论插件</h1><hr id="a0e78167-0561-4b12-9d7d-6e9610b80f91"></hr><p id="35b022a9-0ce9-4dd7-a27d-4bdd519b0dd0">由于这个主题自带了<span id="8123af71-d835-407d-b5a1-3c704f89a862"><span id="42592118-96c7-4707-b114-b18509e0d4dc">gittalk</span></span>、<span id="2a9992d8-ef6a-4a91-b6fd-81cec222da56"><span id="80e3df86-976e-4bcb-8a15-19babbbab968">gitment</span></span>、<span id="d90b3835-d5d6-4844-a6d2-f3488dfa9da3"><span id="d9770d68-2843-4652-aba2-ae0784bdc725">valine</span></span>等评论插件,所以我们只需要对应插件参数就行了,这个博客用的是<span id="28f3e054-ed4f-43aa-b9c3-1c898337f19e"><span id="12d7cf3d-d688-451d-a7af-2af0a051bd60">gittalk</span></span>,如下:</p><div id="500e7c49-611d-4fc7-8356-3ad3ce1a5a33"><img src="https://p26.toutiaoimg.com/origin/pgc-image/73df6602ee084dafb1696b5afab650b0?from=pc" /></div><p id="0b99f37c-6496-429d-8a0b-2e53e69ababb">当然也可以用其他评论插件,只需要配置对应项就是了,不是自带的可以照着网上的教程自己弄一个,类似的文章有很多,可以搜索关键字就行了。</p><h1 id="2b822bf4-780e-45ad-9cb5-61d2b9ce8ade">2.9 添加网易云音乐BGM</h1><hr id="22f71ec3-ce58-40bd-a2a1-b178e09cb0b5"></hr><p id="01da2fde-3b1b-4fc6-95b0-a73ef00ed03d">写文章的时候,想插入一段<span id="3260aafc-9429-4256-ae86-f71b4ee99de5"><span id="90f32c8c-353d-4000-bb60-7f092c7493fb">BGM</span></span>怎么办?</p><p id="0227c082-2c50-4efa-84b9-3781e2124923">其实我们可以借助一些在线音乐的外链播放方式,首先打开网易云网页版,找到想听的歌曲,然后点击生成外链:</p><div id="30ef613a-910b-41a4-9d09-c83645c149c8"><img src="https://p26.toutiaoimg.com/origin/pgc-image/b310be9fd97947bdb12ce728b5d00449?from=pc" /></div><p id="b37dd359-c152-46f8-bfdb-e1625d4a88a8">可能你会遇到问题,比如点击生成外链会提示你由于版权原因,不能生成,那么可以用下面办法(目前还有效,不知道后面会不会失效)</p><ol id="5f8c7ee9-cc27-4c36-a1dd-35225e05533a"><li id="e43b1627-384a-462a-9fd1-4ffa6946728a">(以<span id="85937d65-383f-4374-87e7-c58ec92b978d"><span id="1e49f960-4902-4430-9ce2-2197657f8dd5">Chrome</span></span>为例,其他浏览器类似) 打开歌单页面,在生成外链播放器上右击,点击审查元素(检查)ctrl+shift+i;</li><li id="26de1cc1-696d-45ff-a318-03e6abe8aeb4">接着找到生成外链播放器这段文字直接双击复制前面的<span id="b2ff154a-4ebb-40ce-bfae-b5704ea1854b"><span id="4f5c72dc-c0ae-4705-9ba2-004fbd0c72a9">/outchain/2/20707408/</span></span></li></ol><div id="8a3a1e42-fa71-4fdf-8421-aa345baf91af"><img src="https://p26.toutiaoimg.com/origin/pgc-image/0de660c1de5b4f30a7a9c7016e6aeee0?from=pc" /></div><ol id="68a945a9-bbd2-4197-a38c-558b87730a6c"><li id="7f9b6a16-f6d7-45c6-829f-705cfc3106be">然后在浏览器地址栏修改歌单链接,示例:http://music.163.com///outchain/2/20707408/</li><li id="be9e3f0c-7023-4894-acd0-de359fa2b1f0">然后就转到外链设置页面了。</li></ol><p id="b5f1eff3-f2f7-432d-aaf9-b404a6aea52f">复制如下代码:</p><p id="48478824-b128-48cc-91bd-d5f36b22661f">粘贴到文章对应位置就行了,为了美观,设置一下居中,具体代码如下:</p><pre id="c4bae007-9588-4a66-9f9d-389df7028173"><code id="f833548f-6d63-44f2-8b5a-9c430e30192d"><span id="54d308aa-a518-4c6b-bd84-57ba7f4c841d"><<span id="0c984cc9-f921-421e-84d9-67f28ce1cddc">div</span><span id="53c1d05a-9cb1-4fc9-b70a-88c817f07c7d">align</span>=<span id="10e6c986-daf3-4c53-9fa4-d2eb1b70048d">"middle"</span>></span>这里粘贴刚刚复制的代码<span id="380ee733-c6e6-49e9-95dd-5560abef710c"></<span id="d0f578c3-4d45-44bc-baec-bbd866c0074c">div</span>></span></code></pre><h1 id="04a33a40-bd38-485b-8b92-5769bb6872a9">2.10 博客音乐板块</h1><hr id="7253a789-e4c9-422e-abe1-f58681b87d77"></hr><ul id="4b8eded6-6d37-4725-adb9-a7f406504b6f"><li id="0a7d2079-49da-4809-a0cd-5d5f3176f725">首先我们找到网易云在线平台,任意找到一首歌点进去播放,可以在地址栏拿到音乐<span id="0ba316cd-9a36-4200-af29-7026d236f8c5"><span id="73967edd-18ba-49ea-b940-02b578a60188">ID</span></span>号</li><li id="d00da1e6-2fb2-4991-88da-472e9c8521b5">然后通过下面网址:http://music.163.com/song/media/outer/url?id=XXXXXX.mp3,<span id="88760f73-bfb1-4646-a5c0-c9ce2742fabb"><span id="16e96378-a97b-4d51-bac8-d382004ac50c">XXXXXX</span></span>就是歌曲<span id="6f68c7a2-22a6-40c2-815d-1996b886f2d9"><span id="8bfb61c6-3e25-4e77-83d3-a98da68080d7">ID</span></span>号,每一首歌我们只需要换掉这个<span id="03efef97-5a0a-48ac-924b-81e415690cc4"><span id="2497be8e-7c70-4b48-b705-d0772e397f08">ID</span></span>号就行了,就相当于每一首的外链了</li><li id="dd6b9491-4257-4a09-bd60-5b71c4028dd7">最后封面图也可以按<span id="90a9888c-fad2-4e7f-92ad-ff1a317da4dd"><span id="a041ee56-d4a4-4806-9375-4e238a7fa01b">F12</span></span>去找页面元素的链接,填到对应的<span id="75fa1caa-0d25-4fee-8af8-eed0083a12ab"><span id="c533cf60-8667-4bc4-b7ce-94ff13cd83b4">musics.jason</span></span>文件中就可以,批量填入,听到好听的歌曲随时更换随时新增,很方便。</li></ul><p id="6bce5738-ee39-4cee-b366-3ec8e7f78542">操作如下图:</p><div id="e26a6c18-d80b-4042-88c8-b807177c247f"><img src="https://p26.toutiaoimg.com/origin/pgc-image/f511fb0d9d5145d89df8b6798dde8880?from=pc" /></div><h1 id="138643ae-1dd6-439f-ae95-398254f849ea">2.11 增加emoji支持</h1><hr id="d8aacf08-c479-4ae2-a8c5-63e6f85d8f0f"></hr><p id="3041038c-a64b-4103-8cd9-7d9a06f71216">为博客新增对<span id="c0b250f0-83cb-47c3-b15c-f4ebd5a0e62e"><span id="50a8a496-7512-4970-8724-ee77f65579ff">emoji</span></span>表情的支持,使用到了 hexo-filter-github-emojis 的 Hexo 插件来支持<span id="502bcd1f-54f0-4157-9f61-5eb08c0a39f6"><span id="f37ce908-445d-4675-b76d-055b613ac261">emoji</span></span>表情的生成,把对应的<span id="034c110c-b46e-4f85-8488-44d2457e9693"><span id="6d8df82a-6ef2-4f5d-a994-77b99b475f75">markdown emoji</span></span>语法(<span id="66887a6e-179f-4459-9250-0081f75eccce"><span id="2a6f89e9-1ea0-4628-ae02-17456c5195ab">::</span></span>,例如:<span id="e7c07e7d-bd46-43a6-a88c-b0b48893df20"><span id="cc39a5f6-9261-46a6-8c50-d76693a8967f">:smile:</span></span>)转变成会跳跃的<span id="729b63ba-ac22-4021-a464-e0e3fa1a86c1"><span id="2a660e27-4b3a-48fb-af34-e57dac18b71d">emoji</span></span>表情,安装命令如下:</p><pre id="41b69b02-e0e9-4e90-aa91-24aca17d6711"><code id="2a490698-b7a4-4903-b5b1-f29beaf5400b">npm<span id="e66d7091-9dab-4a0b-af93-00fa57b8b812">install</span>hexo-filter-github-emojis<span id="f83eb9df-8326-4d84-b355-01666500cf41">--save</span></code></pre><p id="a0b920ef-e10e-4225-b771-8fa64f8da21d">在 Hexo 根目录下的<span id="32d210a3-8df1-4704-8e22-a05672d328b5"><span id="8741d4e8-d51c-4fce-b337-494c101f7597">_config.yml</span></span>文件中,新增以下的配置项:</p><pre id="5d2b27e4-80ad-4b11-990f-b32103f553f0"><code id="45936719-1d8d-47eb-9961-4944142f5e74"><span id="8579db89-06a0-41da-81b4-4303165238cd">githubEmojis:</span><span id="b0b38d9b-74ef-4f5f-8e83-ac178d0f3c32">enable:</span><span id="bdc6e8c3-2b5d-45c5-8c79-8e2aea7164f2">true</span><span id="94c620c2-6d87-47b3-8515-ec8a9487f820">className:</span><span id="e8fdb8c4-3757-44ee-be4a-2e3a47846a01">github-emoji</span><span id="7482634a-65c7-4883-935c-476fedef680f">inject:</span><span id="f2bc144a-7659-4dc4-9288-47fb78a9d01d">true</span><span id="ccfc7f50-e4ab-46c4-8c4a-b29a49efd4ce">styles:</span><span id="cd6bbf32-dbde-40a1-ab7f-f0325b6c97c1">customEmojis:</span></code></pre><p id="a7491bd9-9306-4295-9560-e4c8db29c469">执行<span id="cb2a9b4b-f9e3-4948-9495-22cc94f44751"><span id="765ae063-d670-4be3-9888-e9d7ee84d81a">hexo clean && hexo g</span></span>重新生成博客文件,然后就可以在文章中对应位置看到你用<span id="79b15095-10fa-404e-8652-42c8d4ee11cb"><span id="d6eb3ab0-fa45-433f-a77c-fb68adf319fa">emoji</span></span>语法写的表情了。如下图:</p><hr id="cd0f0501-c300-4bd8-b35e-7fbb6ea147d1"></hr><pre id="5d2b8fc5-62a1-4c3d-a7ea-ec31f343ed34"><code id="6450d091-f858-484b-8d47-06342126ebe1"><span id="6ee1d4a0-71a8-40d7-98b0-ef63422e878e">valine:</span><span id="ac657f6c-9f5b-4fa3-ad13-d38136369bae">enable:</span><span id="128331d9-bc1a-44d8-a950-821ebf05df3c">true</span><span id="8456eef0-13dc-4073-8d95-bc1ec4e27b1d">appId:</span><span id="2005bf03-b9b5-4b02-8023-5b9e55167f2b">XXXXXXXXXXXXXXXXXXXXX</span><span id="bd9a4f4b-8afd-4700-8973-af5b481f2732">appKey:</span><span id="b9c398dc-7327-4004-89ec-dcb7c7c23c45">XXXXXXXXXXXXXXXXXXXX</span><span id="2fa51111-40ea-415e-b1bf-484519896d43">notify:</span><span id="6c347a58-9831-4a27-9e55-59f4906054a3">true</span><span id="3d1693e6-cfa6-439a-982b-aca8e71d464f">verify:</span><span id="3ea4113f-d01a-416b-b5f6-35d7220bb937">true</span><span id="9c7b9dde-79f1-4376-9a9d-bb877392ffa3">visitor:</span><span id="f582eba0-52e5-4587-a511-b98d16ba5058">true</span><span id="b25779c4-c80f-4524-baa3-6b1776ca737d">avatar:</span><span id="a001a068-25de-4bcd-be91-514f461b96f4">mm</span><span id="a2a96e8a-867c-4883-a077-a40ed7f23259">Gravatar style : mm/identicon/monsterid/wavatar/retro/hide</span><span id="7a106444-0c62-4c99-84f1-4d121c7ec41e">pageSize:</span><span id="5ede4eb8-47af-472c-927f-1f9db9fc03c0">10</span><span id="c8d4fe9c-c644-4b9c-aa6e-a5f6710844cb">placeholder:</span><span id="45183a2d-a597-420d-8389-fc57268e6c8d">just go go</span><span id="66cb7b9f-3b2e-4a65-ab63-5868ac8111ab">Comment Box placeholder</span></code></pre><blockquote id="a3dc2129-50fd-4471-88ed-fd95afb4ffad"></blockquote><p id="e4a62610-bdae-4383-b158-361f0e6c9d7b">如下图:</p><div id="b5ec0e70-6da9-4085-a530-a2294b2fd456"><img src="https://p26.toutiaoimg.com/origin/pgc-image/c210b50682354d628b2f7fbea07217ae?from=pc" /></div><p id="5e5b17b4-a648-4c50-829f-1dc760b3b4dc">解决办法:<span id="1f219d02-d32a-44c7-9c61-02a66712e54a"><span id="d174bc66-9634-4d39-a1c5-80e29889d856">F12</span></span>开发者模式,控制台定位<span id="58ff4453-22cb-4486-a226-d4605f7e826b"><span id="bff714be-0654-4518-bebf-0913154910e9">bug</span></span>位置,修改参数,调整对应主题源文件参数,得以解决,如下图示:</p><h1 id="68e091e5-12a5-491b-9839-3c1857438b60">2.13 添加博客动态标签</h1><hr id="41050482-6963-4471-8f65-b9dc163a636a"></hr><p id="e2c3c343-6adb-4c6c-9587-d693fb9d50bc">原理就是给博客增加一个事件判断,如下图所示:</p><div id="af4b8feb-c4ec-44bd-87c8-5f96fe20b556"><img src="https://p26.toutiaoimg.com/origin/pgc-image/bc688bc97cfe4de5bde5d1ba52e6f58e?from=pc" /></div><p id="d87df7c6-2bf3-47d7-a403-e130c9e9fc85">打开博客主题文件夹,路径:<span id="c8110614-0597-4606-bc21-aa7b72aea199"><span id="5ebb2d21-2c63-4f34-ab95-b93ab9f8a4e8"><span id="5fadf23a-0c09-4c8d-8afe-f492f0d7128e">themes/matery/layout/layout.ejs</span></span></span>,在对应位置添加如下代码:</p><pre id="b9144bbe-16e6-4cbe-a3dd-62c6b1b3edea"><code id="5ca3a828-41b0-4404-90b4-f97e57e22df1"><span id="3082865e-dc22-4a7c-a8dd-845ca23f1de7"><<span id="df14d474-d435-475a-8291-52d0acc2ff0e">script</span><span id="27e2b889-c7c8-477a-adfd-d4757779af54">type</span>=<span id="ed7eb971-ae64-48fd-af8c-9b862877f406">"text/javascript"</span>></span><span id="d8247def-e07d-4c0f-af1c-a37edfca6bad"><span id="78338262-77f2-4404-a0d7-1e422e7e34df">var</span>OriginTitile =<span id="77c92678-c14f-494a-ac59-b2ebdd8380b0">document</span>.title, st;<span id="e79f30e0-2f30-4571-a3c1-cfa41629bb6e">document</span>.addEventListener(<span id="c2007920-a5d8-4580-9609-a285c2f677a4">"visibilitychange"</span>,<span id="8137d766-4f53-41cb-aac4-b4f4d12027d8"><span id="7957ddc5-06fd-48e5-b297-60368f3e7a22">function</span>()</span>{<span id="bb3f516e-0354-458b-93f8-70c728fede9a">document</span>.hidden ? (<span id="25aadf9d-6fa4-4200-acc0-368569761cb4">document</span>.title =<span id="13787c25-893e-4542-a67a-99155bc441bf">"看不见我~看不见我~"</span>, clearTimeout(st)) : (<span id="1a42b270-c0f1-42d8-8c95-45b5afbd2e2c">document</span>.title =<span id="2b7bdfc4-b20f-4d69-8e98-55b6fa34e0b2">"(๑•̀ㅂ•́) ✧被发现了~"</span>, st = setTimeout(<span id="6fbc113c-3bf6-4031-b807-408568df73e0"><span id="64dd5185-8e0f-4a57-8569-44e94f6057c8">function</span>()</span>{<span id="bd2a307a-d302-462a-8b3e-1a88d935da3a">document</span>.title = OriginTitile },<span id="d46b1add-6f54-48a6-8a55-acc576d634cf">3e3</span>)) })</span><span id="dc088286-e92f-40ca-b762-57548ce5fb05"></<span id="117c9ebf-72c5-4517-9ca8-394facaf631f">script</span>></span></code></pre><p id="f96fb063-9436-402f-b706-2664fc8625de">然后<span id="1e8ff24f-0ef5-4170-bde2-6e36752d0ac2"><span id="dba0fbe9-03de-42bb-9eea-8963367045ba">hexo clean</span></span>&&<span id="8c384192-949c-46fd-811e-46c08f8591b3"><span id="f0a10292-041c-4ce1-acc2-112839d87928">hexo g</span></span>即可。</p><h1 id="b52e4e75-f388-4118-9e0f-29e524f53404">第三部分 优化</h1><hr id="1433d205-6d7a-4d34-91e9-93e9ffef55cd"></hr><p id="c6040d33-870d-4779-95d0-a4f0b9e39e65"><span id="43072fc0-9083-450e-88aa-eb93849a136b"><span id="d5f1ce63-b893-47be-ae8b-9c3809eecb2f">hexo</span></span>添加各种优化功能,比如<span id="5233250b-32a5-421f-b6ab-1de77d8d9f5a"><span id="f2f7c41e-a3ea-435e-ab52-55045db8e293">SEO</span></span>优化等。待续......</p><h1 id="90098c3d-322e-433f-996c-0a0d7557abbd">1. 网站SEO优化</h1><hr id="4ea44f25-aec8-4db1-8df7-dbe8c35e0ddb"></hr><p id="0ea1b01e-2422-4abf-a0d5-003c11dd60ea">网站推广是一个比较烦人的事情,特别是对于专心搞技术的来说,可能就不是很擅长,那么怎么才能让别人知道我们网站呢?也就是说我们需要想办法让别人通过搜索就可以搜索到博客的内容,给我们带来自然流量,这就需要<span id="929cf251-4551-4b43-a213-563c300b4732"><span id="3668f772-ef29-48e0-8b4b-2584f684f5da">seo</span></span>优化,让我们的站点变得对搜索引擎友好</p><blockquote id="54b93440-7c74-4d13-9215-58adaf75e898"><p id="f6e772d9-e9d7-4b6d-8e95-7f912e714376"><span id="c528b696-4741-4b8f-8888-6c5dde8310fa"><span id="c0d788c4-c0f3-4fdd-9c05-9fb3da12dcda">SEO</span></span>是由英文<span id="bbc0d1e1-c991-4ffa-97b2-2f7cf06ea796"><span id="d27ba791-995a-4ee2-af67-fde471f5d9d0">Search Engine Optimization</span></span>缩写而来, 中文意译为搜索引擎优化。<span id="d312bc51-04f4-4239-9ddc-8620dd1b6c1c"><span id="a52174e7-15e6-424b-a2fc-74553d8eae1b">SEO</span></span>是指通过站内优化比如网站结构调整、网站内容建设、网站代码优化等以及站外优化。</p></blockquote><h1 id="0162a582-9376-4232-bf40-c7eada34ee52">1.1 让百度收录你的站点</h1><hr id="dbbed98e-fc0f-4d1b-afd9-a59ef335400a"></hr><div id="e2267216-2566-406c-8160-c65ed860f125"><img src="https://p26.toutiaoimg.com/origin/pgc-image/f9e6d903a34d4d2d833dcbc485bf21cc?from=pc" /></div><h1 id="c1d81c4c-8f30-4fb1-81b5-1c074ae3d887">1.1.1 验证网站所有权</h1><hr id="f2fed6fc-71c3-4d35-84cf-81f67d2381d8"></hr><p id="2e4683e1-6fcf-473e-a85a-268944e0ae02">登录百度站长搜索资源平台:<span id="01681e1b-bdd7-4eac-9ed7-991313dbf572">http://zhanzhang.baidu.com, 只要有百度旗下的账号就可以登录,登录成功之后在站点管理中点击添加网站然后输入你的站点地址。</span></p><blockquote id="5885486d-1af8-4600-a6b5-a4fa2225b27d"><p id="d21b52f7-de5a-4059-87a0-d986ca9ad83b"><span id="d51501b4-93b5-4908-b834-68f97998f38a">注意,这里需要输入我们自己购买的域名,不能使用</span><span id="5e881812-b35a-4a07-b938-410b98f7cced"><span id="482a74a2-3a98-48cb-81ad-19915b098ff2">xxx.github.io</span></span>之类域名.因为<span id="ad030d7a-055c-46cb-a122-22a07d61673b"><span id="07a6dc33-7448-431c-ae6a-fb9ef68c0c78">github</span></span>是不允许百度的<span id="ba7d8a2d-5f14-4778-aebb-93ecbe75a939"><span id="4f0fbc6c-a545-4450-b7fc-be7bd5d5ad2c">spider</span></span>(蜘蛛)爬取<span id="f68c2192-6e80-4dc0-ad6d-6713a7fd799f"><span id="b47303c1-7cec-46e3-a00c-41e97e9a3412">github</span></span>上的内容的,所以如果想让你的站点被百度收录,只能使用自己购买的域名</p></blockquote><div id="f7aeb77b-d07c-4b52-addd-3f4a500b0b65"><img src="https://p26.toutiaoimg.com/origin/pgc-image/e3d664b7d9fe487ea26b655af59cc1c2?from=pc" /></div><ul id="c998764f-b7b7-4a08-b599-9e6a1443fe41"><li id="46461bf9-2c1b-4b69-a776-58f88b1ec399">文件验证。</li><li id="faef4347-6aec-4222-b579-7626e9587737"><span id="9eeff56b-290b-48aa-a43e-9c23a1110559"><span id="759cfd42-c75a-44f7-b3fb-fdeedb3e7a4a">html</span></span>标签验证</li><li id="b0c097d1-23bb-4fde-807d-13d6a494ee99"><span id="b572636a-3cd1-4b8a-b9c3-8133fcdaaea3"><span id="5656693e-5659-4563-a9d6-a4e0e2a7e049">CNAME</span></span>解析验证(<strong id="ff3f02c8-1ef3-4fb2-8e67-ee96acb7506b">推荐使用</strong>)</li></ul><p id="1ada3261-8c2c-4152-a7a1-de849056fb7e">其实使用哪一种方式都可以,都是比较简单的。</p><blockquote id="19b0dc33-a5e7-4712-9eff-f4a2bf24229e"><p id="39a43257-0e18-45ec-8f7e-a92362d69395"><strong id="30849b82-1ea5-490a-adba-5c1729e4b51a"><span id="37e9955d-6f6f-4e29-909e-da6c87a4c1b7">但是一定要注意,使用文件验证文件存放的位置需要放在</span><span id="2254ab16-3286-4301-b1f8-6432a3c91c8c"><span id="5bfcc083-c162-40f1-b306-59688fdffed9">sourc</span></span>文件夹下,如果是<span id="221dc112-c45d-4630-87d2-13972e55c1a0"><span id="b2e75a67-89a0-4161-a34b-f0f87a8343fa">html</span></span>文件那么<span id="350c649e-0e38-4499-8de2-170dc14af59e"><span id="c086c11a-56f2-46b1-92a9-1eb8ca82db87">hexo</span></span>就会将其编译,所以必须要在<span id="8f7630ee-1b6f-447b-afb8-b3ba11db70f5"><span id="c112d025-35cb-4cfe-8443-43d41bb5cb6f">html</span></span>头部加上的<span id="3c67af92-f702-4eba-86e8-d1658c11c4b5"><span id="f64fb752-2f4d-45c7-aa29-5b558810766f">layout:false</span></span>,这样就不会被<span id="990fadf7-6669-4605-9316-89279e7fa971"><span id="fdd325aa-0b93-472a-83d5-a6bebd9e1b1c">hexo</span></span>编译。(如果验证文件是<span id="68ba945a-af4a-486f-a1d1-c487f4527216"><span id="6b22ccf8-5918-40de-9314-7807b783f6b7">txt</span></span>格式的就不需要)</strong></p></blockquote><p id="f2e5a37a-b1e2-4b8c-b6e0-90e4e56c315d">其他两种方式也是很简单的,个人推荐<span id="cebb914d-f705-40f2-946b-bfdf5a1d470c"><span id="428c5d35-c0a1-41e4-9239-2e045fccdf0e">文件验证</span></span>和<span id="021abd3a-e8b9-4922-abec-7e963ffd3f12"><span id="21f87106-8584-40a3-bf31-ecb9c36c9d21">CNAME</span></span>验证,<span id="5405ee1a-252b-4413-b91a-5b371a12a0a6"><span id="72642d57-c392-4c3d-80a8-f90a4b080b07">CNAME</span></span>验证最为简单,只需加一条解析就好~</p><div id="c8051fc6-6195-4d4f-b2b2-98a7bea7b0ac"><img src="https://p26.toutiaoimg.com/origin/pgc-image/9c0ddbee0b154d82a241dd504cddeb57?from=pc" /></div><h1 id="ef32a9d7-6a38-4c21-b981-52f3b22fbda6">1.1.2 生成网站地图</h1><hr id="a17a441e-39ba-4e3c-bccc-6842a9c840b7"></hr><p id="162593d3-2b44-4744-b1dc-d50d92f361c5">我们需要使用<span id="e6924ea9-5d8b-4928-9047-d983e66166df"><span id="130d61c0-248b-448e-896b-4f52fe3ede23">npm</span></span>自动生成网站的<span id="a8c9e17b-74b5-4a5b-91dd-0ad18acc5a30"><span id="ebb72f5c-7d56-4586-a312-e4a66e15b1dc">sitemap</span></span>,然后将生成的<span id="d5073a36-5a94-473c-ae3d-e9d635e4df84"><span id="b9e7accf-1af9-4865-b901-26e24b256af0">sitemap</span></span>提交到百度和其他搜索引擎</p><h1 id="e2fdab83-4a9c-4dcd-838f-9cabc1b90498">1.1.2.1 安装sitemap插件</h1><hr id="5dc1f1a3-3364-430f-9f19-9ce7acaed909"></hr><pre id="37ff7d9e-fefe-4a1d-9a7f-1b25fe28cdc2"><code id="0a65e47b-adc5-46cb-a198-79e3da046087">npm<span id="5ceb7ad6-da5c-4a75-8283-a0538a4c6d41">install</span>hexo-generator-sitemap<span id="6692bcf4-611e-4340-a398-a3e565fadb33">--save</span>npm<span id="6ce08e9f-54d0-4c72-bd83-7b435075e8a5">install</span>hexo-generator-baidu-sitemap<span id="764cbf7e-ee36-4d6b-9a2a-edb214fbba90">--save</span></code></pre><h1 id="1f8e21c5-f1d2-4e4b-b704-37e49a43865f">1.1.2.2 修改博客配置文件</h1><hr id="278121d4-55b4-4aaf-88de-f1c1ee5a8848"></hr><p id="638eaee8-1d79-463d-bc11-694cefa89ccb">在根目录配置文件<span id="05184db8-a227-4eab-8e78-015bea959679"><span id="3a766d20-d08e-450b-85ff-1a27094c4245">.yml</span></span>中修改<span id="d8f56561-52e2-4c27-bdef-86cadfdf73f3"><span id="8e769094-aa3b-4ce1-8882-566b9ff583a2">url</span></span>为你的站点地址</p><pre id="5876871d-0c79-44c0-8b49-7c034a3503f3"><code id="40703083-f389-47cd-ad37-277f2505dd7c"><span id="d65e053c-d62b-434a-962f-95dab60c26b8">URL</span><span id="355cbf79-dbab-460f-951a-8b7ace851dfc">If your site is put in a subdirectory, set url as http://yoursite.com/child and root as /child/</span><span id="243c6462-d618-4dc1-984d-72727dffcde1">url: https://shw2018.github.io/</span><span id="4b5684ff-7bcc-4f93-b53d-aff8d0c4f28f">url: https://sunhwee.com</span><span id="eacde92d-c480-4278-af00-3e387315b983">root: /</span><span id="1f3fe036-b5a6-4a17-b630-cb33ad69b7e1">permalink: :year/:month/:day/:title/</span><span id="d1344dcf-2ada-4b47-b9d3-1be86a04d445">permalink_defaults:</span></code></pre><p id="dbda36d7-60ad-4dd4-b9e9-45ca482f2724">执行完<span id="89829f8d-09ab-40d3-9075-1b9821431bf6"><span id="4a0cdcc5-99dc-439d-a9a2-f9abe26ec272">hexo g</span></span>命令之后就会在网站根目录生成<span id="93b58e28-c318-47d5-8724-3d535dc89ca7"><span id="7e5eff5d-8715-4da2-a3a4-5d9536f7c98b">sitemap.xml</span></span>文件和<span id="f2f406d8-b1c1-4d62-be69-c01b00036fcc"><span id="b7a8fb81-1398-4876-922c-456a5173ec2f">baidusitemap.xml文件</span></span>,可以通过:<span id="bbb72927-c61e-4799-adbd-17390530f9b8">https://sunhwee.com/baidusitemap.xml, 查看该文件是否生成,其中</span><span id="5e0cf41b-c1f4-4018-a304-12ada1027fbe"><span id="536acc07-1684-487b-b526-b7dcb3ab06dd">sitemap.xml</span></span>文件是搜索引擎通用的文件,<span id="e4699575-29ee-4f85-8e26-f4109f497701"><span id="448bdb55-4d30-4b32-8189-572fd27dcefe">baidusitemap.xml</span></span>是百度专用的<span id="baf89159-c24d-427f-97b8-fc826ef584f8"><span id="abe4cf53-732f-4603-91f0-0056bce19267">sitemap</span></span>文件。</p><h1 id="e7763ee8-5b22-411c-9b67-fb1f71e3edd4">1.1.3 向百度提交链接</h1><hr id="434dbe2c-d970-4b1f-8aba-7a1ff7c54033"></hr><p id="bd1a0aa1-4c3b-491e-bd8c-7bb12b62762f">然后我们就可以将我们生成的<span id="8abf6653-6b17-445f-a74c-345a86ee5d82"><span id="8e0b5797-b7e7-43e9-a17d-b7257c28574b">sitemap</span></span>文件提交给百度,还是在百度站长平台,找到链接提交,这里我们可以看到有两种提交方式,自动提交和手动提交,自动提交又分为主动推送、自动推送和<span id="8218d436-fe1a-4ca4-9291-21a79a983ae6"><span id="9c50d584-cc8b-4cc9-9d87-92b6c4e523d6">sitemap</span></span></p><blockquote id="2add0c5d-0d00-4c0f-bf6e-c99ad2438df9"><p id="ac43b22c-ddad-4f03-9383-266d6d318f3e"><span id="fc228293-5224-46eb-a7fb-6c720c656b75">如何选择链接提交方式</span></p><p id="8b18efec-5ab7-46c0-bfe0-2229648973d0"><span id="28b47dba-027f-4565-af4e-5f0368dfbaad">主动推送:最为快速的提交方式,推荐您将站点当天新产出链接立即通过此方式推送给百度,以保证新链接可以及时被百度收录。自动推送:最为便捷的提交方式,请将自动推送的</span><span id="e661d034-4120-4392-a46a-dc99fd03d15b"><span id="376a9946-a3aa-44a6-a4b9-89b9d42f54be">JS</span></span>代码部署在站点的每一个页面源代码中,部署代码的页面在每次被浏览时,链接会被自动推送给百度。可以与主动推送配合使用。<span id="9f942f68-8c89-4251-a709-e7dd32b4af8e"><span id="407385ac-c4e8-420c-b085-b3de46fbe61a">sitemap</span></span>:您可以定期将网站链接放到<span id="bcb87372-1efd-46b3-a3d6-2775c2e311b3"><span id="796a9e7f-5ca3-44cc-958b-cbc7a9a43c9f">sitemap</span></span>中,然后将<span id="589db6a5-6b40-4ba5-8574-6594a0b0216f"><span id="425807dd-426c-445a-b1db-8bbeecb83b6d">sitemap</span></span>提交给百度。百度会周期性的抓取检查您提交的<span id="9cb3fdb6-4b1f-41fb-89b1-39a1a2cac7f1"><span id="8857f122-4706-45eb-b11e-b3ce38476c80">sitemap</span></span>,对其中的链接进行处理,但收录速度慢于主动推送。手动提交:一次性提交链接给百度,可以使用此种方式。</p></blockquote><p id="e5ee94da-794d-490b-92a3-77f016328b32">一般主动提交比手动提交效果好,这里介绍主动提交的三种方法</p><p id="91ae6621-9833-4b1d-9121-2a7b05a61d3c">从效率上来说:</p><blockquote id="d044f822-8e81-4891-a18e-6399e2b648fa"><p id="23ead9ec-0b02-490b-b026-8b9b8636fab7"><strong id="d0d8070f-edb0-4b2b-a0df-f51fc61a7e9f"><span id="2cc55147-b404-47c8-a30a-f64ebfae22b4">主动推送>自动推送>sitemap</span></strong></p></blockquote><h1 id="f6621f83-4671-418a-ace4-43f45fd2e7ec">1.1.3.1 设置主动推送</h1><hr id="d426666e-684c-40b3-b2b8-251eee9b1a19"></hr><p id="946c1a17-1a44-4f56-acef-1a7fc9d8bcff">安装插件<span id="52371d95-0238-4741-849b-52079735935f"><span id="e82980ff-5a1a-40cd-a11d-92fba88111fa">hexo-baidu-url-submit</span></span></p><pre id="1ff141bb-157f-4630-9376-26142adc5ba7"><code id="da7171ed-cbda-485f-b26e-a4e24b73814a">npm<span id="54aa1773-6ef0-4749-ab41-4bbd823b5018">install</span>hexo-baidu-<span id="07eb13b8-3146-4ad1-ab0f-adfcd58ad02b">url</span>-submit<span id="c8a9aedc-963b-46ae-a134-e05eb333260c">--save</span></code></pre><p id="825fdcd4-da42-4013-9f88-3268ffde022f">然后再根目录的配置文件中新增字段</p><pre id="0bff2a58-45e7-47c4-93d6-4010000f1d64"><code id="3c76fb1e-9e41-48ae-a992-72536b535a00"><span id="c4c85c58-18d5-4844-9da8-47a693283e15">baidu_url_submit:</span><span id="0a9f35bc-3835-4e2a-a0bd-c4b0f8690ab2">count:</span><span id="f34f847f-082f-45e2-8a88-cadf864009a2">80</span><span id="43e7c762-1604-401f-8129-5e74dba14a17">提交最新的一个链接</span><span id="2c86d99d-9464-430c-98b7-530a39b66090">host:</span><span id="7b76b5af-2b59-4756-9e06-0709365f6ce4">www.sunhwee.com</span><span id="dff2bc44-c485-4b7b-b36e-c46ce2302716">在百度站长平台中注册的域名</span><span id="880af758-b8c6-4dd6-870f-bbd0e2c5a95f">token:</span><span id="5e361dc9-0737-4d67-ac6d-1b3cb9277534">xxxxxxxxxxxxxx</span><span id="9efc57e5-23f2-4d29-b17e-2fa27ea032df">请注意这是您的秘钥, 所以请不要把博客源代码发布在公众仓库里!</span><span id="5a05ab5b-f920-4ae5-b85d-026940916090">path:</span><span id="a21b07d0-d72b-4b98-b164-e6cfb784a286">baidu_urls.txt</span><span id="d7582927-6d3d-4f42-b883-a73df7b41f2a">文本文档的地址, 新链接会保存在此文本文档里</span></code></pre><p id="bb2515c1-dc4b-44e4-93b8-ecac22657209">再加入新的<span id="b476293a-ae95-45b7-9c13-b774d8fc0140"><span id="bad24c24-4114-488c-8b04-732f08f00de2">deploy</span></span>:</p><pre id="d1654a8b-8b75-4980-b024-fb444ef5527d"><code id="ca091ed7-f0a5-43f4-917c-821be47844fc"><span id="8e29fad6-bc02-4abf-8931-6e150cdca3b5">deploy</span>: -<span id="45f14e60-7c90-4e10-b3a5-42701315f94f">type</span>: baidu_url_submitter</code></pre><p id="c3198e4f-f044-42e7-80a2-0c214c099c10">如图所示:</p><div id="357e058f-e415-4ab1-929d-6786b5674071"><img src="https://p26.toutiaoimg.com/origin/pgc-image/cfad27088a014a2da411214f5b1f510d?from=pc" /></div><blockquote id="c41f90a4-da05-486a-8ef8-74d2f53eacc6"><p id="324c2bb0-cbdf-4af0-a2e6-2c4d710c7e5b"><strong id="1a558578-3fec-4b1c-9d1d-700c05cefaaa"><span id="83573083-9c1f-4756-b1af-03b8513acfa7">注意,</span></strong><span id="a9b54575-9681-42c7-95aa-78cd9d9e4b30">这里多个</span><span id="86ff1529-bf29-4b30-bf54-408d2f9e631c"><span id="3cff3ebb-a60a-4c5d-8416-80ab9a03ae4f">type</span></span>的写法应该这么写**,前面那个<span id="f29e82a7-2362-44c7-a9ac-39074d652e33"><span id="024b6f64-e040-4978-b002-66dda2d0f799">type</span></span>是我推送到<span id="63728c1b-0263-4f25-b6ad-f916786f3959"><span id="1739ec2e-3781-44e6-9ec5-2554ec299f7a">Github</span></span>与<span id="2a211a7d-f5a8-4573-9b33-500b271b6ce5"><span id="8c184928-c558-4b9c-ba90-a03dbea3da81">Coding</span></span>的<span id="c43b0f85-7340-46fb-811a-54628c389327"><span id="66f4f212-bc62-4b84-8f39-3089d0f98ef6">page</span></span>页面的配置,后面再讲这个。</p></blockquote><p id="c8d19f3c-7465-4c70-9c82-21afb241c2d3">密钥的获取位置在网页抓取中的链接提交这一块,如下所示:</p><div id="d0231182-cb6f-4d20-b000-e4af5f275368"><img src="https://p26.toutiaoimg.com/origin/pgc-image/099d2124da8d439983b2e8cfa11a8bf7?from=pc" /></div><p id="c94f2606-d99f-4b2c-97d3-b144fdf7a07b">这样执行<span id="75164726-1f5c-4fa1-b123-5e30868467ca"><span id="30b9e8d8-27c6-4823-8053-6a46e466ea6d">hexo deploy</span></span>的时候,新的链接就会被推送了。</p><p id="63cbe185-05c5-4fa3-ae50-b85b20a9b4ca">推送成功时,会有如下终端提示</p><div id="b32efb97-119b-47d2-8971-52488140f83f"><img src="https://p26.toutiaoimg.com/origin/pgc-image/560e235fa5d14faab3c3ab8581a12a1f?from=pc" /></div><p id="4fe1afb8-a058-42d4-a199-24b98479dede">在主题配置文件下设置,将<span id="cdc94221-ab32-4f0b-b25f-74bf3ebcdacc"><span id="9b60ce5e-cdeb-4d9a-a29d-83083a959545">baidu_push</span></span>设置为<span id="095a8e04-b2cd-4deb-826f-68f5d813721d"><span id="b443c401-8d4f-450c-8a29-e4053707529c">true</span></span>:</p><h1 id="f05a464b-df90-48fe-a9f4-361682f85ffd">1.1.3.2 设置自动推送</h1><hr id="5c3fad70-1165-4ad7-b6dd-8180751571cf"></hr><p id="9c0eda7f-b627-4cf5-80bb-5bd241886466">在主题配置文件下设置,将<span id="df2c705e-cd15-4966-98c1-6d8e29aa80ae"><span id="3ac68de8-a4fa-48e7-8553-8ae588b258f7">baidu_push</span></span>设置为<span id="d1eec163-04c2-4968-9da7-0c8288f971e7"><span id="53189e7a-1308-4757-aea0-a88ad4078ee3">true</span></span>:</p><pre id="f8c7ca7c-f88f-4fa3-b1be-b419d8363595"><code id="c7508a89-f9d2-4ee3-8371-a7bfeaa918c7"><span id="e1c65471-5a4a-4267-b998-f75e707f72e1">Enable baidu push so that the blog will push the url to baidu automatically which is very helpful for SEO</span><span id="85eab4fd-998b-4d41-a7f3-eaa3e32041d6">baidu_push:</span><span id="60dc1e0f-b680-4f9c-bbe2-9717e3fae745">true</span></code></pre><p id="5a24191d-9082-4981-aa01-b3236d828ef4">然后主题文件目录加入下面代码,一般在目录<span id="dab71872-72f5-40d0-8afa-5c0fa358d951"><span id="f1e13cbb-e11a-4c56-ada1-81846d4ca03a"><span id="61510259-901a-4fe2-ba14-8fa339227b4e">/themes/matery/layout/_partial</span></span></span>中的<span id="2a445c4d-c2d2-4a97-9f1d-04a1b2a7c90e"><span id="adafd1df-6451-4c25-9d2a-cb03ad8c8d4f">head.ejs</span></span>中加入下面<span id="e9697f05-fcb8-422d-8045-3cbe62a28bed"><span id="2d41a3f4-cb58-492f-8a92-344a3d069957">JS</span></span>代码(有可能你的目录不是这样,原理类似),这样全站都有了:</p><pre id="c575d620-a573-4f1b-ba05-914278a450b5"><code id="88dda05a-4456-4da6-b551-2cbdb9450109"><span id="3a87d482-76d6-452e-aee3-0837f82fa5ef"><<span id="3d9c185e-c4a3-4c44-b5d7-0bcbe8755bcf">%</span><span id="3be25f71-5a58-49d0-baed-e6707d5d4b70">if</span>(<span id="90a4dfdc-a76d-429d-ac1b-37719ebd82c7">theme.baidu_push</span>) { %></span><span id="da3e6de7-1cc6-4930-9023-997edfb756de"><<span id="56f07537-c7a8-4324-9c08-e8420801a5c8">script</span>></span><span id="5ad85159-8dd8-441c-82d0-5347e052c739">(<span id="37cb9b08-e842-447c-bf3e-7c60baa61537"><span id="244461ba-4a6d-48b8-8013-259f93391a99">function</span>()</span>{<span id="6ceee379-8a11-438b-8b7e-544ba41cf597">var</span>bp =<span id="7bbb7805-5b95-4d7e-b26b-18da6d636f1f">document</span>.createElement(<span id="3d19d587-e390-414d-9bb2-103322e73eee">script</span>);<span id="ac0dd39c-98ec-4418-b56c-50a11b37b54b">var</span>curProtocol =<span id="9417f6d2-1a5b-4d4f-b7b4-caa4bb849cee">window</span>.location.protocol.split(<span id="eb696dd4-0fea-42f0-9ca1-de532cf928e0">:</span>)[<span id="3bb2279d-a910-4fd8-94a4-72e57c452435">0</span>];<span id="1fd4a95d-4f71-4a04-b4ce-edf93a5b664e">if</span>(curProtocol ===<span id="1951c654-1a87-4a91-a4be-ce966fa3a027">https</span>) { bp.src =<span id="c1ddbbde-d053-4f07-a7ae-85024ce21b1e">https://zz.bdstatic.com/linksubmit/push.js</span>; }<span id="ae6cb86c-a857-4c23-86cd-5a0d5fb3af71">else</span>{ bp.src =<span id="5d144a57-cfb9-4f9f-9143-1408d4781c42">http://push.zhanzhang.baidu.com/push.js</span>; }<span id="35a96fb4-6d6f-4e47-a453-10a3b8442705">var</span>s =<span id="b564297d-529f-491f-a982-0895724afb29">document</span>.getElementsByTagName(<span id="223b8517-cb91-4924-b6d1-ddbe347fe4ab">"script"</span>)[<span id="a7d69444-39b3-42ac-90fa-4bd8807130af">0</span>]; s.parentNode.insertBefore(bp, s); })();</span><span id="5b3acc87-9994-427d-8610-077c96db58a3"></<span id="430947fc-7dd5-4385-b7e1-41430674f813">script</span>></span><span id="1b7deae1-fdd7-4368-91a4-695b4a1643c2"><<span id="013593ca-ce19-41aa-b04f-b6c50ebe3165">%</span>} %></span></code></pre><p id="693fa33f-44d5-44eb-a860-664f1d676a94">这样每次访问博客中的页面就会自动向百度提交<span id="459a94a6-5368-4b9b-a9be-5cdc3efad809"><span id="2aa6a404-d3c6-4204-a9f6-843ad84a7311">sitemap</span></span></p><h1 id="2fb3a68f-38c1-4446-8734-f75f9ccbbb7f">1.1.3.3sitemap方式</h1><hr id="5708ee1f-f267-4518-b369-e416ed60de69"></hr><p id="ba94a877-5152-433b-99b5-8cc6a7745fe4">将我们上一步生成的<span id="2bb12091-4f39-496a-be18-c71bdf12345f"><span id="5a1d999f-3f8e-4a93-ac15-2fd6015d57a8">sitemap</span></span>文件提交到百度就可以了~</p><p id="2c3594e3-013f-4f38-9b5f-681b14e387d5">百度收录过程还是蛮久的,需要大家耐心等待一下,提交链接在站长工具中有显示大概是要两天,站点被百度收录大概花了半个月= =,收录了之后,可以在百度搜索<span id="c723b835-d26a-4b45-ac83-01fb337ac95f"><span id="97296548-4fed-466c-8cbb-10656505ac44">site: xxxxx.com</span></span>可以搜索到结果</p><h1 id="57d01900-c24b-41a0-a9c8-cbdd130b1150">1.2 让google收录你的站点</h1><hr id="6ab4e01a-75c4-42bc-832f-18acbc7d81cc"></hr><h1 id="b0d840c1-17cd-45e4-93dd-a974fa959ad8">1.2.1 操作步骤</h1><p id="39a8a9a1-ba02-4e03-83ac-250217726cc8">相比于百度,<span id="596135f5-c0a1-4ae5-bda1-64523563e55d"><span id="05e2731f-0e44-421a-8ec3-d4b5c79a8014">google</span></span>的效率实在不能更快,貌似十分钟左右站点就被收录了,其实方法是和百度是一样的。</p><ul id="ccacf1c3-fd02-4ae5-aeea-8c10377ab21c"><li id="c7239be9-1b9e-475c-9e59-9f92dd75629f">注册账号</li><li id="f17bd17e-d0e2-484d-8ad2-ef50a5a5eb9a">验证站点</li><li id="982bb9c9-41c1-414c-bfbc-40c7bb58a28c">提交<span id="11da8daf-7d75-4779-88fa-c66260c7f327"><span id="b0220589-f8e6-4efa-ac53-d614c9ba785f">sitemap</span></span></li></ul><blockquote id="51e32116-e350-435d-981e-6602f975bee4"></blockquote><div id="e2128593-638a-4e72-877f-6c5c11ea2b45"><img src="https://p26.toutiaoimg.com/origin/pgc-image/dd795a6acb8c48c8a0f6cfa0e2a9cd19?from=pc" /></div><p id="76468a8e-536f-4a7f-a4b4-8193bd450548">一步一步来就好,过不了过久就可以被<span id="90e01e2f-b338-4ca7-88bf-c0bbc559989c"><span id="419d7393-36fd-4f72-9034-24fa41b7a7ed">google</span></span>收录了</p><div id="af60d1d2-95e9-4b41-9cf9-fcc53291afe2"><img src="https://p26.toutiaoimg.com/origin/pgc-image/b6769f823e17492e8f21cf29c49eb52a?from=pc" /></div><div id="14f9b4a6-0556-4e5a-b799-4b357309072a"><img src="https://p26.toutiaoimg.com/origin/pgc-image/fa4c328167794022a0dfbdb49d31369f?from=pc" /></div><div id="c06995d1-dabc-4150-aebc-086dca1e26c8"><img src="https://p26.toutiaoimg.com/origin/pgc-image/6d85b58ad4fb4486bda3d8dea42748e8?from=pc" /></div><p id="976a4e2e-2776-41fa-badf-d68869d617bb"><span id="91ec01c0-d7c4-4f19-9a71-67d3f8ea3b4d"><span id="8a2d6a26-cc18-43ea-9d82-68f5d1e5dc3c">robots.txt</span></span>是一种存放于网站根目录下的<span id="70d09009-baaf-42ec-adba-81f3a82813b7"><span id="b32a83de-2713-4582-a1f4-6716b46386ab">ASCII</span></span>编码的文本文件,它的作用是告诉搜索引擎此网站中哪些内容是可以被爬取的,哪些是禁止爬取的。<span id="37613482-eb6b-4401-9b75-bdec326b57c5"><span id="cc50a0fa-cea1-4367-9ef8-e1dcb5cb8edc">robots.txt</span></span>放在博客目录下的<span id="11d70bfe-ef1a-42bd-8b96-d3fa0f407021"><span id="3ee08985-82fc-4236-9098-6298f8b94cd8">source</span></span>文件夹中,博客生成后在站点目录<span id="26559df0-381b-438d-8ea2-525224c26027"><span id="f4e261cd-efed-434d-8552-dd37303c5e40">/public/</span></span>下。</p><p id="9b795f95-a592-43a1-bc0d-1c3b03eee60c"><span id="5c658d1d-0871-4f2d-bf8f-b76951e4ce67"><span id="d0fe3014-85f6-4ec4-bd24-19b4b1e8ce86">robots.txt</span></span>是一种存放于网站根目录下的<span id="0d93b5cb-530e-429f-a97b-bb29fd6ecb21"><span id="08286681-f9fa-4424-910d-b0eee703a340">ASCII</span></span>编码的文本文件,它的作用是告诉搜索引擎此网站中哪些内容是可以被爬取的,哪些是禁止爬取的。<span id="dac43ef4-cea8-4307-bf7e-5f82e50ef7ab"><span id="fb622e28-09ca-4719-a456-f56e33a6572d">robots.txt</span></span>放在博客目录下的<span id="18c703f5-6a77-4473-a357-f7118905ed61"><span id="4d9297a2-d9b2-4be6-8555-e07bddfb81a2">source</span></span>文件夹中,博客生成后在站点目录<span id="a6859ad2-7be1-4556-85b7-9dc5071f4de7"><span id="9105ae55-f479-4d0e-b319-f356b55b96d6">/public/</span></span>下。</p><p id="5064a19c-2034-47f6-be99-0885e7c30cb0">我的<span id="8af104f5-f5d3-4bb8-a0d0-6d5a3cba95cd"><span id="6d8354d5-5008-4859-97ec-a788a3bb9d85">robots.txt</span></span>文件内容如下:</p><pre id="53abccc7-af7d-48dc-97e8-c71cd87bc9f6"><code id="f0e64e17-26c3-4d19-b231-fb89021064b8"><span id="80e92554-7154-4947-b508-4f6fde95a8b0">User-agent</span>: *<span id="09c65142-73bf-4dfd-afc3-2ed001b037f4">Allow</span>: /<span id="f3744e7c-a5d5-4e37-a1e4-48b3902e0a03">Allow</span>: /archives/<span id="53be67e5-6096-4f0e-8b8b-7a092001fa2b">Allow</span>: /categories/<span id="f97153cf-1548-4683-b87a-c456d79a71d4">Allow</span>: /about/<span id="2a5652ef-bb4d-4677-98b5-350c96470f5e">Disallow</span>: /js/<span id="0523d99f-ac44-4722-8076-c33183086650">Disallow</span>: /css/<span id="f90f5cb1-be52-43d5-ac5c-ae39aeb26a96">Disallow</span>: /fonts/<span id="cb9b38bd-1cfa-4c30-883e-dc4f1900acb9">Disallow</span>: /vendors/</code></pre><h1 id="8f99948d-27d0-4329-ade8-8023ef391e43">索引擎收录你的站点</h1><hr id="096aa3ce-e191-4868-84a1-c523e75b647b"></hr><p id="24dab98d-c424-453f-abef-beca7ddb4b67">除了百度和<span id="252f579d-160a-4191-b1f9-6f66b4772946"><span id="a09b420b-d94c-40bf-ac2a-34f377b1863d">google</span></span>两大搜索引擎,还有搜狗、360等其他的搜索引擎,流程都是一样的,大家就自行选择添加哈,这里就不再赘述了~</p><h1 id="7bb86d47-6756-487d-b273-98b646c402f6">1.4 优化你的url</h1><hr id="0dbf4ed9-8e72-475c-bf2d-82163aebf99a"></hr><p id="d75047b8-487b-455c-899c-9bca8a6da83f"><span id="e844d1ae-38d2-463a-a70e-7335cfbd1145"><span id="7a52179f-9506-4299-af1b-e773c963b4c3">seo</span></span>搜索引擎优化认为,网站的最佳结构是<strong id="404e2775-4558-49b7-b110-3ca12eb49ec0">用户从首页点击三次就可以到达任何一个页面</strong>,但是我们使用<span id="e9536ae0-278f-4965-9a7b-69a8a4b4a6c5"><span id="b0a7bcaa-6490-4733-abe9-a22cc437b544">hexo</span></span>编译的站点打开文章的<span id="74279044-b916-4155-9860-4f0342f45a2e"><span id="3537fc09-33c5-4c8e-b1bb-fc3d4cfe3935">url</span></span>是:<span id="2ffd432a-2fb5-46fd-8a4c-0314d8a5209e"><span id="25e0133d-8ea7-4021-967d-221308318770"><span id="1ba67249-5f76-40a7-a231-613b1d3a271f">sitename/year/mounth/day/title</span></span></span>四层的结构,这样的<span id="5f55d635-2557-44be-9f04-75fd2f869aad"><span id="7c3b21ab-d4b2-4990-81df-fb779442c759">url</span></span>结构很不利于<span id="f1ded790-edec-4060-971d-dd6dd29e965e"><span id="8478a41d-5f64-4ccd-856d-9bc656812b17">seo</span></span>,爬虫就会经常爬不到我们的文章,于是,我们需要优化一下网站文章<span id="8f6e6410-405f-466f-b31f-dfdf255290c3"><span id="f4324d47-bb8b-4079-a2f9-0a429b40bc36">url</span></span></p><p id="b2117f88-a9a8-41d2-993b-2514b33ae0b5">方案一:</p><p id="492a0584-06bc-454f-af0c-eecd09695a49">我们可以将<span id="db7adb1d-1ea9-42fe-9f76-cf261b0a33f6"><span id="6fa51328-3a41-45ca-8860-a06d6f8b621c">url</span></span>直接改成<span id="3f978553-b100-4930-b74f-0f66bc503f06"><span id="45f2dc67-1d5d-4723-bea1-816cacd2b27d">sitename/title</span></span>的形式,并且<span id="772aa637-d9d9-4308-a1c0-8f08d0895273"><span id="9704e079-a7c0-4d7f-85f0-a1e627aee801">title</span></span>最好是用英文,在根目录的配置文件下修改<span id="7407645c-1ea7-4e79-80e6-666b7d4bb419"><span id="e5dc33f6-e20f-42f4-949e-377d7b6cc845">permalink</span></span>如下:</p><pre id="06b92a74-9df2-4d99-b6ab-76b911b6c40b"><code id="4eba74c4-3e35-4eaa-8d28-488c3196c375"><span id="d6d1e586-82bf-46c1-9a80-7e1bac999657">url</span>:<span id="c30cd565-9f38-4cd0-a283-1154a444b023">https</span>:<span id="fa1eb6dc-93a3-41e9-9c52-b8e75e82c118">//sunhwee.com</span><span id="6395a40e-f3e2-4e7e-8a56-a64d41ec07c9">root</span>: /<span id="5a157cf1-0a50-4af6-8e4c-018a1b50e59f">permalink</span>: :title.html<span id="bfffdb71-6435-4c15-849e-2f328e47d0e8">permalink_defaults</span>:</code></pre><p id="c9812e3e-0d62-4b6e-8f4b-a88439db541d">方案二:</p><p id="8c22b2a9-f502-4d1c-8f32-44bd4cbff0c2">使用插件优化<span id="1d815474-ac8a-4759-9000-e2260f353ba7"><span id="ebdd4d1e-2e74-4f0a-b0c5-0827267b9743">url</span></span></p><p id="42ce4942-d29f-4b4a-bbad-8c63277178e5">插件<span id="e5b32d17-7027-469c-98ed-e90e82c08320"><span id="6eefdbb5-a4a7-437f-8c6c-6fb548e0ad1f">hexo-abbrlink</span></span>实现了这个功能,它将原来的<span id="5e23eaa8-83aa-472d-bc12-768052db3a64"><span id="d206521e-256c-4a77-bee9-127f7b387ce3">URL</span></span>地址重新进行了进制转换和再编码。</p><p id="6a79a145-9feb-464f-9214-29f12e7fbe52">安装<span id="a8cbdff6-5de0-4c69-a9e9-2b703b6cc52d"><span id="60c9723f-06fa-4293-8eb3-94746e7bf272">hexo-abbrlink</span></span>。</p><pre id="adb1a3f5-67f3-409f-afd7-63c576e94fdf"><code id="9750cebe-497f-4d81-9b53-1d8e8e9c2762">npm<span id="b5842b26-b603-4989-8049-691ec74b43c5">install</span>hexo-abbrlink<span id="ef762b16-4c31-45c4-bf10-6ee6fc305a0d">--save</span></code></pre><p id="bc462b8d-175b-40e3-954d-352eb041cd68">配置博客根目录下的_config.yml文件。</p><pre id="ac586101-2800-470e-83f0-5bf5b30f4fe8"><code id="63db9c40-3fc4-409f-b489-a1f0f9060e50"><span id="aa70c4eb-560c-4c62-a3fc-b9798ffb08c8">permalink: :title/</span><span id="06733800-010b-4481-b5ef-276c43397bf5">permalink:</span><span id="8965772f-f290-4771-a50e-6dfbba9e943b">archives/:abbrlink.html</span><span id="665cd78c-7820-4f36-a248-1f779faa6538">abbrlink:</span><span id="750b39a8-79f6-4b50-a94f-12d18f1fc45c">alg:</span><span id="b5b51a55-075c-4de5-936f-3aedc45e3507">crc32</span><span id="6fc261d5-5863-4a66-b485-ff5fd5665a37">算法:crc16(default) and crc32</span><span id="96dc63be-dbd7-467b-bdd6-48a92ab95d91">rep:</span><span id="b3cd4e9a-0c1e-408d-a876-e6c2be9022fd">hex</span><span id="d7ee5fb7-828d-46a1-ab60-fdf6595ff681">进制:dec(default) and hex</span></code></pre><p id="9a167aa4-97e9-48a3-af30-0abef4837b6a">运行<span id="7deeb1d6-26b2-47ea-84fc-af94ac2fa521"><span id="3195279d-b7a7-4a17-a0bd-cbae3cef4e4b">hexo clean</span></span>和<span id="f3e95b2b-6fd3-45e4-b90f-16851a0daef7"><span id="c39ccd15-5013-42f4-923e-1eab51913f6e">hexo g</span></span>命令来重新生成文件看看,可以清楚的看到,<span id="713e126a-dfb1-4e19-aa02-0f3db7285579"><span id="bfb4c8ae-e957-4867-a855-e4ba85b689ff">URL</span></span>结构成功变为了3层。</p><h1 id="d5f834a1-f159-4327-9e17-39407d5ba4b8">1.5 其他seo优化</h1><hr id="82af7e5c-e939-46e0-8116-e34afa65cd9c"></hr><p id="118410d1-6b06-422d-9a18-5e6eb25e5ae5"><span id="32b05f60-afc7-4149-ae19-2444967417b1"><span id="9a2d7049-e5a5-46e0-ba9a-72dd01ea5cf9">seo</span></span>优化应该说是一个收益延迟的行为,可能你做的优化短期内看不到什么效果,但是一定要坚持,<span id="c669f8aa-df71-458b-8f2d-d4fe0fe472f2"><span id="532f62f2-4041-4ecf-8957-326a1932fc55">seo</span></span>优化也是有很深的可以研究的东西,从我们最初的网站设计,和最基础的标签的选择都有很大的关系,网站设计就如我们刚刚说的,要让用户点击三次可以到达网站的任何一个页面,要增加高质量的外链,增加相关推荐(比如说我们经常见到右侧本站的最高阅读的排名列表),然后就是给每一个页面加上<span id="7b7422ae-556c-45d2-88a7-3bf6e1c39047"><span id="d119f6f9-5072-4f45-a706-f0aa4d962d43">keyword</span></span>和描述</p><p id="fdf664dc-2cf0-4228-8fa6-9fdeca56449d">在代码中,我们应该写出能让浏览器识别的语义化<span id="26e33688-683f-43c0-904b-71accee0b4bb"><span id="bf1e337b-876f-4593-b2e7-11baf0687ace">HTML</span></span>,这样有助于爬虫抓取更多的有效信息:爬虫依赖于标签来确定上下文和各个关键字的权重;并且对外链设置<span id="436e572e-d520-40ce-a37d-951d83972460"><span id="bccd2702-c2e4-46dd-8344-16ec101ae709">nofollow</span></span>标签,避免<span id="9f685a80-4f9c-4d8e-b056-65e1aa8a55bf"><span id="2cd5f907-a8df-43ab-aaa8-20082d7e9429">spider</span></span>爬着爬着就爬出去了(减少网站的跳出率),并且我们要尽量在一些比较大的网站增加我们站点的曝光率,因为<span id="33e429ba-1097-4e41-af0e-bb8253dc2652"><span id="283efa60-460c-415d-996f-646ab82f3094">spider</span></span>会经常访问大站,比如我们在掘金等技术社区发表文章中带有我们的站点,这样<span id="faf89e23-16ab-46ad-9454-a627e2712ad3"><span id="a9dd5879-48a3-403e-9b61-cb9f09bb8236">spider</span></span>是很有可能爬到我们中的站点的,so....</p><ul id="89767282-f146-4f59-9485-afb81d2b33a2"><li id="ca881b89-c868-4eef-b0f5-1be6ec8f4770">网站<strong id="3389b687-2718-4575-8232-fcd8115463f2">外链</strong>的推广度、数量和质量</li><li id="fbb3437f-8647-4366-b8a8-dfc18474a889">网站的<strong id="97c2dbae-4df3-47d5-9157-720b35ca2529">内链</strong>足够强大</li><li id="e533899c-3ff8-41cc-a027-2c19a932b2c5">网站的<strong id="7e951f0c-311a-4b00-9557-3cedd6b2cd6d">原创</strong>质量</li><li id="72bfdb98-2c14-47e7-a561-8c32cb506b5e">网站的<strong id="c8adcd09-3ad7-478d-9c7c-1b4aff6fa84f">年龄</strong>时间</li><li id="d2e4d100-9070-4540-9499-f51d2627c39e">网站的<strong id="5d6a5bcf-a0c1-46fa-9e29-56cea191bb59">更新频率</strong>(更新次数越多越好)</li><li id="ba9ba02d-92b7-4a3f-9f1b-7b77016eb42e">网站的<strong id="df145747-4414-4fce-9bdf-eb6d059623d8">服务器</strong></li><li id="3495ef2d-b44d-41c0-a6a6-4ea9f512121e">网站的<strong id="7d2f41a6-4846-4bbc-bf5a-165e6676cffa">流量</strong>:流量越高网站的权重越高</li><li id="bc045f9b-d6ba-4cf1-b1a4-222777f00f58">网站的<strong id="3673e433-6055-46c3-b886-82b6fc8200ec">关键词排名</strong>:关键词排名越靠前,网站的权重越高</li><li id="df82de32-e75e-4c7b-8881-e1067fd2e655">网站的<strong id="7c8ddec6-6f46-492f-ab82-801d9bcae507">收录</strong>数量:网站百度收录数量越多,网站百度权重越高</li><li id="6e145c1e-fda0-491b-b351-c4ddae8e5bef">网站的浏览量及深度:<strong id="a65196d4-835e-4f5c-8100-909731508fc9">用户体验</strong>越好,网站的百度权重越高</li></ul><h1 id="7c24dcab-7fb4-42b4-8623-69d4f4c87949">2. 优化代码块样式</h1><hr id="9f68fd69-7a57-4105-8dca-c17412e08bf3"></hr><p id="8fbe656b-775f-4169-ae11-3b15c15ab2f4">由于代码高亮插件<span id="3788b6a1-5989-4eb0-be2e-559cb44a091c"><span id="a010ca39-6702-4b12-a93e-3c38d8a1b9b5">prism_plugin</span></span>的样式没有行号显示和代码块整体复制功能,不是很方便,为了优化观感和易用性,我们可以对其进行修改:待续......</p><h1 id="012bd62c-3dff-45d9-96ce-09eab8fbc16a">2.1 给代码块开启行号</h1><hr id="de5eb786-80c7-400a-86cf-4839e0c8df8e"></hr><p id="6b7bf135-a46c-4793-8894-2b001d0d34db">我们在配置文件<span id="233eacb7-f55b-48b1-aaf6-b1a5d449f88c"><span id="d90711dd-43cf-4e2f-afa3-00485b1dd046">.yml</span></span>中找到<span id="fe3c8551-787a-4938-916b-7dfe1bd67b85"><span id="714ab592-0874-43c9-8c43-8b72a7322430">prism_plugin</span></span>配置项<span id="3c561596-81bf-4e3f-a9ae-fc9dfcf5b5b5"><span id="d876c484-a630-40ad-8850-e508b653041c">line_number: false( default false)</span></span>改为<span id="30dd88ca-bc7d-4f5f-8a09-700afc26da8d"><span id="7ef17225-5499-4f0e-8c48-57d0918d8312">true</span></span>,开启行号,但是在我们这个<span id="a1bcf2c6-4627-4c1a-a70d-94c1ef913fb3"><span id="a104ea3f-3303-45cc-a234-36760b1a81c7">matery</span></span>主题中中是无效的,有<span id="849553fa-1ba3-42e9-9d14-52deab1d588d"><span id="8f61d2a5-cae1-4509-85a4-eb19347a4e2a">bug</span></span>需要改一下<span id="2ee32c3b-2c46-42fb-8bef-c24cbb67fcd0"><span id="8ddf2a42-6ffd-490a-9936-e66765e00bec">matery.css</span></span>样式参数,在第<span id="8822ebd5-c39f-426c-880d-5b54865978b1"><span id="b832a346-45d7-43a3-8ffa-2350abd159e1">95</span></span>行位置将:</p><pre id="de27d4fc-2284-4356-9e7a-2ab8052ac044"><code id="35415cb6-606b-48d9-a591-a043fc1b85c1"><span id="21c2ac8c-9bac-4da9-a07d-9f7a453d03d8">pre</span>{<span id="ba15794b-2c70-47ca-bc2d-12bd8be5feae">padding</span>:<span id="9a4b00c9-a4e9-4e74-9432-882f1cd511a7">1.5rem</span><span id="731b2fc1-d4d5-4720-8d36-a183e003b970">!important</span>;<span id="a524215e-ff7e-496c-bc56-713ab47253b8">margin</span>:<span id="bb3af1d2-4eb6-47f4-8352-c59438610f2c">1rem</span><span id="b95ce8ee-b3dc-48b3-aaae-bcde9e8a7ec1">0</span><span id="893363e6-3192-4770-bf89-ba69bfdcdcb2">!important</span>;<span id="f9580f5d-d3cc-4624-af8c-7c7c3ae662a2">background</span>:<span id="6807fa06-3b56-4e06-a476-4f26bb5c9fcb">272822</span>;<span id="62874427-94fb-48c8-ac4d-e80ace0b26e2">overflow</span>: auto;<span id="b929dbb7-25b3-4bbe-bf08-566ec042695b">border-radius</span>:<span id="65e21912-1e48-4d4d-bd5e-08b5d45640c2">0.35rem</span>;<span id="85c9395a-e98c-4cfe-ac81-e4c32d6b1291">tab-size</span>:<span id="5ae71c9f-1751-415d-9574-bb466d7bc0e7">4</span>; }</code></pre><p id="59e41102-3908-4b25-aa28-f24b1ccec0ca">改为:</p><pre id="17ae8b3e-1831-45bc-8d89-8963f47c57c8"><code id="4900f47e-051f-4f08-a4c9-3b5eb6090804"><span id="b06a7b8a-4b11-4125-bc3f-2802a40530c7">pre</span>{<span id="5fdb5969-d650-4d63-9c9f-2945832126ae">padding</span>:<span id="39fd3a2a-b7e2-4a92-be93-058726818db6">1.5rem</span><span id="3a36aa4b-bc90-43ae-8567-dce2a5ec68bc">1.5rem</span><span id="df729693-71d7-4318-9cea-f834ec23e7a9">1.5rem</span><span id="df05f52e-757e-4541-a76e-3d3c5e1bbfdd">3.3rem</span><span id="8ef9bc24-7327-410c-9bcf-457770da64ad">!important</span>;<span id="4227e99d-4557-4b06-b7de-847328b1692b">margin</span>:<span id="a5d0669c-8b29-4402-97f6-c8ca3381d347">1rem</span><span id="152ec53d-b6c1-4e9a-81b7-f7d7b5ce8244">0</span><span id="d2e01a31-621f-48c8-8ab5-f6a3d974b922">!important</span>;<span id="9274ad18-002c-4677-90bb-37452c870a0d">background</span>:<span id="c2f6eaad-f6d7-4340-b0d5-e4767bb54a43">272822</span>;<span id="328a9664-cdae-4a09-a637-27efdab2e1ad">overflow</span>: auto;<span id="e66a3bfa-c762-4f6f-a0a0-7ca652e21a53">border-radius</span>:<span id="2de7f723-6d17-40ef-a467-1c574e634045">0.35rem</span>;<span id="efa2a238-0f6e-4d3f-8963-e8629e1c1b21">tab-size</span>:<span id="4a53df47-6c8b-4ff4-b763-860f986444c6">4</span>; }</code></pre><p id="dd39b90b-581d-44bf-8dd5-2a2a8058da94">注释掉紧接着的<span id="5841e2e9-2109-4093-971e-ba93cd84c388"><span id="037a6042-89e6-4b29-b608-324d2c929c84">code</span></span>代码块里面的<span id="58171024-660a-485f-9d06-e7b5e380fe5e"><span id="3c27fc60-8441-4d21-9011-c5df1ce531e0">font-size</span></span>项,如下:</p><pre id="449aa18c-0f94-416a-b048-fdab9e65f833"><code id="4cf1e310-2fd7-4a1c-b7d8-916edc4cb26f"><span id="a8926e33-bada-4234-b58e-a73ae8ab8a96">code</span>{<span id="51a78692-bf7d-4054-9551-85343f06cca6">padding</span>:<span id="ced8e046-43d4-4eb8-8b44-4b5c9c6cb9df">1px</span><span id="cbe71b5e-ff07-4737-87bb-fe296f0e2d01">5px</span>;<span id="2706a0e4-16c6-456b-9663-427f798ffec5">font-family</span>: Inconsolata, Monaco, Consolas,<span id="8b7c6456-e385-488e-9ff7-00360938ce3a">Courier New</span>, Courier, monospace;<span id="402c7f82-d36f-4c12-9dd4-ce70f4113e5a">/*font-size: 0.91rem;*/</span><span id="1d92fb2e-da8a-45df-9036-cb54405ad04b">color</span>:<span id="b4bcfa11-95ab-4e61-a377-15fcce3a841f">e96900</span>;<span id="70badf09-f74b-4d42-801f-c7baa82c50a9">background-color</span>:<span id="bcb8d397-8654-48c8-8007-9372123034cd">f8f8f8</span>;<span id="a4932d3a-192f-49cc-bdab-dcbd8065511a">border-radius</span>:<span id="bf43794b-2721-4d1e-b073-cf895ee38d20">2px</span>; }</code></pre><p id="994ca441-fecf-47c6-bae0-73c146f3233c">好了这下可以显示行号了,如图:</p><div id="661292fe-e3ac-422c-92a2-a209689fc8b4"><img src="https://p26.toutiaoimg.com/origin/pgc-image/123e9574f363483783579eff55228962?from=pc" /></div><h1 id="ed8e2022-23dd-42ee-8bb8-20e222668427">2.2 添加代码块复制功能</h1><hr id="d4c9d6c2-67b5-40cf-a8e7-ea8a203e38b6"></hr><h1 id="48e6362a-43ab-482b-868c-329514b84de4">3. 优化网站加载速度</h1><hr id="3568e66d-4634-462e-a8cf-2a1664b955c4"></hr><h1 id="a3b8dea6-7f7a-4f3a-9014-0665d52fcef0">3.1 优化图片加载</h1><hr id="4e5541ac-db26-4916-9098-73fecca1865e"></hr><p id="a716671d-beb4-47ef-8b28-ae3faf6ddd63"><span id="eccf4520-7d6d-4c41-8398-72f86dab55a7"><span id="b4fa6472-6dc3-4115-87d0-cdf9e601e72e">issue</span></span>问题:优化网站加载逻辑问题:图片最后加载,加入图片懒加载方法</p><p id="4f7b3924-85af-4135-a830-7132f69c0034">hexo-lazyload-image的作用原理是讲你博客里面img标签的src属性替换为一个loading image,把真实的图片地址放在data-origin属性下面。然后当你的网页翻到那张图片时(也就是图片在窗口中完全可见时),他会有一段js用data-origin的内容替换src,打到懒加载的目的。</p><p id="ed561aa2-5f6a-48c1-a547-45133a6c3f5c">一般情况下懒加载和gallery插件会发生冲突,比如按照我上面所说,最终结果就会变成,可能只有第一张图片在gallery中打开是原图,右翻左翻都会是那张loading image,需要你掌握js,可以修改matery.js里面的内容,甚至可能换一个gallery,比如photosiwpe之类的</p><p id="ebfb4a78-26dd-49bb-ba21-332ea8e71a9a">解决方法:修改<span id="a52d6097-ce60-4049-a118-7206dfb141b9"><span id="bfa45280-7a02-4d5c-821b-9c903289e654">/themes/matery/source/js</span></span>中的<span id="02574ebf-266d-430e-a27f-618dc059e10a"><span id="910aa2a0-261c-42a0-a9c5-1a4f53a36d18">matery.js</span></span>文件</p><p id="5635f7f5-6ad1-44d3-a099-5260faf0a1d5">第103行:</p><pre id="9518a875-1a4d-4ae0-b064-05926c3a0a21"><code id="5f76f996-b70b-4bdc-ba15-56278d0907b1"><span id="6d5d3886-c349-4e59-abc1-b9fd85088e8c">$(articleContent,</span><span id="6c0ec882-9ed6-4810-a097-9ac699ff854e">myGallery).lightGallery({</span><span id="ddac2c60-e9c7-4bc4-8cd8-b1d158aebcd4">selector:</span><span id="0cf48a60-aeb4-4a78-9e65-7dd45326966e">.img-item</span><span id="92bf2014-585b-4920-b35a-337ef944e174">,</span><span id="35fa6c97-91d9-43ab-90fb-081cefbecf77">//</span><span id="17e13f0d-06d1-4a47-8a9d-75cc5bc49f9d">启用字幕</span><span id="24607c5f-e5cf-477c-a3b5-a074852811e3">subHtmlSelectorRelative:</span><span id="486e2df3-9c47-4203-bc48-40b62a493efe">true</span><span id="1b9c09a3-cdb5-439a-bc73-b27425089a8b">,</span><span id="5df84658-f233-4a78-93a5-a038d3715261">showThumbByDefault:</span><span id="81ce1b8b-6ea2-4217-96de-fc6b889ebc85">false</span><span id="4751e70b-dda0-4d57-83e9-16c675631d71">//这句加上</span><span id="35b12e2f-3f8a-4440-a360-d346683d9266">});</span></code></pre><p id="3c402f55-f09c-4ffa-a572-5b4255a32c22">后面加上:</p><pre id="124950d9-9f1d-45d7-889b-57a20c914c77"><code id="8eae4df4-c377-4c50-9fd8-6786f92c447d">$(<span id="f5ec0835-f706-413d-9765-a826d7f853c1">document</span>).find(<span id="de55d070-476e-4433-9697-e4c1399046b0">img[data-original]</span>).each(<span id="d2269fc4-0cb3-40e1-b9db-784e60ee89eb"><span id="b2015618-e6af-4d29-8285-9db4ae25db68">function</span>()</span>{ $(<span id="3a40a115-d407-4e10-bb1b-7890a99fe1c3">this</span>).parent().attr(<span id="d1bf9701-c251-4da2-b538-0e33384bb330">"href"</span>, $(<span id="5fc0d140-1b43-48fc-9361-6911f77dc9da">this</span>).attr(<span id="db0893bd-3139-4dc1-9d26-6779d3271536">"data-original"</span>)); });</code></pre><p id="d0843711-5ba3-40c7-982c-0ffe52819ffc">再装个插件,<span id="eba8efd2-a10e-4c6f-9562-dcc5aa977b64">https://github.com/Troy-Yang/hexo-lazyload-image</span>在博客根目录配置.yml文件加入对应字段,如下:</p><pre id="44676c34-e4d6-4f8e-af13-0f441a5de3b0"><code id="f24fc2c7-4ef6-4174-8f06-3a6fd28065f3"><span id="6d417740-2e9a-46a5-b16d-fb6064b1b34e">lazyload configuration 2019.08.23</span><span id="43197ee7-ccea-4f04-99a9-09c8b3832ff4">lazyload:</span><span id="61d585ac-bd55-4fd0-a8c8-e8f8547eb097">enable:</span><span id="7692b6ff-5d1e-40fd-b342-d90d687af52b">true</span><span id="5f0b78df-50e4-4167-b243-9c726bd225a4">onlypost:</span><span id="3715c86a-993a-485c-9536-913d0ed42fde">false</span><span id="6f55ebba-19b0-4a68-acbe-bda56e3bd73f">loadingImg:</span><span id="aa60a700-2ae1-4fbf-a18f-c089a3399c52">eg ./images/loading.gif</span></code></pre><p id="3aec63e3-106a-42c5-9bc7-aa73cf11c0ea">好了,这样实现了博客网站的图片懒加载。</p><h1 id="d29a9090-e096-491a-8d67-ddfda4e8f0d0">3.2 Gulp实现代码压缩</h1><hr id="10cc241b-49fe-4465-9ff9-b7f3b9c03fd6"></hr><p id="91aab3eb-1096-4008-8d07-7cd67d748310"><span id="bd72a7f3-8399-476f-bd84-06c810427175"><span id="0ba16bc3-89b8-4b39-9c8c-4d6834b7a4c4">Gulp</span></span>实现代码压缩,以提升网页加载速度。</p><p id="be0c4f8f-2b28-4bc3-a148-e8a0da709e91">1 首先我们需要安装Gulp插件和5个功能模块,依次运行下面的两条命令。</p><pre id="905227da-862c-453f-902b-2d7c9210c4f7"><code id="60520595-089e-4784-80b9-fcdca365d84c">npm<span id="d9025ba7-817c-474f-a84d-2995efbb94cd">install</span>gulp -g<span id="60a76f50-9ba9-4f35-bfc2-9113c8c73d42">安装gulp</span><span id="0f4df8aa-c00f-4209-b0f5-9d13eb88498d">安装功能模块</span>npm<span id="acb01084-ae50-4d44-ba18-0504b87e64fb">install</span>gulp-htmlclean gulp-htmlmin gulp-minify-css gulp-uglify gulp-imagemin<span id="7ce5b658-0af6-43eb-9c76-5ea008110fed">--save</span><span id="44fe61fc-72db-41c6-aa29-740f81b311c4">额外的功能模块</span>npm<span id="5a971335-98e1-46c6-952d-c4b258977439">install</span>gulp-debug gulp-clean-css gulp-<span id="2f25d021-6627-44f4-b4ec-73235598e81b">changed</span>gulp-<span id="e074aaf9-7f9c-4731-8d69-a0fcbc6dfeed">if</span>gulp-plumber gulp-babel babel-preset-es2015 del<span id="8758b75f-3305-4fb9-804b-3b37e5cd8c07">--save</span></code></pre><p id="3964a420-3c0e-42e3-b434-d0ce037a284a">2 接下来在博客的根目录下新建gulpfile.js文件,并复制下面的内容到文件中。</p><pre id="d8aac7d4-60d9-4a43-9816-264c1f114580"><code id="02143b30-7055-42f7-a265-45cc2443e5b9"><span id="02ed14c1-47a6-402f-a88a-89079f7e176a">var</span>gulp =<span id="0c9bddf8-1c3a-4db3-8d16-6ebfb2503ab8">require</span>(<span id="76a4a4d7-de0b-429e-9999-d1ed8a9e5deb">"gulp"</span>);<span id="f9077e88-e15d-4e8d-924b-60d2715a255d">var</span>debug =<span id="427afd10-401e-4cdc-b83c-a9b31f943f8a">require</span>(<span id="a8704e66-46f8-40e6-852a-e93b002b70a9">"gulp-debug"</span>);<span id="d47ba010-b42d-4f14-8ca4-7e762e8fce1c">var</span>cleancss =<span id="1ee2cdf1-44de-4fb1-a388-1203b9816fac">require</span>(<span id="a787d663-f531-4ffb-86b2-8af42b06ba28">"gulp-clean-css"</span>);<span id="9921ff26-00f3-4e52-b9e9-f5a4ee8a2ec9">//css压缩组件</span><span id="e013a2e8-0c5a-4d4a-b6fc-a807640a1ca9">var</span>uglify =<span id="1b92a28d-4989-44c3-b3a3-49b7fc6d8d32">require</span>(<span id="54477009-2bc4-4d23-a227-8d5295a1aebf">"gulp-uglify"</span>);<span id="b1252489-b90d-4ab6-88d1-fed2d734bb23">//js压缩组件</span><span id="bbfb34b7-6728-4636-b627-84b83c4db87d">var</span>htmlmin =<span id="8f45a1fb-b5b1-480d-bd88-0469b3ee6259">require</span>(<span id="71c3cdc0-6e57-494d-91a6-8dfdd0d420c2">"gulp-htmlmin"</span>);<span id="22549296-f2a4-4881-8be1-cbdde888aa61">//html压缩组件</span><span id="091e6a17-1dba-4286-a5ff-61599b5f6fad">var</span>htmlclean =<span id="b6f7f033-e62a-4977-a7db-9c2e1f2e7021">require</span>(<span id="2d2d97a9-adb8-42a7-a54b-c457d9f982c2">"gulp-htmlclean"</span>);<span id="1b16ab67-404d-41d1-a93c-41716f6fa340">//html清理组件</span><span id="5aa5ecfe-b28b-4383-b512-fa180fdd56d7">var</span>imagemin =<span id="b9337bf7-891e-4d17-94e0-c3944c476a04">require</span>(<span id="8c22703b-0e88-4c53-a12e-d9477ff74894">"gulp-imagemin"</span>);<span id="0cfe98f9-1a66-485d-ac1b-f349e9b1b6e9">//图片压缩组件</span><span id="eb2bf797-1f79-4d75-b452-073b12cc69b4">var</span>changed =<span id="b43c473c-4123-4b3b-8f5d-1a8853ac9990">require</span>(<span id="a991a634-5d90-412d-a8b4-60c75d6f1998">"gulp-changed"</span>);<span id="7154202b-5502-4619-a02f-db1a352634ca">//文件更改校验组件</span><span id="0f7df25a-a12b-44bc-b392-b1a811fbccf3">var</span>gulpif =<span id="3e31ebe1-a844-4d4d-ab70-cf7290545b59">require</span>(<span id="8315a3c3-b841-43ce-a6da-8bca0cef976e">"gulp-if"</span>);<span id="ba91c35b-40c9-4be6-95d2-e489a8faa791">//任务 帮助调用组件</span><span id="cfddf06f-cd76-41d4-a24a-c60426cbaeeb">var</span>plumber =<span id="b3714f52-f052-4ff6-9d04-5522e7b73c16">require</span>(<span id="cf89da13-6828-42cc-abd6-17782fa6ea71">"gulp-plumber"</span>);<span id="5cc12266-d103-4aa5-aa43-6f85e137b0c7">//容错组件(发生错误不跳出任务,并报出错误内容)</span><span id="e9133949-d196-46f9-a799-48126b56cd30">var</span>isScriptAll =<span id="bf37806d-5fab-4bbe-a6a9-c49cc22c4e5b">true</span>;<span id="a3fbc199-db7c-46f1-827a-d2cbdae24a91">//是否处理所有文件,(true|处理所有文件)(false|只处理有更改的文件)</span><span id="f03ec7aa-8239-4728-a3da-6883070d663e">var</span>isDebug =<span id="b8409cfc-cd90-4e16-9c0d-14b2ddfe4505">true</span>;<span id="67aef142-40dc-49c0-a21b-a1a1978fb5fa">//是否调试显示 编译通过的文件</span><span id="f4aefd38-08c5-4ab5-b35f-2e65845e4bf0">var</span>gulpBabel =<span id="cf8f10e5-f070-45f2-86c4-adfade4b9232">require</span>(<span id="1061c72c-952f-4999-971a-e12402f9c945">"gulp-babel"</span>);<span id="fe7a455e-9f9e-4424-8141-6ea906339434">var</span>es2015Preset =<span id="205ddf9c-ff8d-4cdb-a72e-02dab6c16aec">require</span>(<span id="97ab77b0-29cf-4d51-9748-2cfcb71ae837">"babel-preset-es2015"</span>);<span id="803e1a77-dfd8-4801-b65b-d2bea811f7f5">var</span>del =<span id="f5a16e03-3fa5-488d-ba03-ed09cb26c00b">require</span>(<span id="8d44823f-c4ad-4a39-998a-2772bcd28bce">"del"</span>);<span id="e232ae2e-e0b4-483c-9568-1c3c977ef289">var</span>Hexo =<span id="9e6354cb-e979-443a-b551-0aeed8cccc34">require</span>(<span id="5b1abf6a-740b-4276-b80b-9a2f97632c40">"hexo"</span>);<span id="7e562995-0d29-4dcc-8f27-d31ebb1024c1">var</span>hexo =<span id="3701723a-e0c3-4113-b0e9-f3a0d7ee9549">new</span>Hexo(process.cwd(), {});<span id="02858f7c-d421-42c9-b033-36098e3dfa81">// 初始化一个hexo对象</span><span id="3ceb8852-9a65-4a46-a315-d796e0a94061">// 清除public文件夹</span>gulp.task(<span id="62a13e88-315a-4ea5-89e1-27ea409edfc0">"clean"</span>,<span id="c4cb8a47-77e1-4c1b-b20a-03c980c7cd17"><span id="ac2a1522-13ff-4e26-8094-7c2ab29e95ab">function</span><span id="62720ebf-d2e3-4562-814b-07ee7ab21a54">()</span></span>{<span id="13b21064-85d7-4023-b357-3e72d0a7cd4b">return</span>del([<span id="3d99cf27-229f-44af-b15c-5a40d26dcafb">"public/**/*"</span>]); });<span id="e9523f04-caa7-4e1c-9ebf-4710ababdbf6">// 下面几个跟hexo有关的操作,主要通过hexo.call()去执行,注意return</span><span id="afded0bd-e9e3-4f85-af6a-251e4a68ccee">// 创建静态页面 (等同 hexo generate)</span>gulp.task(<span id="967c082a-60da-4289-8ed4-c7ff0289920c">"generate"</span>,<span id="6d0bf043-641b-40a5-a6eb-a539adad6dcb"><span id="ecff6f29-20be-411b-bf48-6b6895e013c9">function</span><span id="7f6a0f40-6de2-4237-8b54-baa0c2599633">()</span></span>{<span id="4cc550bb-61af-4e42-a067-f8008060e2ae">return</span>hexo.init().then(<span id="d9ad67f2-a126-4101-94fd-c2a83e6f5fe0"><span id="6844ff03-0c43-4672-ac8e-dadf6f56b860">function</span><span id="5eced791-5584-4124-b7ed-a09806a01c8d">()</span></span>{<span id="06221c36-c24c-4222-8326-e64836bc7923">return</span>hexo .call(<span id="9f8a18dd-3675-45e2-a02f-522c74c387ed">"generate"</span>, { watch:<span id="74b2dda3-7093-43a7-868b-9f5f6834078e">false</span>}) .then(<span id="903bff0d-2347-40e8-aac9-fcf74c450658"><span id="1599e149-cd94-4f51-ba06-a6c14804475c">function</span><span id="36b88e68-fa49-408a-8ea4-15d5a53e22d4">()</span></span>{<span id="688c8332-a86b-42d3-92f4-cf510752748b">return</span>hexo.<span id="dd6abad2-195a-4a7a-904b-991591df0f43">exit</span>(); }) .<span id="e633f874-c8ac-45f7-aa45-bd941ed52281">catch</span>(<span id="287392be-3665-4dd3-b7e7-cf9f775205ae"><span id="7da30a30-94f0-4446-8ff7-7f91c72a0d3e">function</span><span id="45b6c013-1ab6-4142-8a61-ea679b44e412">(err)</span></span>{<span id="89aa86db-4e1f-40b1-b1a4-df43ff7ed02d">return</span>hexo.<span id="63938c96-3033-41d9-a5a6-c26204bae232">exit</span>(err); }); }); });<span id="bda5a03f-6d7d-41f4-86af-5241c4450cf7">// 启动Hexo服务器</span>gulp.task(<span id="8cf622d6-ed8c-4602-a521-7ec30503e40d">"server"</span>,<span id="af28d2f0-15ed-47ca-bfb9-97def4032672"><span id="3e920529-1285-418f-aba2-74ff9e1ccd16">function</span><span id="51cb1236-468e-4a8b-92d9-5bef3871e617">()</span></span>{<span id="96933242-4f34-4b7c-ba02-de9d3c4927cc">return</span>hexo .init() .then(<span id="c162384d-f882-4231-841c-755554eb106c"><span id="71a7ce00-08f9-4c54-951c-22702a636e70">function</span><span id="e4bbe9fb-6275-44df-b5ae-859e5e15ad4d">()</span></span>{<span id="e594e36f-1b3c-449d-956d-b2b6b1339590">return</span>hexo.call(<span id="aa999b50-471a-4ee2-b924-cb5f3bcecbcd">"server"</span>, {}); }) .<span id="dd521a2c-c6c6-45c2-b2ad-06cd1e4a4d35">catch</span>(<span id="ba2675a1-38ea-4f87-ac4c-3ace39046a16"><span id="657935e4-805d-4d03-8673-9415fcd417ba">function</span><span id="565431ac-93c5-49d5-b8e4-9918aa9c2e83">(err)</span></span>{ console.log(err); }); });<span id="7e547041-f19a-4dd8-a562-cfd0161d621b">// 部署到服务器</span>gulp.task(<span id="aa3eec41-eaed-4631-8245-9062482fe6b9">"deploy"</span>,<span id="f5703286-132e-4613-a79b-5ba27ee466cc"><span id="1c729cf9-a760-4fe5-ab35-778784a3c97a">function</span><span id="6910c990-93d2-4e06-97b7-c98edbb1b5ea">()</span></span>{<span id="20fa5f13-09e9-4694-994c-5a5b6fb84cc7">return</span>hexo.init().then(<span id="8ecf7ead-55bd-4059-b5b0-dee9caabfa17"><span id="6963903f-7d4c-4d81-9445-7f653b91484e">function</span><span id="7e608d87-dcd1-43f1-bd0d-5152bb9000de">()</span></span>{<span id="e50e8f70-5e81-4e99-8cf3-782e92fb366f">return</span>hexo .call(<span id="b26b5880-5a08-4e26-8c26-37521f2de169">"deploy"</span>, { watch:<span id="18cde827-a754-4cd9-a492-55c357e63c86">false</span>}) .then(<span id="b82da2a0-9c5b-4d7c-870f-285760b57005"><span id="a5a8e5b1-d768-4b4e-8ddc-b7a87d3a9e51">function</span><span id="1eb0ac57-b7b3-4b6f-b06a-c2b78186f2e2">()</span></span>{<span id="7e71378e-130b-4f94-849f-548f01ea3b75">return</span>hexo.<span id="3b9aa484-12c9-4587-95d9-5e51bc7c38b5">exit</span>(); }) .<span id="6e2786f4-9c3f-4c04-b419-511302b6bcc3">catch</span>(<span id="95698ea3-65ed-443f-8b44-72688a3e81b8"><span id="f80cf6ed-3dba-4488-b76b-2587a9038e5d">function</span><span id="c33bb17f-fd21-45cf-9f64-960a6c774960">(err)</span></span>{<span id="8d4f3c22-544a-427e-9f41-933d5ab03fd7">return</span>hexo.<span id="fe121301-bdf5-4b7b-a00c-9f7b473872ec">exit</span>(err); }); }); });<span id="25a1a027-2370-4f66-84ea-c076f016b0b8">// 压缩public目录下的js文件</span>gulp.task(<span id="e81ca7ca-4297-4c7b-a8ff-29792fcaf176">"compressJs"</span>,<span id="0967c313-12bf-49f7-9e3a-ac025135a1fd"><span id="32c54518-bc3b-43dc-9663-37a025090287">function</span><span id="8af0aebe-8c57-4b4d-904c-1dc14788306b">()</span></span>{<span id="c5bfe081-16a1-4e79-8c4e-74d52c64fa59">return</span>gulp .src([<span id="f5543fce-b9e1-4046-a391-ad0f167570bc">"./public/**/*.js"</span>,<span id="ab3471e4-6ab3-4b52-a7c4-b73b44469485">"!./public/libs/**"</span>])<span id="88c04299-06a8-4a75-940d-c088a476c5cf">//排除的js</span>.pipe(gulpif(!isScriptAll, changed(<span id="3a5617ee-7737-42ec-be09-eb9be0def07a">"./public"</span>))) .pipe(gulpif(isDebug, debug({ title:<span id="bc9628ef-ebae-4845-8c75-03063a87b6e2">"Compress JS:"</span>}))) .pipe(plumber()) .pipe( gulpBabel({ presets: [es2015Preset]<span id="7376b025-3539-4e81-b334-67c1a1539d97">// es5检查机制</span>}) ) .pipe(uglify())<span id="bc7c78ea-f53b-44b0-bd4f-095d2e4ebb71">//调用压缩组件方法uglify(),对合并的文件进行压缩</span>.pipe(gulp.dest(<span id="893b1363-71ce-4870-b4dd-7cf8cc109c55">"./public"</span>));<span id="3e4c6d92-54cf-45f3-a415-cbca60e69812">//输出到目标目录</span>});<span id="f822a6c8-0127-48ac-9bf6-c09d1793199d">// 压缩public目录下的css文件</span>gulp.task(<span id="6c24dbe6-b6ed-4bdf-93f2-d279c5dea7f4">"compressCss"</span>,<span id="84b0e43e-faad-4395-b448-3cf089de23b0"><span id="86ce516c-e47f-4fdb-bc65-5f2c38f4c9c8">function</span><span id="06d7fb8f-0eb5-4cf5-baec-d7d6a1f69c39">()</span></span>{<span id="f92bf577-aa41-4651-a5f3-44081406d19f">var</span>option = { rebase:<span id="1b41bc6d-7159-4668-8b0e-2a5f3d3f356a">false</span>,<span id="418730cb-2502-471a-9f15-b6a2206f0078">//advanced: true, //类型:Boolean 默认:true [是否开启高级优化(合并选择器等)]</span>compatibility:<span id="82faf885-3066-4951-bdf1-8f58afe0639b">"ie7"</span><span id="5d62b5a6-f3d9-47c9-b357-5a259bd90bb7">//保留ie7及以下兼容写法 类型:String 默认:or* [启用兼容模式; ie7:IE7兼容模式,ie8:IE8兼容模式,*:IE9+兼容模式]</span><span id="a0f0bb12-c2df-48c9-b37a-b5244470ea50">//keepBreaks: true, //类型:Boolean 默认:false [是否保留换行]</span><span id="c84ea9d2-91d0-4cb4-9596-01cd9aecfa57">//keepSpecialComments: * //保留所有特殊前缀 当你用autoprefixer生成的浏览器前缀,如果不加这个参数,有可能将会删除你的部分前缀</span>};<span id="417aa402-9622-4670-9182-3fa757d04072">return</span>gulp .src([<span id="ee1d24cf-bea8-407e-885b-82dadaba7c91">"./public/**/*.css"</span>,<span id="463a6748-4910-42af-9a3c-95537dd37e1c">"!./public/**/*.min.css"</span>])<span id="00644409-a712-44db-9a1a-3a3ae7985869">//排除的css</span>.pipe(gulpif(!isScriptAll, changed(<span id="4dd77e7a-70c4-47a0-be8e-ffe8ede9474a">"./public"</span>))) .pipe(gulpif(isDebug, debug({ title:<span id="2a8626b8-7124-4518-be5b-0edce4511e82">"Compress CSS:"</span>}))) .pipe(plumber()) .pipe(cleancss(option)) .pipe(gulp.dest(<span id="ed1fbc71-32de-45e7-a32e-815c52e4f4d4">"./public"</span>)); });<span id="a5ef0dd9-e590-459f-87f9-cfe95c55da44">// 压缩public目录下的html文件</span>gulp.task(<span id="0e613e84-e66c-437f-a18c-713c1e649267">"compressHtml"</span>,<span id="7f417365-7500-4200-8891-956ccd0d330d"><span id="b22257f5-c3bb-4648-9ac3-305cecf4e554">function</span><span id="5955ddbb-441f-4f5b-8fa1-b296ea710d1e">()</span></span>{<span id="23ec0fed-7a75-4669-b1af-704d1b12bf40">var</span>cleanOptions = { protect: /<\!--%fooTemplate\b.*?%-->/g,<span id="713efff8-dd7f-4f44-81f5-69fe16f33433">//忽略处理</span>unprotect: /<script [^>]*\btype=<span id="7512e0d5-81e5-4a85-9d2d-29f2a762d136">"text\/x-handlebars-template"</span>[\s\S]+?<\/script>/gi<span id="c9aa0d4f-f964-4ef4-bfe8-d24cc2d4908e">//特殊处理</span>};<span id="789c2de6-a99c-4089-8b08-ccc285eb6a44">var</span>minOption = { collapseWhitespace:<span id="841ac426-2757-4188-a59a-15744a5a622e">true</span>,<span id="25ac2cf9-4178-476e-a7c8-2d92bb58bb33">//压缩HTML</span>collapseBooleanAttributes:<span id="30439988-e838-4ee6-b16a-88f435178fa2">true</span>,<span id="fe09b5ce-cfe2-4cd7-8288-7f6e8fdc08d7">//省略布尔属性的值 <input checked="true"/> ==> <input /></span>removeEmptyAttributes:<span id="508112c1-a00a-49c7-8b56-906143ecb795">true</span>,<span id="fa32f466-f11c-4c8a-ac48-2ced8ba30196">//删除所有空格作属性值 <input id="" /> ==> <input /></span>removeScriptTypeAttributes:<span id="da67d012-1b6d-4c14-9088-e6f883e725e4">true</span>,<span id="6ea0f68c-52ec-4c32-98d4-50d109a63204">//删除<script>的type="text/javascript"</span>removeStyleLinkTypeAttributes:<span id="37656f96-bca7-45d8-80b6-13cc6db8cbca">true</span>,<span id="0f66ae68-c7c7-4c75-a67d-591a418a7ded">//删除<style>和<link>的type="text/css"</span>removeComments:<span id="6d985c03-faf5-45fb-9bda-5ecd08d54ead">true</span>,<span id="89679f4b-4bb8-4e72-be2d-eb5c86e15b32">//清除HTML注释</span>minifyJS:<span id="69cfd547-1c8f-43bc-bc6f-832b9eaeab6e">true</span>,<span id="71824841-8622-4b8a-bfb1-f78eb52d541a">//压缩页面JS</span>minifyCSS:<span id="0981251e-c773-49dd-8e77-b8d9c32fff6a">true</span>,<span id="8acfe43d-fc6f-4fa0-82db-d6bfb058e7c5">//压缩页面CSS</span>minifyURLs:<span id="5f17f8c8-d22e-44f2-9100-a0b1ef288fc9">true</span><span id="bfeb01c6-cce2-4002-95de-b00396036a91">//替换页面URL</span>};<span id="1aa1f9ca-2a15-4609-b70c-52acc031e246">return</span>gulp .src(<span id="51ac7339-3e5e-421f-a0b8-a3797baed7f5">"./public/**/*.html"</span>) .pipe(gulpif(isDebug, debug({ title:<span id="1880379d-3d78-40fa-a67d-62ad38dbbc06">"Compress HTML:"</span>}))) .pipe(plumber()) .pipe(htmlclean(cleanOptions)) .pipe(htmlmin(minOption)) .pipe(gulp.dest(<span id="e4ee3974-f2aa-4eb1-86c3-02690025db9f">"./public"</span>)); });<span id="4513c481-451b-411d-aee4-bc30482d2344">// 压缩 public/uploads 目录内图片</span>gulp.task(<span id="cd2afbdc-8d6f-4bbf-bdad-b4b2d76d3b92">"compressImage"</span>,<span id="3454d27e-390c-4d4f-b01d-47dd5f851f3f"><span id="65d23605-3b22-4f86-8c14-883a13fd3ab7">function</span><span id="cc0830ff-e994-477b-97ac-5f5432852fd1">()</span></span>{<span id="46746c4c-3f29-49d3-ab14-e8392e97c51c">var</span>option = { optimizationLevel:<span id="080efdfc-7756-4d9e-8fe1-9df738d2233e">5</span>,<span id="69e4d5fa-3581-40c2-a3c0-0159afaebaa4">//类型:Number 默认:3 取值范围:0-7(优化等级)</span>progressive:<span id="2ce8dbec-2ac0-4ea3-9852-9adf5be4ab2f">true</span>,<span id="12511aa1-a7fe-4bc8-86a8-4ec9f088a9e6">//类型:Boolean 默认:false 无损压缩jpg图片</span>interlaced:<span id="19830c8e-b5c6-4db0-854c-b6ea2278c62a">false</span>,<span id="84cacb35-8719-4634-95a2-6e1c1bbf26e3">//类型:Boolean 默认:false 隔行扫描gif进行渲染</span>multipass:<span id="67407e05-bf4b-41b8-a32d-a6b351d81f72">false</span><span id="d07bba75-4fb0-4781-9a6b-6f66741656dc">//类型:Boolean 默认:false 多次优化svg直到完全优化</span>};<span id="042860fa-3436-4e6a-a47e-54a2a449c22a">return</span>gulp .src(<span id="6240bf82-0e10-415a-9d31-d665170f5cb4">"./public/medias/**/*.*"</span>) .pipe(gulpif(!isScriptAll, changed(<span id="96eb3af4-85aa-4ed0-badc-44ed7b2e4cc8">"./public/medias"</span>))) .pipe(gulpif(isDebug, debug({ title:<span id="f8b731fc-98c9-4161-a25c-979298b51f2a">"Compress Images:"</span>}))) .pipe(plumber()) .pipe(imagemin(option)) .pipe(gulp.dest(<span id="a3c852a3-f55f-454c-ad49-39f5cf0cefb2">"./public"</span>)); });<span id="f9bfa604-1df1-4e67-b39c-48a1ca9c7b2e">// 执行顺序: 清除public目录 -> 产生原始博客内容 -> 执行压缩混淆 -> 部署到服务器</span>gulp.task(<span id="fe4668af-a688-477e-bca5-ea7c6e3441a3">"build"</span>, gulp.series(<span id="98be2805-880f-4bd0-b9ab-6cc087e773de">"clean"</span>,<span id="56456c54-c33b-44d3-a4d0-f3dc96b3c9aa">"generate"</span>,<span id="9f8fa678-78cf-4ddd-959b-017fa2e4add0">"compressHtml"</span>,<span id="fab88ab9-0e7e-4005-b7e2-1d170f1f1f14">"compressCss"</span>,<span id="a98740ba-f9f8-4270-bf6f-5c0f276068a3">"compressJs"</span>,<span id="985fb8ef-b9c2-49f8-acdc-7b8deb2f3c77">"compressImage"</span>, gulp.parallel(<span id="8d738ff6-cfd3-49bf-8ab5-4451e53eba45">"deploy"</span>) ) );<span id="4be44ffc-69e7-438f-86d0-efec7b85cc26">// 默认任务</span>gulp.task(<span id="fa733ea6-b927-49ff-8f4a-2eee06b589ed">"default"</span>, gulp.series(<span id="50a6520e-c41e-4af7-8eaf-ddc57945c868">"clean"</span>,<span id="4f933232-0e14-427c-b743-895937d80f75">"generate"</span>, gulp.parallel(<span id="9f6b0a9d-6d51-4203-8868-1b8077690915">"compressHtml"</span>,<span id="bb384bce-c03c-46b0-8705-150e728dc84a">"compressCss"</span>,<span id="62f85e1d-0759-44f0-8856-c45d3141b9d5">"compressImage"</span>,<span id="f7d38d26-23d2-4bec-a991-f9cfe96b0cc2">"compressJs"</span>) ) );<span id="07bcfd79-fdd6-4abf-aea2-a84556b8d53c">//Gulp4最大的一个改变就是gulp.task函数现在只支持两个参数,分别是任务名和运行任务的函数</span></code></pre><p id="efb1c697-a146-45d6-b269-c5de79c61f75">3 最后<span id="265a4fde-b6d3-4125-a937-cdafee3b5e99"><span id="47bdb892-30c3-4e1a-91b1-377f0cf2b0da">hexo clean</span></span>&&<span id="3fff8f97-7939-4190-833f-52c1381257a7"><span id="9c48d5b8-002a-4048-982a-c14341a21a77">hexo g</span></span>&&<span id="fa28110b-9deb-4a72-b091-3e8575066526"><span id="b4cedbb7-8fb2-4f32-817d-856ce3fa89c4">gulp</span></span>&&<span id="4129bb27-36f3-4259-abc7-403409564f3d"><span id="fbd4d308-7b9b-437c-84a3-ceff2edecadb">hexo d</span></span>就可以了。</p><blockquote id="0aa9934f-bd86-4736-825d-c360a7801283"><p id="ee7984b4-f5ee-4a53-851d-d32510fe5c88"><span id="9e1b9f7a-5b06-44c4-bd89-11ed474f5cbc">注意,很可能你会运行到第三步,也就是运行</span><span id="915ee8a4-9f6a-42cb-8216-ff70e5432d96"><span id="7081504d-e854-40d0-91aa-283db4ddac24">gulp</span></span>压缩命令时会报错,如图所示:</p></blockquote><p id="f638bcb0-4b07-4e4f-ab78-c01fbc836c73">那是因为gulp安装的本地版本和hexo自带的版本不对应导致,第三步gulp压缩可以用下面命令强制使用本地版本:</p><pre id="729be734-669f-4873-a217-68204fed674f"><code id="cb6126f5-4ce5-46bb-bb4a-a2f7ee880033"><span id="bc144d65-5e4c-4e66-be2e-3f5359f81ef1">node</span>./node_modules/gulp/bin/gulp.js</code></pre><h1 id="4cec3d5c-7c43-47a9-a80e-80d7780da876">3. 一些注意事项</h1><hr id="49fcd112-793f-43b2-a219-be105a757533"></hr><h1 id="f5e0d008-741c-4c70-8f69-86ff46c072c2">3.1 备份博客源文件</h1><hr id="f86b320e-8b28-4dbe-9f19-f8e1f0670268"></hr><p id="9d59f1a7-a833-4201-8f7d-cf6a46be3e44">有时候我们想换一台电脑继续写博客,最简单的方法就是把博客整个目录拷贝过去,就是这么暴力。不过,这种方法有个问题就是要是那天电脑崩了,本地源文件丢失了,比较麻烦,所以这时候就可以将博客目录下的所有源文件都上传到<span id="7742b06b-25f3-49f4-adfe-c749d111e8ad"><span id="39a57a63-f7ef-41d5-a170-64400c6501c7">github</span></span>上面。</p><p id="93298ec6-8b9c-481b-be45-4812ec819d1a">首先在<span id="32a06e0a-2d46-4b44-b3c1-5f09d0c1d061"><span id="c7f9ca1f-ae1b-45a6-ba29-eb8f8546e91b">github</span></span>博客仓库下新建一个分支<span id="d9cc04cb-9451-45ff-9280-f5911a084bab"><span id="25ec9a2e-48ca-47d1-8ec0-e3b284a18dc2">hexo</span></span>,然后<span id="cfade6df-948c-4895-9630-d18904678f42"><span id="d43910a5-47af-4569-aaea-9480b3f686e3">git clone</span></span>到本地,把<span id="6b90318f-a9c6-4397-830f-3aaf551cce7b"><span id="5e18aac7-35c3-452b-a1d7-05384ce2f6ae">.git</span></span>文件夹拿出来,放在博客根目录下。</p><p id="b68c4053-2b7d-4dc8-b4ef-513b1e3a6275">然后<span id="27024251-0916-4192-886d-b35fe081e993"><span id="18adb203-df7f-438f-b1f2-90343eba42fb">git branch -b hexo</span></span>切换到<span id="a224a224-4fc6-4559-bbe8-d9e392ce8929"><span id="f7c0a047-5960-43fe-862f-a851da9e93e2">hexo</span></span>分支,然后<span id="baab60fa-19cb-4487-aa8f-c11cd13ccd7b"><span id="b422f0fb-0701-4fae-b11e-99012c38cc19">git add .</span></span>,然后<span id="b69c3ed4-5c89-4f7f-af80-8dcfbec965d9"><span id="65d21c59-42e7-47ac-91fc-18a3594eac3e">git commit -m "xxx"</span></span>,最后<span id="fcfe107d-d55d-4225-8749-47013b3654d0"><span id="9579523e-a7f7-445a-80d6-33c655db14bd">git push origin hexo</span></span>提交就行了。</p><p id="69481f41-cf3e-438a-9a60-8f030781e2cc">具体效果可以看我的博客源文件仓库:传送门。</p><p id="a140c3fd-4058-4b15-a564-e0c925e77598">大家也可以先用下文<span id="9216c86d-833e-4ef7-8d10-33a086f67a3c"><span id="4f40f37c-3105-4c93-981f-e5cecee0d412">hexo</span></span>安装方法安装完<span id="444231f4-9d3a-4d72-b723-a51de13f2fc8"><span id="d826ec45-c9ff-4e71-a6b0-45e9327a835c">hexo</span></span>,然后直接<span id="6b13dea9-c870-405f-90b4-c827971f2dcb"><span id="cf905163-13ef-4b1b-8606-e354a556a219">git clone -b hexo<span id="981a7f2c-cf87-4167-ba33-16610aa41f65">https://github.com/shw2018/shw2018.github.io.git</span></span></span>克隆我的所有源文件,这是我目前修改完的基本没<span id="a35388f9-1def-40b2-a6b2-da7b33c50f88"><span id="b2a18058-c1f6-4b95-87a4-aca37b9a6799">bug</span></span>的定制化的博客,可以直接拿来用。</p><p id="d8e74400-ebfb-4ba5-8f9f-3af074ca765b"><span id="99ef01f6-c2ff-4926-a90c-085b90756227"><span id="f149a072-48fc-4dd9-8dec-0bbe6088d114"><span id="9c394a5d-c274-4678-b05d-e1de6be075fc">ps://github.com/shw2018/shw2018.github.io.git</span></span></span>克隆我的所有源文件,这是我目前修改完的基本没<span id="93d8086e-3ed9-49da-beec-d1ab76e32f0e"><span id="7f957e22-c27a-4d97-9ecf-6c399382ecfa">bug</span></span>的定制化的博客,可以直接拿来用。</p></body></html>

  非常感谢您读完蓝港网络的这篇文章:"Hexo Github:个人博客网站搭建完全教程(看这篇就够了)",仅为提供更多信息供用户参考使用或为学习交流的方便。我们公司提供:网站建设、网站制作、官网建设、SEO优化、小程序制作等服务,欢迎联系我们提供您的需求。

标签:

Copyright © 常州蓝港网络科技有限公司 苏ICP备2022017479号-1