前言
本文是基于大佬们的轮子进行魔改的,如果发现魔改中出现了报错,并且无法修复的话,请回滚一下主题,everfu/hexo-theme-solitude 由于solitude和butterfly的代码有点相似(不保证完全相似)所以这里把一些大佬魔改butterfly代码的一小部分搬过来了()
侧边栏时钟(白夜大佬) 1.添加js和css 创建solitude/source/js/custom/digit-clock.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 var _time10 = Array .from (Array (10 )).map ((n, i ) => i);var _time6 = _time10.slice (0 , 6 );var _time3 = _time10.slice (0 , 3 );var _Structure = [ [_time3, _time10], [_time6, _time10], [_time6, _time10] ]; var clock = document .createElement ('div' );clock.id = 'clock' ; document .getElementById ("card-digit-clock" ).appendChild (clock);var digitGroups = [];requestAnimationFrame (update);_Structure.forEach (digits => { var digitGroup = document .createElement ('div' ); digitGroup.classList .add ('digit-group' ); clock.appendChild (digitGroup); digitGroups.push (digitGroup); digits.forEach (digitList => { var digit = document .createElement ('div' ); digit.classList .add ('digit' ); digitList.forEach (n => { var ele = document .createElement ('div' ); ele.classList .add ('digit-number' ); ele.innerText = n; digit.appendChild (ele); }); digitGroup.appendChild (digit); }); }); function update ( ) { requestAnimationFrame (update); var date = new Date (); var time = [date.getHours (), date.getMinutes (), date.getSeconds ()]. map (n => `0${n} ` .slice (-2 ).split ('' ).map (e => +e)). reduce ((p, n ) => p.concat (n), []); time.forEach ((n, i ) => { var digit = digitGroups[Math .floor (i * 0.5 )].children [i % 2 ].children ; Array .from (digit).forEach ((e, i2 ) => e.classList [i2 === n ? 'add' : 'remove' ]('bright' )); }); }
然后创建solitude/source/css/custom/digit-clock.css
文件,在里面添加以下内容:
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 #card-digit-clock { display : flex; justify-content : center; align-items : center; } #clock { font-size : 10px ; position : relative; } .digit-group { display : inline-block; } .digit-group :not (:last-child ):after { color : inherit; content : ":" ; font-size : 50px ; } .digit { display : inline-block; width : 33px ; } .digit .digit-number { color : inherit; transform : rotate (-90deg ); transition : font-size 200ms ,transform 350ms ,color 150ms ; } .digit .digit-number .bright { color : inherit; font-size : 25px ; transform : rotate (0deg ); }
2.添加aside.yml 在[BlogRoot]/source/_data
目录下新建一个aside.yml
文件,内容如下:
1 2 3 4 5 6 7 8 - name: digit-clock title: class: card-digit-clock id: card-digit-clock icon: content_class: content_id: content_html: "<script defer async pjax src='/js/custom/digit-clock.js'></script>"
3.在主题配置文件添加组件 在150行左右,添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 aside: home: noSticky: "about,digit-clock" Sticky: "allInfo" post: noSticky: "about,digit-clock" Sticky: "newestPost" page: noSticky: "about,digit-clock" Sticky: "newestPost,allInfo"
4.引入css 修改themes\solitude\source\css\index.styl
文件,在任意一行添加:
最后使用hexo cl
和hexo s
来预览效果
自定义鼠标样式(猕猴桃佬+站长微改) 1.添加js和css 在[BlogRoot]theme\solitude\source\js
新建cursor.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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 var CURSOR ;Math .lerp = (a, b, n ) => (1 - n) * a + n * b;const getStyle = (el, attr ) => { try { return window .getComputedStyle ? window .getComputedStyle (el)[attr] : el.currentStyle [attr]; } catch (e) {} return "" ; }; class Cursor { constructor ( ) { this .pos = {curr : null , prev : null }; this .pt = []; this .create (); this .init (); this .render (); } move (left, top ) { this .cursor .style ["left" ] = `${left} px` ; this .cursor .style ["top" ] = `${top} px` ; } create ( ) { if (!this .cursor ) { this .cursor = document .createElement ("div" ); this .cursor .id = "cursor" ; this .cursor .classList .add ("hidden" ); document .body .append (this .cursor ); } var el = document .getElementsByTagName ('*' ); for (let i = 0 ; i < el.length ; i++) if (getStyle (el[i], "cursor" ) == "pointer" ) this .pt .push (el[i].outerHTML ); document .body .appendChild ((this .scr = document .createElement ("style" ))); this .scr .innerHTML = `* {cursor: url("data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' width='8px' height='8px'><circle cx='4' cy='4' r='4' opacity='.5'/></svg>") 4 4, auto}` ; } refresh ( ) { this .scr .remove (); this .cursor .classList .remove ("hover" ); this .cursor .classList .remove ("active" ); this .pos = {curr : null , prev : null }; this .pt = []; this .create (); this .init (); this .render (); } init ( ) { document .onmouseover = e => this .pt .includes (e.target .outerHTML ) && this .cursor .classList .add ("hover" ); document .onmouseout = e => this .pt .includes (e.target .outerHTML ) && this .cursor .classList .remove ("hover" ); document .onmousemove = e => {(this .pos .curr == null ) && this .move (e.clientX - 8 , e.clientY - 8 ); this .pos .curr = {x : e.clientX - 8 , y : e.clientY - 8 }; this .cursor .classList .remove ("hidden" );}; document .onmouseenter = e => this .cursor .classList .remove ("hidden" ); document .onmouseleave = e => this .cursor .classList .add ("hidden" ); document .onmousedown = e => this .cursor .classList .add ("active" ); document .onmouseup = e => this .cursor .classList .remove ("active" ); } render ( ) { if (this .pos .prev ) { this .pos .prev .x = Math .lerp (this .pos .prev .x , this .pos .curr .x , 0.15 ); this .pos .prev .y = Math .lerp (this .pos .prev .y , this .pos .curr .y , 0.15 ); this .move (this .pos .prev .x , this .pos .prev .y ); } else { this .pos .prev = this .pos .curr ; } requestAnimationFrame (() => this .render ()); } } (() => { CURSOR = new Cursor (); })();
然后在/source/css
新建cursor.css
,添加以下代码:
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 #cursor { position : fixed; width : 16px ; height : 16px ; background : rgb (32 , 159 , 181 ) !important ; border-radius : 8px ; opacity : 0.25 ; z-index : 10086 ; pointer-events : none; transition : 0.2s ease-in-out; transition-property : background, opacity, transform; } #cursor .hidden { opacity : 0 ; } #cursor .hover { opacity : 0.1 ; transform : scale (2.5 ); -webkit-transform : scale (2.5 ); -moz-transform : scale (2.5 ); -ms-transform : scale (2.5 ); -o-transform : scale (2.5 ); } #cursor .active { opacity : 0.5 ; transform : scale (0.5 ); -webkit-transform : scale (0.5 ); -moz-transform : scale (0.5 ); -ms-transform : scale (0.5 ); -o-transform : scale (0.5 ); }
2.引入css和js 在主题配置文件的Inject
配置项添加以下代码:
1 2 3 4 5 extends: head: - <link rel="stylesheet" href="/css/cursor.css"> body: - <script defer src="/js/cursor.js"></script>
最后使用hexo cl
和hexo s
来预览效果
网站恶搞标题(猕猴桃佬+站长微改) 1.新建js
这段是给旧版本solitude用的,如果你的solitude已有这个功能,请在主题配置文件开启。
在\source\js\
新建title.js
,并且在里面添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 var OriginTitile = document .title ;var titleTime;document .addEventListener ('visibilitychange' , function ( ) { if (document .hidden ) { document .title = '不要走啊(っ °Д °;)っ' ; clearTimeout (titleTime); } else { document .title = '欢迎回来ヾ(≧▽≦*)o' ; titleTime = setTimeout (function ( ) { document .title = OriginTitile ; }, 2000 ); } });
2.插入js 在Inject
的body
配置项添加以下代码:
1 - <script async src="/js/title.js"></script>
自定义留言板(akilar大佬) 安装插件 在博客根目录打开Git Bash
,然后安装以下插件:
1 npm install hexo-butterfly-envelope --save
添加配置项 在config.yml
添加以下配置项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 envelope_comment: enable: true custom_pic: cover: https://npm.elemecdn.com/hexo-butterfly-envelope/lib/violet.jpg line: https://npm.elemecdn.com/hexo-butterfly-envelope/lib/line.png beforeimg: https://npm.elemecdn.com/hexo-butterfly-envelope/lib/before.png afterimg: https://npm.elemecdn.com/hexo-butterfly-envelope/lib/after.png message: - 有什么想问的? - 有什么想说的? - 有什么想吐槽的? - 哪怕是有什么想吃的,都可以告诉我哦~ bottom: 自动书记人偶竭诚为您服务! height: path: front_matter: title: 留言板 comments: true
最后