Hexo自定

Hexo NexT主题添加点击爱心效果

创建js文件

/themes/next/source/js/src下新建文件clicklove.js,接着把该链接下的代码拷贝粘贴到clicklove.js文件中。
代码如下:

1
!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);

修改_layout.swig

\themes\next\layout\_layout.swig文件末尾添加:

1
2
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>

添加动态背景

_layout.swig

找到themes\next\layout\_layout.swig文件,添加内容:
在``里添加:

1
2
3
<div class="bg_content">
<canvas id="canvas"></canvas>
</div>

仍是该文件,在末尾添加:

1
<script type="text/javascript" src="/js/src/dynamic_bg.js"></script>

dynamic_bg.js

themes\next\source\js\src中新建文件dynamic_bg.js,代码链接中可见:dynamic_bg.js

custom.styl

themes\next\source\css\_custom\custom.styl文件末尾添加内容:

1
2
3
4
5
6
7
.bg_content {
position: fixed;
top: 0;
z-index: -1;
width: 100%;
height: 100%;
}

tag cloud

进入到 hexo 的根目录,在命令行中输入npm install hexo-tag-cloud@^2.0.* --save

package.json 中添加依赖: "hexo-tag-cloud": "2.0.*" ,在

在文件 theme/next/layout/_macro/sidebar.swig的</nav>标签之前添加如下代码:

1
2
3
4
5
6
7
8
9
10
11
12
{% if site.tags.length > 1 %}
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
<div class="widget-wrap">
<h3 class="widget-title">Tag Cloud</h3>
<div id="myCanvasContainer" class="widget tagcloud">
<canvas width="250" height="250" id="resCanvas" style="width=100%">
{{ list_tags() }}
</canvas>
</div>
</div>
{% endif %}

增加新页面页面

hexo new post tags/about/archive

其中对于tags:

open …/_posts/tags/index.md

title: tags
date: 2020-05-21 18:35:04
layout: “tags”
type: tags

bug

导航栏中点击tags,archive,home,浏览器提示找不到,比如annot GET /tags/%20/

对theme/next/_config.yml文件进行编辑,将中“||”前的空格删掉,上面已经是编辑好的配置,如下所示。

menu:

home: /|| home

about: /about/|| user

tags: /tags/|| tags

#categories: /categories/ || th

archives: /archives/|| archive

#schedule: /schedule/ || calendar

#sitemap: /sitemap.xml || sitemap

# commonweal: /404/|| heartbeat