打造个性博客 添加RSS 添加动态背景 修改文章内链接文本样式 修改文章底部的那个带#号的标签 在每篇文章末尾统一添加“本文结束”标记 修改作者头像并旋转 博文压缩 修改代码块自定义样式 侧边栏社交小图标设置 主页文章添加阴影效果 在网站底部加上访问量 添加热度 网站底部字数统计 添加 EREADME.md 文件 设置网站图标 实现统计功能 在文章底部增加版权信息 添加评论 隐藏网页底部powered By Hexo / 强力驱动 修改网页底部的桃心 文章加密访问 添加 jiahis 分享 博文置顶 修改字体大小 修改打赏字体不闪动 自定义鼠标样式 为博文加上宠物 DaoVoice 在线联系 点击爆炸效果 效果 安装 Hexo 插件:(这个插件会放在node_modules这个文件夹里)
1 2 cd */blog $ npm install --save hexo-generator-feed
修改 Hexo 配置文件 _config.yml 添加如下信息
1 2 3 plugins: hexo-generate-feed
然后打开next主题文件夹里面的 _config.yml ,在里面配置为如下样子:(就是在 rss: 的后面加上 /atom.xml ,注意在冒号后面要加一个空格)
配置完之后运行:
重新生成一次,你会在 ./public 文件夹中看到 atom.xml 文件。然后启动服务器查看是否有效,之后再部署到 Git 平台中。
添加动态背景 效果 实现方法 直接在主题配置文件中找到 canvas_nest: false ,把它改为 canvas_nest: true 就行了(注意分号后面要加一个空格)
修改文章内链接文本样式 效果 实现方法 修改文件 themes\next\source\css_common\components\post\post.styl,在末尾添加如下css样式,:
1 2 3 4 5 6 7 8 9 10 11 // 文章内链接文本样式 .post-body p a{ color: border-bottom: none; border-bottom: 1px solid &:hover { color: border-bottom: none; border-bottom: 1px solid } }
其中选择.post-body 是为了不影响标题,选择 p 是为了不影响首页“阅读全文”的显示样式,颜色可以自己定义。
修改文章底部的那个带#号的标签 效果 实现方法 修改模板 /themes/next/layout/_macro/post.swig,搜索 rel=”tag”>#,将 # 换成
在每篇文章末尾统一添加“本文结束”标记 效果 实现方法 在路径 \themes\next\layout_macro 中新建 passage-end-tag.swig 文件,并添加以下内容:
1 2 3 4 5 <div> {% if not is_index %} <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div> {% endif %} </div>
接着打开\themes\next\layout_macro\post.swig文件,在post-body 之后, post-footer 之前添加如下画红色部分代码(post-footer之前两个DIV): 代码如下
1 2 3 4 5 <div> {% if not is_index %} {% include 'passage-end-tag.swig' %} {% endif %} </div>
然后打开主题配置文件(_config.yml),在末尾添加:
1 2 3 passage_end_tag: enabled: true
完成以上设置之后,在每篇文章之后都会添加如上效果图的样子。
修改作者头像并旋转 打开 \themes\next\source\css_common\components\sidebar\sidebar-author.styl ,在里面添加如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 .site-author-image { display: block; margin: 0 auto; padding: $site-author-image-padding; max -width: $site-author-image-width; height: $site-author-image-height; border: $site-author-image-border-width solid $site-author-image-border-color; /* 头像圆形 */ border-radius: 80px; -webkit-border-radius: 80px; -moz-border-radius: 80px; box-shadow: inset 0 -1px 0 /* 设置循环动画 [animation: (play)动画名称 (2s)动画播放时长单位秒或微秒 (ase-out)动画播放的速度曲线为以低速结束 (1s)等待1 秒然后开始动画 (1 )动画播放次数(infinite为循环播放) ]*/ /* 鼠标经过头像旋转360 度 */ -webkit-transition: -webkit-transform 1.0 s ease-out; -moz-transition: -moz-transform 1.0 s ease-out; transition: transform 1.0 s ease-out; } img:hover { /* 鼠标经过停止头像旋转 -webkit-animation-play-state:paused; animation-play-state:paused;*/ /* 鼠标经过头像旋转360 度 */ -webkit-transform: rotateZ(360deg); -moz-transform: rotateZ(360deg); transform: rotateZ(360deg); } /* Z 轴旋转动画 */ @-webkit-keyframes play { 0 % { -webkit-transform: rotateZ(0deg); } 100 % { -webkit-transform: rotateZ(-360deg); } } @-moz-keyframes play { 0 % { -moz-transform: rotateZ(0deg); } 100 % { -moz-transform: rotateZ(-360deg); } } @keyframes play { 0 % { transform: rotateZ(0deg); } 100 % { transform: rotateZ(-360deg); } }
博文压缩 在站点的根目录下执行以下命令:
1 2 $ npm install gulp -g $ npm install gulp-minify-css gulp-uglify gulp-htmlmin gulp-htmlclean gulp --save
在Blog根目录新建 gulpfile.js ,并填入以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 var gulp = require('gulp' ); var minifycss = require('gulp-minify-css' ); var uglify = require('gulp-uglify' ); var htmlmin = require('gulp-htmlmin' ); var htmlclean = require('gulp-htmlclean' ); // 压缩 public 目录 css gulp.task('minify-css' , function() { return gulp.src('./public/**/*.css' ) .pipe(minifycss()) .pipe(gulp.dest('./public' )); }); // 压缩 public 目录 html gulp.task('minify-html' , function() { return gulp.src('./public/**/*.html' ) .pipe(htmlclean()) .pipe(htmlmin({ removeComments: true, minifyJS: true, minifyCSS: true, minifyURLs: true, })) .pipe(gulp.dest('./public' )) }); // 压缩 public/js 目录 js gulp.task('minify-js' , function() { return gulp.src('./public/**/*.js' ) .pipe(uglify()) .pipe(gulp.dest('./public' )); }); // 执行 gulp 命令时执行的任务 gulp.task('default' , [ 'minify-html' ,'minify-css' ,'minify-js' ]);
生成博文是执行 hexo g && gulp 就会根据 gulpfile.js 中的配置,对 public 目录中的静态资源文件进行压缩。
修改``代码块自定义样式 打开 \themes\next\source\css_custom\custom.styl ,向里面加入:(颜色可以自己定义)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Custom styles. code { color: background: margin: 2px; } // 大代码块的自定义样式 .highlight, pre { margin: 5px 0 ; padding: 5px; border-radius: 3px; } .highlight, code, pre { border: 1px solid }
侧边栏社交小图标设置 效果 打开主题配置文件(_config.yml),搜索 social_icons: ,在图标库 找自己喜欢的小图标,并将名字复制在如下位置,保存即可 主页文章添加阴影效果 打开 \themes\next\source\css_custom\custom.styl ,向里面加入:
1 2 3 4 5 6 7 8 // 主页文章添加阴影效果 .post { margin-top: 60px; margin-bottom: 60px; padding: 25px; -webkit-box-shadow: 0 0 5px rgba(202 , 203 , 203 , .5 ); -moz-box-shadow: 0 0 5px rgba(202 , 203 , 204 , .5 ); }
在网站底部加上访问量 打开 \themes\next\layout_partials\footer.swig 文件,在copyright前加上: 代码如下
1 <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
然后再合适的位置添加显示统计的代码 代码如下
1 2 3 4 5 <div class="powered-by"> <i class="fa fa-user-md"></i><span id="busuanzi_container_site_uv"> 本站访客数:<span id="busuanzi_value_site_uv"></span> </span> </div>
在这里有两中不同计算方式的统计代码:
pv的方式,单个用户连续点击n篇文章,记录n次访问量
1 2 3 <span id ="busuanzi_container_site_pv" > 本站总访问量<span id="busuanzi_value_site_pv"></span>次 </span>
uv的方式,单个用户连续点击n篇文章,只记录1次访客数
1 2 3 <span id ="busuanzi_container_site_uv" > 本站总访问量<span id="busuanzi_value_site_uv"></span>次 </span>
添加之后再执行 hexo d -g ,然后再刷新页面就能看到效果
添加热度 实现方法 next主题集成 leanCloud ,打开 /themes/next/layout/_macro/post.swig ,在画红线的区域添加 ℃ : 然后打开,/themes/next/languages/zh-Hans.yml,将画红框的改为热度就可以了
网站底部字数统计 切换到根目录下,然后运行如下代码
1 $ npm install hexo-wordcount --save
然后在 /themes/next/layout/_partials/footer.swig 文件尾部加上:
1 2 3 4 <div class="theme-info"> <div class="powered-by"></div> <span class="post-count">博客全站共{{ totalcount(site) }}字</span> </div>
添加 README.md 文件 每个项目下一般都有一个 README.md 文件,但是使用 hexo 部署到仓库后,项目下是没有 README.md 文件的。
在 Hexo 目录下的 source 根目录下添加一个 README.md 文件,修改站点配置文件 _config.yml,将 skip_render 参数的值设置为
保存退出即可。再次使用 hexo d 命令部署博客的时候就不会在渲染 README.md 这个文件了。
设置网站的图标 实现方法 在 EasyIcon 中找一张(32*32)的ico图标,或者去别的网站下载或者制作,并将图标名称改为 favicon.ico,然后把图标放在 /themes/next/source/images 里,并且修改主题配置文件:
实现统计功能 实现方法 在根目录下安装 hexo-wordcount ,运行:
1 $ npm install hexo-wordcount --save
然后在主题的配置文件中,配置如下:
1 2 3 4 5 6 # Post wordcount display settings # Dependencies: https://github.com/willin/hexo-wordcount post_wordcount: item_text: true wordcount: true min2read: true
在文章底部增加版权信息 在目录 next/layout/_macro/ 下添加 my-copyright.swig:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 {% if page.copyright %} <div class="my_post_copyright"> <script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script> <!-- JS库 sweetalert 可修改路径 --> <script src="https://cdn.bootcss.com/jquery/2.0.0/jquery.min.js"></script> <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script> <p><span>本文标题:</span><a href="{{ url_for(page.path) }}">{{ page.title }}</a></p> <p><span>文章作者:</span><a href="/" title="访问 {{ theme.author }} 的个人博客">{{ theme.author }}</a></p> <p><span>发布时间:</span>{{ page.date.format("YYYY年MM月DD日 - HH:mm") }}</p> <p><span>最后更新:</span>{{ page.updated.format("YYYY年MM月DD日 - HH:mm") }}</p> <p><span>原始链接:</span><a href="{{ url_for(page.path) }}" title="{{ page.title }}">{{ page.permalink }}</a> <span class="copy-path" title="点击复制文章链接"><i class="fa fa-clipboard" data-clipboard-text="{{ page.permalink }}" aria-label="复制成功!"></i></span> </p> <p><span>许可协议:</span><i class="fa fa-creative-commons"></i> <a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p> </div> <script> var clipboard = new Clipboard('.fa-clipboard' ); $(".fa-clipboard" ).click(function(){ clipboard.on('success' , function(){ swal({ title: "" , text: '复制成功' , icon: "success" , showConfirmButton: true }); }); }); </script> {% endif %}
在目录 next/source/css/_common/components/post/ 下添加 my-post-copyright.styl :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 .my_post_copyright { width: 85 %; max -width: 45em; margin: 2.8 em auto 0 ; padding: 0.5 em 1.0 em; border: 1px solid font-size: 0.93 rem; line-height: 1.6 em; word-break : break -all ; background: rgba(255 ,255 ,255 ,0.4 ); } .my_post_copyright p{margin:0 ;} .my_post_copyright span { display: inline-block; width: 5.2 em; color: font-weight: bold; } .my_post_copyright .raw { margin-left: 1em; width: 5em; } .my_post_copyright a { color: border-bottom:0 ; } .my_post_copyright a:hover { color: text-decoration: underline; } .my_post_copyright:hover .fa-clipboard { color: } .my_post_copyright .post-url:hover { font-weight: normal; } .my_post_copyright .copy-path { margin-left: 1em; width: 1em; +mobile(){display:none;} } .my_post_copyright .copy-path:hover { color: cursor: pointer; }
修改 next/layout/_macro/post.swig ,在代码
1 2 3 4 5 <div> {% if not is_index %} {% include 'wechat-subscriber.swig' %} {% endif %} </div>
之前添加增加如下代码:
1 2 3 4 5 <div> {% if not is_index %} {% include 'my-copyright.swig' %} {% endif %} </div>
修改 next/source/css/_common/components/post/post.styl 文件,在最后一行增加代码:
1 @import "my-post-copyright"
保存重新生成即可。 如果要在该博文下面增加版权信息的显示,需要在 Markdown 中增加 copyright: true 的设置,类似:
小技巧:如果你觉得每次都要输入 copyright: true 很麻烦的话,那么在 /scaffolds/post.md 文件中添加: 这样每次hexo new “你的内容”之后,生成的md文件会自动把copyright:加到里面去
添加评论 试过后再添加 隐藏网页底部powered By Hexo / 强力驱动 打开 themes/next/layout/_partials/footer.swig ,使用””隐藏之间的代码即可,或者直接删除。位置如图:
修改网页底部的桃心 还是打开 themes/next/layout/_partials/footer.swig ,找到: 然后还是在图标库 中找到你自己喜欢的图标,然后修改画红线的部分就可以了。
文章加密访问 打开 themes->next->layout->_partials->head.swig 文件,在以下位置插入这样一段代码: 代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 <script> (function () { if ('{{ page.password }}') { if (prompt('请输入文章密码') !== '{{ page.password }}') { alert('密码错误!'); if (history.length === 1) { location.replace("http://xxxxxxx.xxx"); // 这里替换成你的首页 } else { history.back(); } } } })(); </script>
然后在文章上写成类似这样:
添加jiathis分享 注意:JiaThis 不支持 https 在主题配置文件中,JiaThis为true,就行了,如下图