本文主要是将本站在PaperMod主题使用中的一些shortcodes记录下.
还有另外一篇
根据本站主题进行的一些顶修改。
本站源代码已开源,请访问github。
文章实现图片轮播# 来自小球飞鱼
随便放几张图看下效果
加入的功能分别有:图片无限循环、鼠标滚轮 / 键盘方向键切换、懒加载和自动调节高度。
步骤1:创建短代码模板
在layou/shortcodes
文件夹中创建imgloop.html
短代码模板,内容如下,相关功能加入参考 Swiper3.x
文档。
html
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
{{ if .Site.Params.enableimgloop }}
< link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/css/swiper.min.css" >
<!-- Swiper -->
< div class = "swiper-container" >
< div class = "swiper-wrapper" >
{{$itItems := split (.Get 0) ","}}
{{range $itItems }}
< div class = "swiper-slide" >
< img src = "{{.}}" alt = "" >
</ div >
{{end}}
</ div >
<!-- Add Pagination -->
< div class = "swiper-pagination" ></ div >
</ div >
< script src = "https://cdnjs.cloudflare.com/ajax/libs/Swiper/3.4.2/js/swiper.min.js" ></ script >
<!-- Initialize Swiper -->
< script >
var swiper = new Swiper ( '.swiper-container' , {
pagination : '.swiper-pagination' ,
paginationClickable : true ,
//自动调节高度
autoHeight : true ,
//键盘左右方向键控制
keyboardControl : true ,
//鼠标滑轮控制
mousewheelControl : true ,
//自动切换
//autoplay : 5000,
//懒加载
lazyLoading : true ,
lazyLoadingInPrevNext : true ,
//无限循环
loop : true ,
});
</ script >
{{ end }}
步骤2:加入css
在assets/scss/cutom.css
中加入如下代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
. swiper-container {
max-width : 820 px ;
margin : 2 em auto ;
}
. swiper-slide {
text-align : center ;
font-size : 18 px ;
background-color : #fff ;
/* Center slide text vertically */
display : flex ;
justify-content : center ;
align-items : center ;
img {
margin : 0 !important ;
}
}
限制了最大宽度(820 是试出来的值),原因是如果按照文章原本的写法,会出现一个很奇妙的情况:刚载入时一切正常,刷新后图片突然放大,溢出显示区域,但只要稍微拉一下浏览器窗口大小就又恢复正常。
研究半晌实在百思不得其解,不像是 CSS 失效,滑动正常肯定不是 JS 失效,稍微挤压一下中间文章区域就正常了到底是个什么毛病…… 还好搞不清楚是什么情况不要紧,限制一下最大宽度就能解决这件事,傻人有傻福。
最后在配置文件config.yaml
中的params
下加入enableimgloop: true
Twikoo评论回复邮件模板# 来自张洪Heo
废话不多说直接上代码:
html
1
< div class = "page flex-col" >< div class = "box_3 flex-col" style = " display: flex; position: relative; width: 100%; height: 206px; background: #ef859d2e; top: 0; left: 0; justify-content: center;" >< div class = "section_1 flex-col" style = " background-image: url("这里更改为你的网站图标"); position: absolute; width: 152px; height: 152px; display: flex; top: 130px; background-size: cover;" ></ div ></ div >< div class = "box_4 flex-col" style = " margin-top: 92px; display: flex; flex-direction: column; align-items: center;" >< div class = "text-group_5 flex-col justify-between" style = " display: flex; flex-direction: column; align-items: center; margin: 0 20px;" >< span class = "text_1" style = " font-size: 26px; font-family: PingFang-SC-Bold, PingFang-SC; font-weight: bold; color: #000000; line-height: 37px; text-align: center;" > 嘿!你在 ${SITE_NAME} 博客中收到一条新回复。</ span >< span class = "text_2" style = " font-size: 16px; font-family: PingFang-SC-Bold, PingFang-SC; font-weight: bold; color: #00000030; line-height: 22px; margin-top: 21px; text-align: center;" > 你之前的评论 在 ${SITE_NAME} 博客中收到来自 ${NICK} 的回复</ span ></ div >< div class = "box_2 flex-row" style = " margin: 0 20px; min-height: 128px; background: #F7F7F7; border-radius: 12px; margin-top: 34px; display: flex; flex-direction: column; align-items: flex-start; padding: 32px 16px; width: calc(100% - 40px);" >< div class = "text-wrapper_4 flex-col justify-between" style = " display: flex; flex-direction: column; margin-left: 30px; margin-bottom: 16px;" >< span class = "text_3" style = " height: 22px; font-size: 16px; font-family: PingFang-SC-Bold, PingFang-SC; font-weight: bold; color: #C5343E; line-height: 22px;" > ${PARENT_NICK}</ span >< span class = "text_4" style = " margin-top: 6px; margin-right: 22px; font-size: 16px; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #000000; line-height: 22px;" > ${PARENT_COMMENT}</ span ></ div >< hr style = " display: flex; position: relative; border: 1px dashed #ef859d2e; box-sizing: content-box; height: 0px; overflow: visible; width: 100%;" >< div class = "text-wrapper_4 flex-col justify-between" style = " display: flex; flex-direction: column; margin-left: 30px;" >< hr >< span class = "text_3" style = " height: 22px; font-size: 16px; font-family: PingFang-SC-Bold, PingFang-SC; font-weight: bold; color: #C5343E; line-height: 22px;" > ${NICK}</ span >< span class = "text_4" style = " margin-top: 6px; margin-right: 22px; font-size: 16px; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #000000; line-height: 22px;" > ${COMMENT}</ span ></ div >< a class = "text-wrapper_2 flex-col" style = " min-width: 106px; height: 38px; background: #ef859d38; border-radius: 32px; display: flex; align-items: center; justify-content: center; text-decoration: none; margin: auto; margin-top: 32px;" href = "${POST_URL}" >< span class = "text_5" style = " color: #DB214B;" > 查看详情</ span ></ a ></ div >< div class = "text-group_6 flex-col justify-between" style = " display: flex; flex-direction: column; align-items: center; margin-top: 34px;" >< span class = "text_6" style = " height: 17px; font-size: 12px; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #00000045; line-height: 17px;" > 此邮件由评论服务自动发出,直接回复无效。</ span >< a class = "text_7" style = " height: 17px; font-size: 12px; font-family: PingFangSC-Regular, PingFang SC; font-weight: 400; color: #DB214B; line-height: 17px; margin-top: 6px; text-decoration: none;" href = "${SITE_URL}" > 前往博客</ a ></ div ></ div ></ div >
将 这里更改为你的网站图标
更改为网站图标图片的url地址。
安装方法:
进入twikoo管理后台选择邮件通知将代码黏贴到 MAIL_TEMPLATE
中
Twikoo邮件自定义字段:
Twikoo文档不提供邮件模板的参数含义,这里附上,方便魔改。@Leonus
和 @小香猪 提供。
参数 含义 参数 含义 ${SITE_URL} 网站链接 ${POST_URL} 文章链接 ${SITE_NAME} 网站名字 ${IMG} 回复人头像 ${PARENT_NICK} 被回复人昵称 ${PARENT_IMG} 被回复人头像 ${PARENT_COMMENT} 被回复人的评论内容 ${MAIL} 回复人邮件 ${NICK} 回复人昵称 ${IP} 回复人 IP 地址
html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
< div class = "page flex-col" >
< div class = "box_3 flex-col" style = "
display: flex;
position: relative;
width: 100%;
height: 206px;
background: #ef859d2e;
top: 0;
left: 0;
justify-content: center;
" >< div class = "section_1 flex-col" style = "
background-image: url("这里更改为你的网站图标");
position: absolute;
width: 152px;
height: 152px;
display: flex;
top: 130px;
background-size: cover;
" ></ div ></ div >
< div class = "box_4 flex-col" style = "
margin-top: 92px;
display: flex;
flex-direction: column;
align-items: center;
" >
< div class = "text-group_5 flex-col justify-between" style = "
display: flex;
flex-direction: column;
align-items: center;
margin: 0 20px;
" >
< span class = "text_1" style = "
font-size: 26px;
font-family: PingFang-SC-Bold, PingFang-SC;
font-weight: bold;
color: #000000;
line-height: 37px;
text-align: center;
" > 嘿!你在 ${SITE_NAME} 博客中收到一条新回复。</ span >
< span class = "text_2" style = "
font-size: 16px;
font-family: PingFang-SC-Bold, PingFang-SC;
font-weight: bold;
color: #00000030;
line-height: 22px;
margin-top: 21px;
text-align: center;
" > 你之前的评论 在 ${SITE_NAME} 博客中收到来自 ${NICK} 的回复</ span >
</ div >
< div class = "box_2 flex-row" style = "
margin: 0 20px;
min-height: 128px;
background: #F7F7F7;
border-radius: 12px;
margin-top: 34px;
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 32px 16px;
width: calc(100% - 40px);
" >
< div class = "text-wrapper_4 flex-col justify-between" style = "
display: flex;
flex-direction: column;
margin-left: 30px;
margin-bottom: 16px;
" >
< span class = "text_3" style = "
height: 22px;
font-size: 16px;
font-family: PingFang-SC-Bold, PingFang-SC;
font-weight: bold;
color: #C5343E;
line-height: 22px;
" > ${PARENT_NICK}</ span >
< span class = "text_4" style = "
margin-top: 6px;
margin-right: 22px;
font-size: 16px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #000000;
line-height: 22px;
" > ${PARENT_COMMENT}</ span >
</ div >< hr style = "
display: flex;
position: relative;
border: 1px dashed #ef859d2e;
box-sizing: content-box;
height: 0px;
overflow: visible;
width: 100%;
" >< div class = "text-wrapper_4 flex-col justify-between" style = "
display: flex;
flex-direction: column;
margin-left: 30px;
" >
< hr >
< span class = "text_3" style = "
height: 22px;
font-size: 16px;
font-family: PingFang-SC-Bold, PingFang-SC;
font-weight: bold;
color: #C5343E;
line-height: 22px;
" > ${NICK}</ span >
< span class = "text_4" style = "
margin-top: 6px;
margin-right: 22px;
font-size: 16px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #000000;
line-height: 22px;
" > ${COMMENT}</ span >
</ div >
< a class = "text-wrapper_2 flex-col" style = "
min-width: 106px;
height: 38px;
background: #ef859d38;
border-radius: 32px;
display: flex;
align-items: center;
justify-content: center;
text-decoration: none;
margin: auto;
margin-top: 32px;
" href = "${POST_URL}" >
< span class = "text_5" style = "
color: #DB214B;
" > 查看详情</ span >
</ a >
</ div >
< div class = "text-group_6 flex-col justify-between" style = "
display: flex;
flex-direction: column;
align-items: center;
margin-top: 34px;
" >
< span class = "text_6" style = "
height: 17px;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #00000045;
line-height: 17px;
" > 此邮件由评论服务自动发出,直接回复无效。</ span >
< a class = "text_7" style = "
height: 17px;
font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #DB214B;
line-height: 17px;
margin-top: 6px;
text-decoration: none;
" href = "${SITE_URL}" > 前往博客</ a >
</ div >
</ div >
</ div >
插入音乐测试 (已失效)# 先看演示
基于 MetingJS
制作.
安装方法:
将以下代码放入 ./layouts/shortcodes/music.html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
{{ if .IsNamedParams }}
<!-- require APlayer -->
< link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" >
< script src = "https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js" ></ script >
<!-- require MetingJS -->
< script src = "https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js" ></ script >
< meting-js
id = "{{ .Get " id " }}"
server = "{{ .Get " server " }}"
type = "{{ .Get " type " }}"
fixed = "{{ if .Get " fixed " }}{{ . Get " fixed " }}{{ else }} false {{ end }}"
mini = "{{ if .Get " mini " }}{{ . Get " mini " }}{{ else }} false {{ end }}"
autoplay = "{{ if .Get " autoplay " }}{{ . Get " autoplay " }}{{ else }} false {{ end }}"
loop = "{{ if .Get " loop " }}{{ . Get " loop " }}{{ else }} none {{ end }}"
theme = "{{ if .Get " autoplay " }}{{ . Get " autoplay " }}{{ else }}# 255579 {{ end }}"
volume = "{{ if .Get " volume " }}{{ . Get " volume " }}{{ else }} 0 . 6 {{ end }}"
prelosd = "{{ if .Get " prelosd " }}{{ . Get " prelosd " }}{{ else }} auto {{ end }}"
mutex = "{{ if .Get " mutex " }}{{ . Get " mutex " }}{{ else }} true {{ end }}"
list-folded = "{{ if .Get " list-folded " }}{{ . Get " list-folded " }}{{ else }} true {{ end }}" >
</ meting-js >
{{ end }}
参数表格
option default description id require song id / playlist id / album id / search keyword server require music platform: netease, tencent, kugou, xiami, baidu type require song, playlist, album, search, artist
使用示例
{< music id="569200212" type="song" server="netease" >}}
,具体使用还需要再前面再加一个 {
文章中引入豆瓣读书和豆瓣电影(失效中)# 来自木木木木木
或者su lv’sblog
先看效果
{/{< douban “https://movie.douban.com/subject/35267208/"
>}/}
{/{< douban “https://book.douban.com/subject/35496106/"
>}/}
安装方法
定位到 layouts/shortcodes目录
,新建一个文件叫 douban.html
,放入如下代码:
html
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE HTML>
< html lang = "en" >
< head >
< title ></ title >
< style >
. post-preview {
max-width : 780 px ;
height : 200 px ;
margin : 1 em auto ;
position : relative ;
display : flex ;
/*background: #eee;*/
background : var ( -- entry );
border-radius : 15 px ;
box-shadow : 0 2 px 4 px rgba ( 0 , 0 , 0 , .25 ), 0 0 2 px rgba ( 0 , 0 , 0 , .25 );
}
. dark . post-preview {
/*background: #383838;*/
background : var ( -- entry );
box-shadow : 0 2 px 4 px rgba ( 0 , 0 , 0 , .5 ), 0 0 2 px rgba ( 0 , 0 , 0 , .5 );
}
. post-preview--meta {
width : 80 % ;
padding : 23 px ;
overflow : hidden ;
}
. post-preview--middle {
line-height : 28 px ;
}
. post-preview--title {
font-size : 22 px ;
margin : 0 !important ;
}
. post-preview--title a {
text-decoration : none ;
}
. post-preview--date {
font-size : 14 px ;
color : #999 ;
}
. post-preview--excerpt {
font-size : 14 px ;
line-height : 1.825 ;
}
. post-preview--excerpt p {
display : inline ;
margin : 0 ;
}
. post-preview--image {
height : 200 px !important ;
width : 25 % ;
float : right ;
border-radius : 0 15 px 15 px 0 ;
}
. post-preview img {
margin : unset ;
width : 20 % ;
border-radius : 0 15 px 15 px 0 ;
}
@ media ( max-width : 550px ) {
. post-preview {
width : 95 % ;
}
. post-preview--excerpt {
display : none ;
}
. post-preview--middle {
line-height : 19 px ;
}
}
. rating {
display : block ;
line-height : 15 px ;
}
. rating-star {
display : inline-block ;
width : 75 px ;
height : 15 px ;
background-repeat : no-repeat ;
background-image : url ( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEsAAAClCAYAAAAUAAAYAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA5xJREFUeNrs3T9rFEEcxvG7qEQIglaCICKkin9AUEtBKxU7wS61VlYivgWj70TtNFj5BqzE7qxEWwsxKIoYn4UtluFmbm8nczvzm+/BjxyuDwNzu3uXD0+46f7LC5PA45Hm+WTYw1x2LRDc0jzTXB+wqMlsaLPutz8fDFjYZHYauAz3NBvt83XNnyUWNpn1nVm3OsHmsb3EomazzZnVXKMPNcc0xzUnNKc0Rzv/77fms+Z7O3vt9b1eU7bZrNN68l5zcolX4ofmsuZXTdnmMvyi2dR86Bmcac62P6vKrnVubpc0bxYE32nOab45N8YqsvPeDfcD4SOav4HjprPuu+H5BTt9LXDMfNbdLPfT678Fx6vKupt1o/O8+R3pkOaJ5/iktqx7z/qp+aq5q/nY+fczmheaK03Gs7D5rLtZdzSvA6/Ebc2u55j57HQB0TzW7AzkjiKzny6+2hlKNE8juMNcFqKBaIZndRlCNBBNgmx7ZkE0fbLtZkE0EA1EM17WuQwhGogGooFoss6296y52cNO+J6HLJoPaFdbsvA9zGerIxrPh85eWYgGooFoDiQbuAxp0UA0EVmdWbRo+ma1WbRoIBqIZtzsnHdDWjQQDUQD0WSbde5ZS2UhmtqJJtSEiVkXooFoIJre2VATJmZdiKZ2ogk1YSb8oVMvDeUPnSAaiCaPJkzMuhANRAPRQDQpsqEmTMy6EI11oolpwkA0EA1EcyDZmCYMRAPR+LMxTZjqiCamCQPRQDQQzehNGIgGooFoIJpVZ2OaMBBN7USTqgkD0UA0EE3vbKomDERTO9GkasKYJJpUTRiIBqKBaEZvwkA0EA1EA9GkyKZqwkA01olmrCYMRAPRQDR9LkO+0QmiKbAJUyTRjNWEgWggGohm9CYMRAPRQDQQzZDsWE0YiMYC0eTYhIFoIJrKiCbHJgxEY4FocmzCZEs0OTZhIBqIpjKiybEJA9FANBANROPL5tiEgWhKIJoSmzAQDURjjGhKbMJANCUQTYlNmNGIpsQmDEQD0RgjmhKbMBANRAPR1Es0JTZhIJpciMZaEwaigWgKJBprTRiIJheisdaESUo01powEA1EUyDRWGvCQDQQDURjm2isNWEgmlURzWw2q4pZIBqIJkOiCVyGJpkFolkV0ejMMvel28mIRptl7ku3IRqIpjCimfNuaJpZIBqIBqIpm2ice5Z5ZonJupvVkMRu4JW4qXnrOWY++1+AAQBw9BJSCTeN9wAAAABJRU5ErkJggg== );
overflow : hidden ;
}
. allstar10 {
background-position : 0 px 0 px ;
}
. allstar9 {
background-position : 0 px -15 px ;
}
. allstar8 {
background-position : 0 px -30 px ;
}
. allstar7 {
background-position : 0 px -45 px ;
}
. allstar6 {
background-position : 0 px -60 px ;
}
. allstar5 {
background-position : 0 px -75 px ;
}
. allstar4 {
background-position : 0 px -90 px ;
}
. allstar3 {
background-position : 0 px -105 px ;
}
. allstar2 {
background-position : 0 px -120 px ;
}
. allstar1 {
background-position : 0 px -135 px ;
}
. allstar0 {
background-position : 0 px -150 px ;
}
. rating-average {
color : #777 ;
display : inline-block ;
font-size : 13 px ;
margin-left : 10 px ;
}
</ style >
< script src = "https://code.jquery.com/jquery-1.12.4.min.js"
integrity = "sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin = "anonymous" ></ script >
< script type = "text/javascript" >
$ ( document ). ready ( function () {
$ ( '.douban_item' ). each ( function () {
var _this = $ ( this );
var strs = _this . attr ( 'urlstring' ). toString ();
var db_reg = /^https\:\/\/(movie|book)\.douban\.com\/subject\/([0-9]+)\/?/ ;
if ( db_reg . test ( strs )) {
var db_type = strs . replace ( db_reg , "$1" );
var db_id = strs . replace ( db_reg , "$2" ). toString ();
var db_api = "https://douban.edui.fun/" ;
if ( db_type === 'movie' ) {
var ls_item = 'movie' + db_id ;
var url = db_api + "movies/" + db_id ;
if ( localStorage . getItem ( ls_item ) == null || localStorage . getItem ( ls_item ) === 'undefined' ) {
$ . ajax ({
url : url , type : 'GET' , dataType : "json" , success : function ( data ) {
localStorage . setItem ( ls_item , JSON . stringify ( data ));
movieShow ( _this , ls_item , strs )
}
})
} else {
movieShow ( _this , ls_item , strs )
}
} else if ( db_type === 'book' ) {
var ls_item = 'book' + db_id ;
var url = db_api + "v2/book/id/" + db_id ;
if ( localStorage . getItem ( ls_item ) == null || localStorage . getItem ( ls_item ) === 'undefined' ) {
$ . ajax ({
url : url , type : 'GET' , dataType : 'json' , success : function ( data ) {
localStorage . setItem ( 'book' + db_id , JSON . stringify ( data ));
bookShow ( _this , ls_item , strs )
}
})
} else {
bookShow ( _this , ls_item , strs )
}
}
}
});
});
function movieShow ( _this , ls_item , str ) {
var storage = localStorage . getItem ( ls_item );
var data = JSON . parse ( storage );
var db_star = Math . ceil ( data . rating );
$ ( "<div class='post-preview'><div class='post-preview--meta'><div class='post-preview--middle'><div class='post-preview--title'><a target='_blank' style='box-shadow: none; font-weight: bolder;' href='" + str + "'>" + data . name + "</a></div><div class='rating'><div class='rating-star allstar" + db_star + "'></div><div class='rating-average'>" + data . rating + "</div></div><time class='post-preview--date'>导演:" + data . director + " / 类型:" + data . genre + " / " + data . year + "</time><section style='max-height:75px;overflow:hidden;' class='post-preview--excerpt'>" + data . intro . replace ( /\s*/g , "" ) + "</section></div></div><img referrerpolicy='no-referrer' loading='lazy' class='post-preview--image' src=" + data . img + "></div>" ). replaceAll ( _this )
}
function bookShow ( _this , ls_item , str ) {
var storage = localStorage . getItem ( ls_item );
var data = JSON . parse ( storage );
var db_star = Math . ceil ( data . rating . average );
$ ( "<div class='post-preview'><div class='post-preview--meta'><div class='post-preview--middle'><div class='post-preview--title'><a target='_blank' style='box-shadow: none; font-weight: bolder;' href='" + str + "'>" + data . title + "</a></div><div class='rating'><div class='rating-star allstar" + db_star + "'></div><div class='rating-average'>" + data . rating . average + "</div></div><time class='post-preview--date'>作者:" + data . author + " / 出版:" + data . pubdate + " / " + data . publisher + " </time><section style='max-height:75px;overflow:hidden;' class='post-preview--excerpt'>" + data . summary . replace ( /\s*/g , "" ) + "</section></div></div><img referrerpolicy='no-referrer' loading='lazy' class='post-preview--image' src=" + data . images . medium + "></div>" ). replaceAll ( _this )
}
</ script >
</ head >
< body >
< div class = "douban_show" >
< div id = "db{{ .Get " src " }}" urlstring = "{{ .Get " src " }}" class = "douban_item post-preview" ></ div >
</ div >
</ body >
</ html >
使用方法
{< douban src="直接放网址如:https://book.douban.com/subject/20394150/" >}}
,具体使用还需要再前面再加一个 {
折叠代码# 借鉴自loveit主题
先看示例
页脚添加音乐播放器# 安装 APlayer
我直接在把主题内的 layouts\partials\footer
文件夹全部在根目录下了😂。
在 partials
文件夹内新建 music.html
文件,然后填写:
html
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
<!DOCTYPE html>
< html >
< head >
<!-- require APlayer -->
< link rel = "stylesheet" href = "https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" >
< script src = "https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js" ></ script >
<!-- require MetingJS -->
< script src = "https://cdn.jsdelivr.net/npm/meting@2.0.1/dist/Meting.min.js" ></ script >
</ head >
< body >
< div class = "demo" >
< div id = "player1" >
</ div >
</ div >
< script >
var ap = new APlayer
({
element : document . getElementById ( 'player1' ),
fixed : true ,
autoplay : true ,
mini : true ,
theme : '#f8f4fc' ,
loop : 'all' ,
order : 'random' ,
preload : 'auto' ,
volume : 0.5 ,
mutex : true ,
listFolded : false ,
listMaxHeight : 90 ,
lrcType : 0 ,
music : [{
name : '音乐名' , url : '音乐链接' , artists : '音乐作者' , cover : '封面链接' }]
});
//ap.init();
</ script >
</ body >
之后新建
custom.html
文件,添加
{{ partial "music" . }}
然后保存。
PaperMod
中在 /layouts/baseof.html
中加入上句代码即可
如果想要修改播放器的各项设置可以在文档中查看各项参数的配置。
打开 hugo
本地监听的端口,发现左下角出现播放器!
测试bilibili#
下划线# 谁在用琵琶弹奏一曲东风破 岁月在墙上剥落看见小时候
画廊测试# 这种实现方法简单粗暴,图片大小不一样就会产生下面这种效果,缺乏美感。 2.比较美观,且整齐
Code折叠# 常规的md插入的代码不支持折叠,如果代码太长会很不友好,所以要用简码让代码展开收起 。
在layouts/shortcode/下新建code.html文件 html
1
2
3
4
5
6
7
8
< div class = "highlight-wrapper" >
< div class = "highlight-before" style = "display:none" > {{ .Get 0 }}</ div >
{{ if len .Params | eq 2 }}
{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}
{{ else }}
{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}
{{ end }}
</ div >
在head中引入javascript javascript
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
< script >>
var height = "300px" ;
if (
document . readyState === "complete" ||
( document . readyState !== "loading" && ! document . documentElement . doScroll )
) {
makeCollapsible ();
} else {
document . addEventListener ( "DOMContentLoaded" , makeCollapsible );
}
function toggle ( e ) {
e . preventDefault ();
var link = e . target ;
var div = link . parentElement . parentElement ;
if ( link . innerHTML == " 展开 " ) {
link . innerHTML = " 收起 " ;
div . style . maxHeight = "" ;
div . style . overflow = "none" ;
}
else {
link . innerHTML = " 展开 " ;
div . style . maxHeight = height ;
div . style . overflow = "hidden" ;
div . scrollIntoView ({ behavior : 'smooth' });
}
}
function makeCollapsible () {
var divs = document . querySelectorAll ( '.highlight-wrapper' );
for ( i = 0 ; i < divs . length ; i ++ ) {
var div = divs [ i ];
if ( div . offsetHeight > parseInt ( height , 10 )) {
div . style . maxHeight = height ;
div . style . overflow = "hidden" ;
var e = document . createElement ( 'div' );
e . className = "highlight-link" ;
var html = '<a href=""> 展开 </a>' ;
e . innerHTML = html ;
div . appendChild ( e );
}
}
var links = document . querySelectorAll ( '.highlight-link' );
for ( i = 0 ; i < links . length ; i ++ ) {
var link = links [ i ];
link . addEventListener ( 'click' , toggle );
}
}
//事件处理
window . onload = function () {
var divs = document . querySelectorAll ( '.highlight-wrapper' );
var eleItems = []. slice . call ( divs );
eleItems . forEach ( function ( item , idx ) {
item . addEventListener ( 'mouseover' , function () {
var tag = item . querySelectorAll ( '.highlight-before' )[ 0 ];
tag . style . display = "block" ;
});
item . addEventListener ( 'mouseout' , function () {
var tag = item . querySelectorAll ( '.highlight-before' )[ 0 ];
tag . style . display = "none" ;
});
});
}
< /script>>
引入css样式 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
. highlight-wrapper {
position : relative ;
}
. highlight-before {
position : absolute ;
top : 10 px ;
left : 0 ;
z-index : 2 ;
color : white ;
background-color : #333333 ;
opacity : .8 ;
padding : 2.5 px 10 px ;
border-radius : 5 px ;
-webkit- user-select : none ;
-moz- user-select : none ;
-o- user-select : none ;
user-select : none ;
}
. highlight-link {
position : absolute ;
bottom : 0 ;
right : 0 ;
}
. highlight-link a {
box-shadow : 0 0 px ;
font-size : 14 px ;
color : #eea2a4 ;
}
多标签页# 创建shortcode模板 ./layouts/shortcodes/tabs.html 1
2
3
4
< div class = "x-tabs" >
< div class = "x-tabs-nav" ></ div >
< div class = "x-tabs-content" > {{ .Inner }}</ div >
</ div >
./layouts/shortcodes/tab.html 1
2
3
< div class = "x-tab" title = "{{ .Get 0 }}" >
{{ .Inner }}
</ div >
添加样式./assets/css/extended/custom.css
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
36
37
38
39
. x-tabs {
margin : 8 px 0 ;
display : block ;
border : 1 px solid var ( -- tertiary );
border-radius : 2 px ;
}
. x-tabs-nav {
position : relative ;
display : flex ;
flex : none ;
background-color : var ( -- theme );
border-bottom : 1 px solid var ( -- tertiary );
}
. x-tabs-nav-item . active {
border-bottom : 1 px solid #1890ff ;
}
. x-tabs-nav-item > span {
display : block ;
color : var ( -- primary );
font-size : 16 px ;
padding : 4 px 16 px ;
}
. x-tabs-nav-item . active > span ,
. x-tabs-nav-item > span : hover {
color : #1890ff !important ;
}
. x-tab {
display : none ;
padding : 8 px 16 px ;
}
. x-tab . active {
display : block ;
}
添加脚本 html
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
< script >
const removeClass = ( parent , el , className ) => {
parent . querySelectorAll ( el ). forEach ( $el => {
$el . classList . remove ( className );
});
};
document . querySelectorAll ( '.x-tabs' ). forEach ( tabs => {
const $tabsNav = tabs . querySelector ( '.x-tabs-nav' );
const $tabsContent = tabs . querySelector ( '.x-tabs-content' );
tabs . querySelectorAll ( '.x-tab' ). forEach ( tab => {
const title = tab . getAttribute ( 'title' ) || 'tab' ;
const nav = document . createElement ( 'div' );
nav . classList . add ( 'x-tabs-nav-item' )
nav . innerHTML = '<span>' + title + '</span>' ;
$tabsNav . append ( nav );
});
tabs . querySelectorAll ( '.x-tabs-nav-item' ). forEach ( $navItem => {
$navItem . addEventListener ( 'click' , e => {
e . preventDefault ();
removeClass ( tabs , '.x-tabs-nav-item' , 'active' );
removeClass ( tabs , '.x-tab' , 'active' );
$navItem . classList . add ( 'active' );
const index = Array . from ( $navItem . parentNode . children ). indexOf ( $navItem );
$tabsContent . children . item ( index ). classList . add ( 'active' );
});
});
const $firstNav = $tabsNav . querySelector ( '.x-tabs-nav-item:first-child' );
if ( $firstNav ) {
$firstNav . click ();
}
});
</ script >
使用方法 1
2
3
4
5
6
7
8
{{ % tabs %}}
{{ % tab "Java" %}}
第一个 tab,注意 {{ 和 % 之间有个空格,使用的时候记得去掉
{{ % /tab %}}
{{ % tab "JavaScript" %}}
第二个 tab
{{ % /tab %}}
{{ % /tabs %}}
强化学习reinforcement learning 有近几十年的研究历史,是 人工智能artificial intelligence 的一个研究方向
这是一个数字脚注 .
这是一个带标签的脚注