侧边栏公众号

魔改前须知

  1. 魔改有风险,记得备份
  2. 鉴于每个人的根目录名称都不一样,本帖 博客根目录 一律以[BlogRoot]指代。
  3. 涉及魔改源码的内容,会使用diff代码块标识,复制时请不要忘记删除前面的+、-符号。
  4. 引入 自定义的css与js文件,方法见 Hexo博客添加自定义css和js文件
  5. themes/butterfly 等同于 /node_modules/hexo-theme-butterfly

效果:见主页则边栏
1)在 BlogRoot/node_modules/hexo-theme-butterfly/layout/includes/widget 文件夹下新建card_wx.pug 文件, 填入以下内容

1
2
3
4
5
#card-wechat.card-widget.tzy-right-widget
#flip-wrapper
#flip-content
.face
.back.face

2)在BlogRoot/node_modules/hexo-theme-butterfly/layout/includes/widget/index.pug中引入 card_wx.pug

注意:删除+即可,无需加空格

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
#aside-content.aside-content
//- post
if is_post()
- const tocStyle = page.toc_style_simple
- const tocStyleVal = tocStyle === true || tocStyle === false ? tocStyle : theme.toc.style_simple
if showToc && tocStyleVal
.sticky_layout
include ./card_post_toc.pug
else
!=partial('includes/widget/card_author', {}, {cache: true})
//- 文章页显示,文章页不需要展示的话,就不用加
+ !=partial('includes/widget/card_wx', {}, {cache: true})
!=partial('includes/widget/card_announcement', {}, {cache: true})
!=partial('includes/widget/card_top_self', {}, {cache: true})
.sticky_layout
if showToc
include ./card_post_toc.pug
!=partial('includes/widget/card_recent_post', {}, {cache: true})
!=partial('includes/widget/card_ad', {}, {cache: true})
else
//- page
!=partial('includes/widget/card_author', {}, {cache: true})
//- 主页显示
+ !=partial('includes/widget/card_wx', {}, {cache: true})
!=partial('includes/widget/card_announcement', {}, {cache: true})
!=partial('includes/widget/card_weibo', {}, {cache: true})
!=partial('includes/widget/card_top_self', {}, {cache: true})

.sticky_layout
if showToc
include ./card_post_toc.pug
!=partial('includes/widget/card_friend_link', {}, {cache: true})
!=partial('includes/widget/card_recent_post', {}, {cache: true})
!=partial('includes/widget/card_ad', {}, {cache: true})
!=partial('includes/widget/card_newest_comment', {}, {cache: true})
!=partial('includes/widget/card_categories', {}, {cache: true})
!=partial('includes/widget/card_tags', {}, {cache: true})
!=partial('includes/widget/card_archives', {}, {cache: true})
!=partial('includes/widget/card_webinfo', {}, {cache: true})
!=partial('includes/widget/card_bottom_self', {}, {cache: true})

3)在 [BlogRoot]\source\css\custom.css 增加如下代码,可以将background: var(--lmx0-theme) !important;改为自己的主题色。

图片自取(下面css),自行ps。

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
/* 公众号 start */
[data-theme='light'] #aside-content .card-widget#card-wechat {
background: var(--lmx0-theme) !important;
}

#aside-content .card-widget#card-wechat {
background: var(--card-bg);
display: flex;
justify-content: center;
align-content: center;
padding: 0;
cursor: pointer !important;
border: none;
height: 110px;
}

/* 如果你设置了aside 的 mobile 为 false,记得放开下面这段注释;
如果你设置了aside 的 mobile 为 true ,不需要改动。 */

/* @media screen and (max-width: 768px) {
#aside-content .card-widget#card-wechat {
display: none !important;
}
} */

@media screen and (min-width: 1300px) {
#aside-content .card-widget {
margin-top: 1rem;
}
}

#flip-wrapper {
-webkit-perspective: 1000;
perspective: 1000;
position: relative;
width: 235px;
height: 110px;
z-index: 1;
}

#flip-wrapper:hover #flip-content {
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
}

#flip-content {
width: 100%;
height: 100%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
transition: cubic-bezier(0, 0, 0, 1.29) 0.3s;
}

.face {
position: absolute;
width: 100%;
height: 100%;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
background: url(https://img.zhheo.com/i/2022/08/31/630efc6e3e794.png) center center no-repeat;
background-size: 100%;
}

.back.face {
display: block;
-webkit-transform: rotateY(180deg);
transform: rotateY(180deg);
box-sizing: border-box;
background: url(https://s1.vika.cn/space/2023/01/18/094535637deb43548746e730e520c021) center center no-repeat;
background-size: 100%;
}
/* 公众号 end */