给大家分享下博客主页顶部推荐文章如何实现,主要参考自heo
具体效果如下

创建hometop.pug
在themes/butterfly/layout/includes
下创建hometop.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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| if is_home() #home_top .recent-top-post-group#recent-top-post-group .recent-post-top#recent-post-top #bannerGroup #banners .banners-title .banners-title-big 无限活力 .banners-title-big 与热爱生活 .banners-title-small BYWIND.XYZ .tags-group-all .tags-group-wrapper each i in site.data.creativity - const evenNum = i.creativity_list.filter((x, index) => index % 2 === 0); - const oddNum = i.creativity_list.filter((x, index) => index % 2 === 1); each item, index in i.creativity_list if ((index + 1 <= evenNum.length) && (index + 1 <= oddNum.length)) .tags-group-icon-pair .tags-group-icon(style=`background: ${evenNum[index].color}`) img(src=evenNum[index].icon, onerror='this.onerror=null,this.src="/img/friend_404.gif"', title=evenNum[index].name, alt=evenNum[index].name) .tags-group-icon(style=`background: ${oddNum[index].color}`) img(src=oddNum[index].icon, onerror='this.onerror=null,this.src="/img/friend_404.gif"', title=oddNum[index].name, alt=oddNum[index].name) each i in site.data.creativity - const evenNum = i.creativity_list.filter((x, index) => index % 2 === 0); - const oddNum = i.creativity_list.filter((x, index) => index % 2 === 1); each item, index in i.creativity_list if ((index + 1 <= evenNum.length) && (index + 1 <= oddNum.length)) .tags-group-icon-pair .tags-group-icon(style=`background: ${evenNum[index].color}`) img(src=evenNum[index].icon, onerror='this.onerror=null,this.src="/img/friend_404.gif"', title=evenNum[index].name, alt=evenNum[index].name) .tags-group-icon(style=`background: ${oddNum[index].color}`) img(src=oddNum[index].icon, onerror='this.onerror=null,this.src="/img/friend_404.gif"', title=oddNum[index].name, alt=oddNum[index].name) a#banner-hover(onclick='toRandomPost()') span.bannerText 随便逛逛 i.fas.fa-arrow-right.banner-righticon .categoryGroup .categoryItem(style='box-shadow:var(--bywind-shadow-blue)') a.categoryButton.CB1.bikan(href='/categories/学习笔记/') span.categoryButtonText 必看精选 i.fas.fa-dove .categoryItem(style='box-shadow:var(--bywind-shadow-red)') a.categoryButton.remen(href='/categories/Hexo魔改/') span.categoryButtonText 热门文章 i.fas.fa-burn .categoryItem(style='box-shadow:var(--bywind-shadow-green)') a.categoryButton.shiyong(href='/categories/后端/') span.categoryButtonText 实用教程 i.fas.fa-book .topGroup if site.data.slider each i in site.data.slider .recent-post-item .post_cover.left_radius a(href=url_for(i.link), title=i.title) span.recent-post-top-text(onclick=`pjax.loadUrl("`+i.link+`")`) 荐 img.post_bg.entered.loaded(src=url_for(i.cover) onerror="this.onerror=null,this.src='/img/404.png'") .recent-post-info(onclick=`pjax.loadUrl("`+i.link+`")`) a.article-title(href=url_for(i.link), title=i.title)= i.title
|
引入页面
创建完成后在layout/includes/layout.pug
中添加include ./hometop.pug
1 2 3 4
| if page.type !== '404' #body-wrap(class=pageType) include ./header/index.pug + include ./hometop.pug
|
创建creativity.yml
在source/_data
下创建creativity.yml
文件
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
| - class_name: 开启创造力 creativity_list: - name: Vue color: "#b8f0ae" icon: https://cdn.bywind.xyz/img/banners/vue.webp - name: Java color: "#fff" icon: https://cdn.bywind.xyz/img/banners/Java.webp - name: Docker color: "#57b6e6" icon: https://cdn.bywind.xyz/img/banners/docker.webp - name: Webpack color: "#2e3a41" icon: https://cdn.bywind.xyz/img/banners/webpack.webp - name: Photoshop color: "#4082c3" icon: https://cdn.bywind.xyz/img/banners/PS.webp - name: Swift color: "#eb6840" icon: https://cdn.bywind.xyz/img/banners/swift.webp - name: Python color: "#fff" icon: https://cdn.bywind.xyz/img/banners/python.webp - name: Node color: "#333" icon: https://cdn.bywind.xyz/img/banners/node-logo.svg - name: Git color: "#df5b40" icon: https://cdn.bywind.xyz/img/banners/git.webp - name: Css color: "#2c51db" icon: https://cdn.bywind.xyz/img/banners/css.webp - name: Js color: "#f7cb4f" icon: https://cdn.bywind.xyz/img/banners/js.webp
|
创建slider.yml
在source/_data
下创建slider.yml
文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| - cover: https://cloud-image-host.oss-cn-beijing.aliyuncs.com/background/45663c9f2ce54eb2ae8628efb0c43390.jpg link: /posts/e255a10a.html title: 大学课程 - 计算机网络
- cover: https://cloud-image-host.oss-cn-beijing.aliyuncs.com/background/fe86174cbe99485e85f43b37c16622da.jpg link: /posts/8d4b7ae1.html title: 大学课程 - 计算机组成原理
- cover: https://cloud-image-host.oss-cn-beijing.aliyuncs.com/background/v2-8e40cc0dbad304617ad773d0f256d339_r.jpg link: posts/d04bd5bc.html title: 大学课程 - 操作系统
- cover: https://cloud-image-host.oss-cn-beijing.aliyuncs.com/background/63233ec9893f4.webp link: /posts/f73eaef5.html title: Fiddler抓包 - 功能非常强大的web调试利器
- cover: https://cloud-image-host.oss-cn-beijing.aliyuncs.com/page/cover/2022112902.png link: /posts/5f262806.html title: 博客美化日记 - 囊括本博客Butterfly主题的基本美化升级
- cover: https://cdn.bywind.xyz/img/cover/image-20221208194011653.png link: /posts/e9cd2bbc.html title: 基于Butterfly的外挂标签引入 - 独特的风格让你的博客别具一格
|
添加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 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
| #home_top { max-width: 1400px; margin: auto; margin-top: .5rem; padding: 0 1.5rem; width: 100% }
@media screen and (max-width: 768px) { #home_top { padding:0; margin-top: 0 } }
.recent-top-post-group { border-radius: 12px; overflow: hidden; overflow-x: auto; width: 100%; margin-bottom: 0 }
.recent-post-top { display: flex; flex-direction: row; flex-wrap: nowrap; width: 100%; overflow-x: scroll }
.recent-post-top::-webkit-scrollbar { display: none }
.recent-post-top .recent-post-item { display: flex; width: 200px; flex-direction: column; align-items: flex-start; margin-left: .5rem; background: var(--bywind-card-bg); border-radius: 12px; overflow: hidden; min-width: 200px; height: 164px; max-height: 164px; border: var(--style-border-always); transition: .3s; position: relative; box-shadow: var(--bywind-shadow-border) }
@media screen and (max-width: 768px) { .recent-post-top .recent-post-item { border-radius:8px; box-shadow: none; clip-path: inset(0 0 0 0 round 8px) }
.recent-post-top .recent-post-item:last-child { margin-right: 1rem } }
@media screen and (min-width: 1300px) { .recent-post-top .recent-post-item { margin-right:0; margin-bottom: .5rem }
.recent-post-top .recent-post-item:active { transform: scale(.97) }
.recent-post-top { overflow-x: visible }
.recent-top-post-group { overflow: visible; overflow-x: visible } }
span.recent-post-top-text { position: absolute; top: 0; left: -40px; display: flex; z-index: 1; background: var(--bywind-theme); color: var(--bywind-white); padding: 2px 8px; font-size: .6rem; border-radius: 12px 0 12px 0; transition: .3s; cursor: pointer }
.recent-post-item:hover .recent-post-top-text { left: 0 }
@media screen and (min-width: 1300px) { .recent-post-top .recent-post-item:hover { border:var(--style-border-hover); box-shadow: var(--bywind-shadow-main); transform: scale(1.03) }
.recent-post-top .recent-post-item:active { transform: scale(.97) } }
@media screen and (max-width: 768px) { .recent-top-post-group { border-radius:0; background: var(--bywind-background) }
.recent-post-top-text { display: none!important }
.recent-post-top .recent-post-item .post_cover img { border-radius: 8px 8px 0 0!important } }
.recent-post-top .recent-post-item .post_cover a { height: 100px; overflow: hidden; display: flex }
.recent-post-top .recent-post-item .post_cover img { object-fit: cover; width: 100%; background: var(--bywind-secondbg); border-radius: 12px 12px 0 0 }
.recent-post-top .recent-post-item:hover .post_cover img { transform: scale(1) }
.recent-post-top .recent-post-item .recent-post-info { padding: .3rem .5rem .3rem .5rem!important; transition: .3s }
.recent-post-top .recent-post-item:hover .recent-post-info a { color: var(--bywind-fontcolor) }
@media screen and (max-width: 1300px) { .recent-post-top .recent-post-item:hover .recent-post-info a { color:var(--bywind-theme); transition: .3s } }
.recent-post-top .recent-post-item .recent-post-info .article-title { -webkit-line-clamp: 2; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; line-height: 1.5; justify-content: center; align-items: flex-end; align-content: center; padding-top: .5rem; font-weight: 700; font-size: .8rem!important; padding: 0!important }
.categoryItem { overflow: hidden; transform: scale(1); transition: all 0.8s cubic-bezier(0.65, 0.15, 0.37, 1.19); height: 48%; border-radius: 12px; }
a.categoryButton { height: 100%; width: 100%; background: var(--bywind-card-bg); border-radius: 12px; display: inline-block; text-align: left; line-height: 4em; font-weight: bold; font-size: 0.9rem; color: var(--bywind-white); transition: all 0.8s cubic-bezier(0.39, 0.575, 0.565, 1); transform: scale(1); overflow: hidden; font-family: PingFang SC, Hiragino Sans GB, Microsoft YaHei; }
a.categoryButton i { transform: scale(1.0) rotate(15deg); }
@media screen and (min-width: 1300px) { a.categoryButton:active { transform: scale(0.97); } }
@media screen and (max-width: 768px) { a.categoryButton { border-radius: 8px; }
.categoryItem { border-radius: 0px; height: 47%; box-shadow: none !important; } }
a.categoryButton:after { top: 50px; width: 1rem; left: 21px; height: 2px; background: var(--bywind-white); content: ""; border-radius: 1px; position: absolute; }
.categoryButtonText { padding-left: 21px; }
a.categoryButton i { font-size: 5rem; opacity: 0.2; position: absolute; right: 0%; top: 20%; transition: 0.3s; width: 100px; text-align: center; filter: blur(2px); }
@media screen and (max-width: 768px) { a.categoryButton i { display: none; }
.recent-post-top .categoryGroup { min-width: 130px !important; margin-bottom: 0.5rem; margin-left: 1rem; max-height: 164px; overflow: hidden; position: relative; } }
.topGroup { display: flex; }
#bannerGroup { display: flex; }
div#banners { display: none; }
@media screen and (min-width: 1300px) { .topGroup { display: flex; flex-direction: row; flex-wrap: wrap; justify-content: flex-end; height: calc(328px + 0.5rem); align-content: space-between; width: calc(600px + 1.5rem); position: relative; }
div#bannerGroup { width: calc(100% - 600px - 2rem); margin-right: 0.5rem; height: calc(328px + 0.5rem); display: flex; flex-direction: column; justify-content: space-between; }
div#banners { display: flex; width: 100%; height: 76%; background: var(--bywind-card-bg); margin-bottom: 0.5rem; border: var(--style-border); border-radius: 12px; overflow: hidden; position: relative; box-shadow: var(--bywind-shadow-border); flex-direction: column; overflow: hidden; transition: 0.3s; clip-path: inset(0 0 0 0 round 12px); }
div#banners:hover { box-shadow: var(--bywind-shadow-main); }
#banners.flink { margin-bottom: 0.5rem; }
#banners .banner-button-group { position: absolute; right: 2rem; top: 2rem; display: flex; }
#banners .banner-button { padding: 8px 12px; background: var(--bywind-fontcolor); border-radius: 12px; color: var(--bywind-card-bg); display: flex; align-items: center; z-index: 1; transition: 0.3s; cursor: pointer; box-shadow: var(--bywind-shadow-black); }
#banners .banner-button.secondary { background: var(--bywind-secondbg); border: var(--style-border-always); color: var(--bywind-lighttext); margin-right: 1rem; box-shadow: var(--bywind-shadow-border); }
#banners .banner-button:hover { background: var(--bywind-theme); color: var(--bywind-white); }
#banners .banner-button i { margin-right: 8px; font-size: 1rem; }
.banners-title { top: 2rem; left: 1.5rem; position: absolute; display: flex; flex-direction: column; }
.banners-title-big { font-size: 36px; line-height: 1; font-weight: bold; margin-bottom: 8px; }
.banners-title-small { font-size: 12px; line-height: 1; color: var(--bywind-secondtext); margin-top: 8px; margin-bottom: 0.5rem; }
#banner-hover { position: absolute; width: 100%; height: 100%; top: 0; left: 0; background: var(--bywind-theme); color: var(--bywind-white); padding-left: 0.5rem; display: flex; flex-direction: column; justify-content: center; opacity: 0; transition: cubic-bezier(0.71, 0.15, 0.16, 1.15) 0.6s; }
.bannerText { font-size: 4rem; line-height: 4rem; font-weight: bold; }
.banner-righticon { font-size: 4rem; opacity: 0.6; }
#banners:hover #banner-hover { opacity: 1; padding-left: 2rem; background: #4259efc9; backdrop-filter: blur(15px); -webkit-backdrop-filter: blur(15px); -webkit-backface-visibility: hidden; -webkit-transform-style: preserve-3d; transition: 0.3s; background-size: 200%; cursor: pointer; } } .tags-group-icon { width: 120px; height: 120px; border-radius: 30px }
.tags-group-all { display: flex; transform: rotate(-30deg) }
.tags-group-all.nowrapMove { transform: rotate(0); padding-bottom: 2rem }
.tags-group-wrapper { margin-top: 5rem; display: flex; flex-wrap: nowrap; animation: rowup 60s linear infinite }
.nowrapMove .tags-group-wrapper { margin-top: 7rem; animation: rowup 120s linear infinite }
.tags-group-icon-pair .tags-group-icon:nth-child(even) { margin-top: 1rem; transform: translate(-60px) }
.tags-group-icon-pair { margin-left: 1rem }
.tags-group-icon { display: flex; align-items: center; justify-content: center; color: #fff; font-size: 66px; font-weight: 700; box-shadow: var(--bywind-shadow-blackdeep) }
.nowrapMove .tags-group-icon { border-radius: 50% }
.tags-group-icon img { width: 60% } .nowrapMove .tags-group-icon img { min-width: 100%; min-height: 100%; border-radius: 50%; object-fit: cover }
.categoryItem:hover i { opacity: .8; transition: .8s; transition-delay: .15s; transform: scale(1.03) rotate(0); font-size: 2.5rem; filter: blur(0) }
@media screen and (min-width: 1300px) { .categoryItem:hover i { transform:scale(1.03) rotate(0) } }
.cate-button-text { box-shadow: var(--bywind-shadow-black) }
.recent-post-top .categoryGroup { display: flex; flex-direction: column; justify-content: space-between; min-width: 200px }
.categoryGroup .categoryItem:nth-child(3) { display: none }
@media screen and (min-width: 1300px) { .recent-post-top .categoryGroup { flex-direction:row; height: 24% }
.categoryItem { width: calc(100% / 3 - .33rem); height: 100%; margin-right: .5rem }
.categoryItem:last-child { margin-right: 0 }
.categoryItem:hover { width: 50% }
.categoryGroup .categoryItem:nth-child(3) { display: flex } }
a.categoryButton.bikan { background: linear-gradient(to right,#358bff,#15c6ff); background-size: 200% }
a.categoryButton.remen { background: linear-gradient(to right,#f65,#ffbf37); background-size: 200% }
a.categoryButton.shiyong { background: linear-gradient(to right,#18e7ae,#1eebeb); background-size: 200% }
[data-theme=dark] a.categoryButton.bikan { background: linear-gradient(to right,#0653b8,#2fcbff); background-size: 200% }
[data-theme=dark] a.categoryButton.remen { background: linear-gradient(to right,#e22a16,#da980c); background-size: 200% }
[data-theme=dark] a.categoryButton.shiyong { background: linear-gradient(to right,#099e74,#0ea4a4); background-size: 200% }
a.categoryButton:hover { background-position: 100% 0 } @keyframes rowup { from { transform: translateX(0) }
to { transform: translateX(-50%) } } #recent-post-top .recent-post-item .post_cover { width: 100%; }
|
hexo三连即可,对于部分样式问题可以f12自取,如有问题可以评论区交流。