最近突然迷上了next主题,故换上这个新装,并初步进行了相关文章、本地搜索、页面点击效果、文章置顶、网页标签图标等设置,算是简单的完成了这次的主题的配置,后期还待优化,毕竟next主题自定义和扩展都很丰富。
1. 添加相关文章功能
插件:hexo-related-popular-posts
插件地址:https://github.com/tea3/hexo-related-popular-posts#1-edit-your-theme
安装:npm install hexo-related-popular-posts –save
修改:hexo-theme-next/blob/master/layout/_macro/post.swig文件
修改如下
1 | </footer> |
2. 添加本地搜索功能
插件:hexo-generator-search
npm install hexo-generator-search --save
在站点配置文件_config.yml添加如下
1 | # Search |
修改主题配置文件_config.yml如下
1 | local_search: |
3. 添加页面点击效果
修改_layout.swig,并在\themes\next\layout_layout.swig文件末尾添加
1 | <script type="text/javascript" src="/js/clicklove.js"></script> |
创建clicklove.js文件并置于/themes/next/source/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); |
4. 添加文章置顶
修改 hero-generator-index
插件,将文件:node_modules/hexo-generator-index/lib/generator.js 内的代码替换为:
1 | ; |
之后在文章中添加top属性即可,赋值越大排名越高
1 | title: test |
5. 添加网页标签图标
修改主题配置文件
1 | favicon: |
这里用的都是一张图片,next原配置也是用的一张图片只是格式大小不同,我试过直接设置favicon: /images/favicon.ico 但是会报错。
6. 设置网页加载进度条
这里用到的是theme-next-pace
地址如下:https://github.com/theme-next/theme-next-pace
1 | pace: |
7. 设置标签样式
修改主题配置文件,这里因为我用的是next最新版本直接设置即可,
1 | # Use icon instead of the symbol # to indicate the tag at the bottom of the post |
旧版可以通过修改模板/themes/next/layout/_macro/post.swig,搜索 rel="tag">#
,将 # 换成<i class="fa fa-tag"></i>
8. 设置侧边栏
修改主题配置文件,搜索social:找到如下位置
1 | social: |
格式如下
Cloudmusic: https://music.163.com/#/user/home?id=247843674 || headphones
社交连接名称: 社交连接地址 || 社交连接图标
注意该图标必须是Font Awesome中的图标名称
9. 关闭目录自动序列
1 | toc: |
参考资料
https://xian6ge.cn/posts/5b8c41e7/
https://www.aisun.org/2017/10/hexo-next+dingzhi/
https://blog.csdn.net/nightmare_dimple/article/details/86661502