经过在网上的学习,又在hexo的Next主题中添加了几个比较好玩的东西,以下:
注:此功能某些只对 next
主题有效。javascript
_config.yml
pace: true 下面是加载时显示的效果
一种方法是手动对相关文件进行修改,具体可参考博文置顶。css
另外一种方法就是,目前已经有修改后支持置顶的仓库,java
npm uninstall hexo-generator-index --save npm install hexo-generator-index-pin-top --save
Front-matter
中加上 top: true
便可。好比下面这篇文章:--- title: Hexo好玩的小东西 date: 2018-06-12 18:59:12 top: true ... ---
/blog/themes/next/layout/_macro
目录下的 post.swig
文件,定位到 <div class="post-meta">
标签下,插入以下代码:{% if post.top %} <i class="fa fa-thumb-tack"></i> <font color=7D26CD>置顶</font> <span class="post-meta-divider">|</span> {% endif %}
在 /themes/next/source/js/src
下新建文件 clicklove.js
,接着把该连接下的代码拷贝粘贴到 clicklove.js
文件中。添加的代码以下:git
!function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document);
在 \themes\next\layout\_layout.swig
文件末尾添加:github
<!-- 页面点击小红心 --> <script type="text/javascript" src="/js/src/clicklove.js"></script>
在 next\source\js\src
文件夹下建立 crash_cheat.js
,添加代码以下:web
<!--崩溃欺骗--> var OriginTitle = document.title; var titleTime; document.addEventListener('visibilitychange', function () { if (document.hidden) { $('[rel="icon"]').attr('href', "/img/TEP.ico"); document.title = '╭(°A°`)╮ 页面崩溃啦 ~'; clearTimeout(titleTime); } else { $('[rel="icon"]').attr('href', "/favicon.ico"); document.title = '(ฅ>ω<*ฅ) 噫又好了~' + OriginTitle; titleTime = setTimeout(function () { document.title = OriginTitle; }, 2000); } });
在 next\layout\_layout.swig
文件中,添加引用(注:在swig
末尾添加):shell
<!--崩溃欺骗--> <script type="text/javascript" src="/js/src/crash_cheat.js"></script>
app_id
,后面会用到/themes/next/layout/_partials/head.swig
文件,添加内容以下:{% if theme.daovoice %} <script> (function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/0f81ff2f.js","daovoice") daovoice('init', { app_id: "{{theme.daovoice_app_id}}" }); daovoice('update'); </script> {% endif %}
_config.yml
文件中添加内容:# Online contact daovoice: true daovoice_app_id: # 这里填你刚才得到的 app_id
网页的在线联系功能已经完成,从新hexo g,hexo d上传GitHub后,页面上就能看到效果了。
效果请看右下角npm
\themes\next\layout\_macro
中新建 passage-end-tag.swig
文件,添加代码至该文件中:<div> {% if not is_index %} <div style="text-align:center;color: #ccc;font-size:16px;font-family: cursive;">-------------纸短情长 <i class="fa fa-umbrella"></i> 下次再见-------------</div> {% endif %} </div>
\themes\next\layout\_macro\post.swig
文件,在 post-body
后,post-footer
前,添加下面内容:<div> {% if not is_index %} {% include 'passage-end-tag.swig' %} {% endif %} </div>
_config.yml
,在末尾添加:# 文章末尾添加“本文结束”标记 passage_end_tag: enabled: true
此刻,看下面,这就是结束语啦api
themes\next\source
文件夹下。themes\next\source\dist\music.js
文件,添加内容:const ap = new APlayer({ container: document.getElementById('aplayer'), fixed: true, autoplay: true, volume: 0.3, loop: 'all', audio: [ { name: "逍遥叹", artist: '徐薇', url: 'http://other.web.ri01.sycdn.kuwo.cn/resource/n3/24/12/4042158646.mp3', cover: 'http://imge.kugou.com/stdmusic/20171117/20171117142652315559.jpg', }, { name: '红昭愿', artist: '音阙诗听', url: 'http://up.mcyt.net/?down/45962.mp3', cover: 'http://imge.kugou.com/stdmusic/20170407/20170407225248906484.jpg', }, { name: '时间煮雨', artist: '郁可惟', url: 'http://up.mcyt.net/?down/37600.mp3', cover: 'http://imge.kugou.com/stdmusic/20130625/20130625181709936236.jpg', }, { name: '爱情转移', artist: '陈奕迅', url: 'http://other.web.ra01.sycdn.kuwo.cn/resource/n2/320/52/97/1397406180.mp3', cover: 'http://imge.kugou.com/stdmusic/20161010/20161010200518926406.jpg', } ] });
源码中对应的参数解释,这边都有:Aplayer 中文文档hexo
audio对应的即是音频文件,因此音乐播放器须要播放的音乐是须要本身进行相关信息(如歌曲连接、歌词、封面等)的配置。这里放一个mp3音乐外链网站:(http://www.170mv.com/tool/song/) ,搜索酷我中对应的音乐,而后解析出外联网址;对应土平的话能够在酷狗上找到并单击右键保存。
注:因为该外链网站没有歌词连接,我这边没有进行配置,因此播放器在播放音乐时点击歌词是没有显示的。
themes\next\layout\_layout.swig
文件,将如下文件添加到 <body itemscope ...>
后面就行,即在 <body></body>
里面。<link rel="stylesheet" href="/dist/APlayer.min.css"> <div id="aplayer"></div> <script type="text/javascript" src="/dist/APlayer.min.js"></script> <script type="text/javascript" src="/dist/music.js"></script>
next\layout_partials\share\baidushare.swig
文件中代码显示:{% if theme.baidushare.type === "button" %} ... ... {% elseif theme.baidushare.type === "slide" %} ... ...
baidushare: type: slide baidushare: true
_config.yml
中提示:Warning: Baidu Share does not support https.
由于百度分享不支持在 https
上使用,因此一种解决方法即是,直接放文件到咱们本身的目录下面。访问连接:static文件夹
下载压缩包到本地,解压后,将 static
文件夹保存至 themes\next\source
目录下。
themes\next\layout_partials\share\baidushare.swig
文件# 将 末尾 部分的代码: .src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)]; # 改成: .src='/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
_config.yml
中打开 wordcount
统计功能便可。以下所示:post_wordcount: item_text: true wordcount: true # 单篇 字数统计 min2read: false # 单篇 阅读时长 totalcount: true # 网站 字数统计 separated_meta: false
hexo-wordcount
插件npm i --save hexo-wordcount
next/layout/_macro/post.swig
修改字数统计、阅读时长(只须要添加文字便可):<span title="{{ __('post.wordcount') }}"> {{ wordcount(post.content) }} 字 </span> <span title="{{ __('post.min2read') }}"> {{ min2read(post.content) }} 分钟 </span>
找到文件 next/layout/_partials/footer.swig
,将下面内容复制粘贴进去便可:
<section class="footer-time"> <span class="footer__copyright"> <div> <span id="span_dt_dt"> </span> <script language="javascript"> function show_date_time(){ window.setTimeout("show_date_time()", 1000); BirthDay=new Date("6/8/2018 10:56:12");//这个日期是能够修改的 today=new Date(); timeold=(today.getTime()-BirthDay.getTime());//其实仅仅改了这里 sectimeold=timeold/1000 secondsold=Math.floor(sectimeold); msPerDay=24*60*60*1000 e_daysold=timeold/msPerDay daysold=Math.floor(e_daysold); e_hrsold=(e_daysold-daysold)*24; hrsold=Math.floor(e_hrsold); e_minsold=(e_hrsold-hrsold)*60; minsold=Math.floor((e_hrsold-hrsold)*60); seconds=Math.floor((e_minsold-minsold)*60); span_dt_dt.innerHTML="一世长安的博客已经运行 "+daysold+" 天 "+hrsold+" 小时 "+minsold+" 分 "+seconds+" 秒"; } show_date_time(); </script> </div> <script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"> </script> </section>
找到文件 next/layout/_partials/footer.swig
将下面代码删除便可:
{% if theme.footer.powered %} <div class="powered-by">{# #}{{ __('footer.powered', '<a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a>') }}{# #}</div> {% endif %} {% if theme.footer.powered and theme.footer.theme.enable %} <span class="post-meta-divider">|</span> {% endif %} {% if theme.footer.theme.enable %} <div class="theme-info">{# #}{{ __('footer.theme') }} — {# #}<a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">{# #}NexT.{{ theme.scheme }}{# #}</a>{% if theme.footer.theme.version %} v{{ theme.version }}{% endif %}{# #}</div> {% endif %}
npm install --save hexo-helper-live2d
live2d: enable: true scriptFrom: local model: use: live2d-widget-model-wanko display: position: right width: 150 height: 300 mobile: show: true
注:萌妹纸功能是集成在 yilia
主题中的,next
主题我还没发现有这个功能,因此若是使用的话,确实会有一个可爱的萌妹纸出如今你的网页上,可是:你用代码控制不了她(比方说妹纸的人选、大小、位置等)。
参考连接1:(https://asdfv1929.github.io/)
参考连接2:(http://www.aisun.org/2017/10/...