Skip to content

参考heo效果

step1: 在_config.yml中增加配置(记得冒号后面的空格哦)

yml
toggleList: [
  {
    title: '博客相关',
    list: [
      {
        text: '主页',
        link: 'https://www.addthis.com/',
        src: 'https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image'
      },
      {
        text: '博客',
        link: 'https://www.addthis.com/',
        src: 'https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image'
      }
    ]
  },
  {
    title: '其他工具',
    list: [
      {
        text: '腾讯云',
        link: 'https://www.addthis.com/',
        src: 'https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image'
      }
    ]
  }
]
  • 根据自己的需要调整自己实际的链接入口
  • 可以使用post目录规则的相对路径
yml
toggleList:
  - title: 标题
    list: 
      - text: 主页
        link: https://www.addthis.com/
        src: https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image
      - text: 博客
        link: https://www.addthis.com/
        src: https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image
  - title: 标题2
    list: 
      - text: 美化文档
        link: https://www.addthis.com/
        src: https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image
      - text: 腾讯云
        link: https://www.addthis.com/
        src: https://p9-passport.byteacctimg.com/img/mosaic-legacy/3791/5070639578~300x300.image

step2: themes\butterfly\layout\includes\header\nav.pug 中替换logo部分布局(建议做好原文件备份)

pug
nav#nav
  div#blog_name
    div.back-home-button
      i.fas.fa-bars.fa-fw
      if (config.toggleList)
      div.back-menu-list-groups
        - let toggleList = config.toggleList
        each group in toggleList
          div.back-menu-list-group
            div.back-menu-list-title= group.title 
            div.back-menu-list
              - let list = group.list
              each item in list
                - let link = /http/i.test(item.link)?item.link:url_for('/')+item.link
                - let src = item.src ? (/http/i.test(item.src)?item.src:url_for('/')+item.src) : 'https://butterfly.js.org/img/404.jpg'
                  a.back-menu-item(href=`${link}`) 
                    img.back-menu-item-icon(src=`${src}`)
                    span.back-menu-item-text #[=item.text]
    a#site-name(href=url_for('/')) #[=config.title]

step3: 在公共css中加入样式,按自己的引用文件自行添加(未使用less的同学请自行拆解为css)

less
#nav {
    #blog_name {
        flex-wrap: nowrap;
        height: 60px;
        display: flex;
        align-items: center;
        z-index: 102;
        transition: .3s;

        .back-home-button{
            background: #202020;
            color: #fff;
            .back-menu-list-groups {
                position: absolute;
                top: 65px;
                left: 1.5rem;
                background: #fff;
                border-radius: 12px;
                border: 1px solid#e3e8f7;
                flex-direction: column;
                font-size: 12px;
                color: rgba(60, 60, 67, 0.6);;
                box-shadow: 0 8px 16px -4px #2c2d300c;
                transition: 0s;
                opacity: 0;
                pointer-events: none;
            }
            &:hover{
                .back-menu-list-groups {
                    display: flex;
                    opacity: 1;
                    transition: .3s;
                    top: 55px;
                    pointer-events: auto;
                    left: 1.5rem;
                }
            }
            .back-menu-list-group {
                display: flex;
                flex-direction: column;
                .back-menu-list-title {
                    margin: 8px 0 0 16px;
                    transition: .3s;
                }
                .back-menu-list {
                    display: flex;
                    flex-direction: row;
                    flex-wrap: wrap;
                    width: 340px;
                    justify-content: space-between;
                    &:before {
                        position: absolute;
                        top: -15px;
                        left: 0;
                        width: 100%;
                        height: 20px;
                        content: '';
                    }
                    .back-menu-item {
                        width: 150px;
                        display: flex;
                        align-items: center;
                        margin: 4px 8px;
                        padding: 4px 8px;
                        transition: .3s;
                        border-radius: 8px;
                        height: 40px;
                        &:hover{
                            color: #fff;
                            background: rgba(0,0,0,.9);
                            transition: .3s;
                            .back-menu-item-text{
                                color:#fff;
                            }
                        }
                        .back-menu-item-icon {
                            width: 24px;
                            height: 24px;
                            border-radius: 24px;
                            background: #f1f3f8;
                        }
                        .back-menu-item-text {
                            font-size: 16px;
                            margin-left: .5rem;
                            color: #363636;
                        }
                    }
                }
            }
            
        }
        
        .back-home-button {
            display: flex;
            width: 35px;
            height: 35px;
            padding: 0;
            align-items: center;
            justify-content: center;
            margin-right: 4px;
            transition: .3s;
            border-radius: 8px;
            color: #fff;
        }
    }
}
@media screen and (min-width: 900px){
    #nav .back-home-button:hover {
        box-shadow: 0 8px 12px -3px #20202023;
        
    }
}
@media screen and (max-width: 768px){
    .back-home-button:hover .back-menu-list-groups {
        padding-bottom: 8px;
        box-shadow: 0 8px 12px -3px #20202023;
        left: 2px !important;
    }
}

更改完配置项,hexo cl && hexo s 看看效果吧!

Released under the MIT License.