基于Hexo和Butterfly创建个人技术博客,(12) 定制化博客站点高级功能,如搜索、在线聊天、自定义样式等

news2024/10/6 8:32:07

Butterfly官方网站,请 点击进入
部分特效来源于网站的总结,请点击进入

本章目标:
选择自己需要的内容,然后加以实现。本文中涉及的修改方式主要包含三种:1、修改源码;2、扩展源码;3、添加插件;

一、引入自定义js、css文件

在/source/下新建css目录用于存放自定义的js和css,然后修改主题文件

inject: # 插入代码到头部 </head> 之前 和 底部 </body> 之前
  head:
    - <link rel="stylesheet" href="/css/custom.css">
  bottom:
    - <link rel="stylesheet" href="/css/footer.css">

二、UI美化

1、自定义字体

这个字体是对全站生效的,在custom.css中添加以下内容

@font-face {
    font-family: 'bodyfont';
    src: url('https://npm.elemecdn.com/ethan4116-blog/lib/font/ZhuZiAWan.ttf');
    font-display: swap;
}

body,
.bfont {
    font-family: bodyfont !important;
}

2、top图增加视频功能

这个稍有点复杂,教程是用butterfly 4.9.0版本改的,这个功能一般用于page类型的页面会比较合适。

  1. 修改 custom.css添加如下代码
/*视频功能*/
#index-video {
    z-index: 0;
    position: absolute;
    top: 0;
    left: 0;
    height: 80vh;
    width: 100%;
    object-fit: cover;
}
@media only screen and (max-width: 768px) {
    #index-video {
        display: none;
    }
}

@media only screen and (min-width: 768px) {
    .bg-cover {
        background-image: none !important;
    }
}
  1. 修改 /themes/butterfly/source/css/_layout/head.styl添加如下代码,注意代码缩进
    &.has-video
    position: relative
    height: 80vh !important

  #page-site-info-video
    position: absolute
    top: 300px
    padding: 0 10px
    width: 100%

    +maxWidth768()
      top: 140px
  1. 修改 /themes/butterfly/layout/includes/header/index.pug第23行左右,替换原来var isHomeClass实现,变成如下代码
    // - var isHomeClass = is_home() ? 'full_page' : 'not-home-page'
    - var isHomeClass = is_home() ? 'full_page' : (page.banner_type == 'video' ) ? 'not-home-page has-video bg-cover' : 'not-home-page'

并在这个文章最后添加

    if page.banner_type == 'video'
        video#index-video(autoplay='' loop='' muted='')
          source(src=page.top_img)
        #page-site-info-video
          h1#site-title=site_title

4、测试,可以随便找一个页面,修改front-matter,添加如下两行:

top_img: https://xxxx.mp4
banner_type: video 

上面代码中的 banner_typevideo是自定义的类型,可以自己定义,但需要同时修改index.pug文件。
这个视频功能不支持默认配置,只能在单个page页中配置;

三、功能套件

比如某些文章不想对外看到或是为了拉粉需要填加微信公众号后,然后才能得到就可以用到此功能了。

1、文章加密

  1. npm install --save hexo-blog-encrypt;,github地址请查看
  2. 在需要加密的文章的front-matter中设置password: hello
password: hello1
message: 您好, 这里需要密码, 请微信联系博主获取.
theme: Wave
wrong_pass_message: 抱歉, 这个密码看着不太对, 请微信联系管理员获取.

2、本地搜索

在这里插入图片描述

安装插件 : npm install hexo-generator-search --save

  1. 修改_config.xml文件,添加以下内容
search:
  path: search.xml
  field: post
  content: true
  format: html
  1. 修改_config.butterfly.xml文件,添加以下内容
local_search: # search (搜索)
  enable: true
  preload: false
  top_n_per_article: 1
  unescape: false
  CDN:

3、在线聊天-TIDIO

在这里插入图片描述

  1. 在tidio官网注册帐号,注册过程需要设置几步操作,挺简单的按说明选择就好。 ;
    2、修改_config.butterfly.xml文件,添加以下内容,不再需要引入额外的js文件了:
chat_btn: true # 工具栏的聊天按钮
chat_hide_show: true #向上滚动时才显示,向下滚动时隐藏

tidio:
  enable: true
  public_key: aokypncqxxxxxx

其中 Public key 在 tidio 的 TIDIO操作面板中取,如下图:
在这里插入图片描述

4、侧边栏添加个人微信二维码

  1. /themes/butterfly/layout/includes/widget文件夹下新建card_wx.pug文件,内容如下:
#card-wechat.card-widget.tzy-right-widget
    #flip-wrapper
      #flip-content
        .face
        .back.face
  1. 修改/themes/butterfly/layout/includes/widget/index.pug文件,添加如下内容
    else
      !=partial('includes/widget/card_author', {}, {cache: true})
      !=partial('includes/widget/card_announcement', {}, {cache: true})
      !=partial('includes/widget/card_wx', {}, {cache: true}) # 新增这行
      !=partial('includes/widget/card_top_self', {}, {cache: true})
  else
    //- page
    !=partial('includes/widget/card_author', {}, {cache: true})
    !=partial('includes/widget/card_announcement', {}, {cache: true})
    !=partial('includes/widget/card_wx', {}, {cache: true}) # 新增这行
  1. 复制以下内容到custom.css文件中,custom.css文件如何添加见本章开头描述;
/* 公众号 Start */

[data-theme='light'] #aside-content .card-widget#card-wechat {
    background: #49b1f5 !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(/img/wx_cover.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(/img/wx.png) center center no-repeat;
    background-size: 100%;
}
  1. 设置上面的css中图片部分为自己的图片

5、页脚部分设置

本节候改的内容比较多,本站最终设置好的样子如下图所示:
在这里插入图片描述

  1. 修改/themes/butterfly/layout/includes/footer.pug文件,完整代码如下:
#footer-wrap
  #ft
    .ft-item-1
      .t-top
        .t-t-l
          p.ft-t.t-l-t 关于本站
          .bg-ad
            div
              | (这里的内容随你写,但是不要过长影响整体美观度,具体可根据实现效果修改)随便说点什么说点什么、随便说点什么说点什么随便说点什么说点什么随。
        .t-t-r
          p.ft-t.t-l-t 快捷导航
          ul.ft-links
            li
              a(href='https://') 建站指南
              a(href='https://') 网址导航
            li
              a(href='https:///') 来杯咖啡
              a(href='https:///') 留点什么
            li
              a(href='https:///') 关于博主
              a(href='https:///') 文章归档
    .ft-item-2
      p.ft-t 推荐链接
      .ft-img-group
        .img-group-item
          a(href='https://aa11.top/')
            img(src='https://bu.dusays.com/2022/05/02/626f92e193879.jpg' alt='')

  if theme.footer.owner.enable
    - var now = new Date()
    - var nowYear = now.getFullYear()
    if theme.footer.owner.since && theme.footer.owner.since != nowYear
      .copyright!= `&copy;${theme.footer.owner.since} - ${nowYear + ' '}  By ${config.author}`
    else
      .copyright!= `&copy;${nowYear + ' '} <i id="heartbeat" class="fa fas fa-heartbeat"></i> ${config.author}`

  if theme.footer.copyright
    .framework-info
      span= _p('footer.framework') + ' '
      a(href='https://hexo.io')= 'Hexo'
      span.footer-separator |
      span= _p('footer.theme') + ' '
      a(href='https://github.com/jerryc127/hexo-theme-butterfly')= 'Butterfly'
  if theme.footer.custom_text
    .footer_custom_text!=`${theme.footer.custom_text}`

  1. 将以下代码复制到自定义的custom.css中,custom.css的创建方法见本章开头描述
/* 自定义底部  start */
#ft {
    max-width: 1200px;
    margin: 0 auto 12px;
    display: flex;
    color: rgb(255 255 255 / 80%) !important;
    text-align: left;
    flex-wrap: wrap;
}

.ft-item-1,
.ft-item-2 {
    display: flex;
    height: 100%;
    padding: 10px 14px;
}

.ft-item-1 {
    flex-direction: column;
    flex: 2;
}

.ft-item-2 {
    flex: 1;
    flex-direction: column;
}

.t-top {
    display: flex;
}

.t-top .t-t-l {
    display: flex;
    flex-direction: column;
    flex: 1.4;
    margin-right: 10px;
}

.t-top .t-t-l .bg-ad {
    width: 85%;
    border-radius: 10px;
    padding: 0 10px;
}

.t-top .t-t-r {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.ft-links {
    padding: 0 14px;
    list-style: none;
    margin-top: 0 !important;
}

.ft-links li a {
    display: inline-block !important;
    width: 50%;
    cursor: pointer !important;
}

.ft-links li a:hover {
    text-decoration: none !important;
    color: #6f42c1 !important;
}

.ft-item-2 .ft-img-group {
    width: 100%;
}

.ft-t {
    font-size: 0.8rem;
    margin-bottom: 20px;
    line-height: 1;
    font-weight: 600;
}

.t-l-t {
    padding-left: 14px;
}

.ft-item-2 .ft-img-group .img-group-item {
    display: inline-block;
    width: 18.4%;
    margin-right: 14px;
    margin-bottom: 6px;
}

.ft-item-2 .ft-img-group .img-group-item a {
    display: inline-block;
    width: 100%;
    height: 100%;
    cursor: pointer !important;
}

.ft-item-2 .ft-img-group .img-group-item a img {
    width: 100%;
    max-height: 80px;
}

@media screen and (max-width: 768px) {

    .ft-item-1 {
        flex-basis: 100% !important;
    }

    .ft-item-2 {
        flex-basis: 100% !important;
    }

    .t-top .t-t-l .bg-ad {
        width: 100%;
    }
}

@media screen and (max-width: 576px) {
    .t-top {
        flex-wrap: wrap;
    }

    .t-top .t-t-l {
        flex-basis: 100% !important;

    }

    .t-top .t-t-r {
        margin-top: 16px;
        flex-basis: 100% !important;
    }
}
/* 自定义底部  End */

3、如果未调整过主题颜色的话还需要修改以下代码,否则在light模式下,链接hover的效果是白色,看不见,修改themes/butterfly/source/css/_mode/darkmode.styl,在文章最后添加如下代码,注意缩进

    .ft-links li a:hover {
      text-decoration: none !important;
      color: $light-blue !important;
    }

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/664188.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

项目进度延误怎么办?给项目经理的6个处理提示

有研究调查称&#xff0c;只有2.5%的企业能100%成功完成他们的项目。影响项目成功的因素有很多&#xff0c;但对项目生产力造成严重损失的一个重要方面是项目延误。 无论是同事请病假&#xff0c;还是客户想要返工&#xff0c;许多事情都可能导致项目延误。当发生这些情况&…

桥梁监测系统多少钱?桥梁监测系统组成部分有哪些?

桥梁作为大多数城市和国家的重要设施&#xff0c;为居民提供了交流和沟通的纽带。然而&#xff0c;随着时间的推移、超荷载的运输和不间断的环境影响&#xff0c;桥梁的状态日益恶化。为了更好的了解桥梁的结构状态&#xff0c;保障桥梁的安全性和可靠性&#xff0c;桥梁监测系…

SQL注入第二章节MYSQL手工注入

SQL注入第二章节MYSQL手工注入 2.1 SQL注入之sqli-labs环境搭建 一、SQLi-Labs是什么&#xff1f; SQLi-Labs是一个专业的SQL注入练习平台&#xff0c;适用于GET和POST场景&#xff0c;包含了以下注入&#xff1a; 基于错误的注入&#xff08;Union Select&#xff09; 字符…

信息论/python笔记: 最大信息系数 MIC

1 互信息 sklearn 笔记整理&#xff1a;sklearn.metrics_sklearn中的mean absolute percentage error_UQI-LIUWJ的博客-CSDN博客 2 最大信息系数&#xff08;MIC&#xff0c;Maximal Information Coefficient&#xff09; 2.1 方法介绍 衡量两个变量X和Y之间的关联程度&…

知识蒸馏的说明

本文参考&#xff1a; ChatGPT 温度系数t与top-p, 超参怎么设置最优&#xff1f; - 知乎 知识蒸馏系列&#xff08;一&#xff09;&#xff1a;三类基础蒸馏算法_OpenMMLab的博客-CSDN博客 知识蒸馏算法汇总 - 知乎 知识蒸馏__Old_Summer的博客-CSDN博客 目录 1、 ChatGPT…

一文弄懂mysql事务

首先,什么是事务呢? 事务就是由单独单元的一个或多个sql语句组成, 在这个单元中, 每个sql的语句都是相互依赖的, 而整个单独单元作为一个不可分割的整体存在, 类似于物理当中的原子(一种不可分割的最小单位) 通俗的来讲就是, 事务就是一个整体, 里面的内容要么都执行成功, 要…

大学生找工作的个人简历模板(合集)

大学生找工作的个人简历模板1 个人基本简历 姓名&#xff1a;-国籍&#xff1a;中国 目前所在地&#xff1a;__ 民族&#xff1a;汉族 户口所在地&#xff1a;__ 身材&#xff1a; 婚姻状况&#xff1a;未婚年龄&#xff1a;__岁 培训认证&#xff1a;诚信徽章&#xff1a; 求职…

swagger 入门指南

1. 写在最前面 最近在负责的服务&#xff0c;出现了客户接二连三的投诉 api 参数难以理解的问题。本着从「根本上解决问题」的思路&#xff0c;笔者思考了以下方案&#xff1a; 简化难以理解的参数&#xff0c;重新设计一版 api 优化 api 文档&#xff0c;更易于用户理解 1…

代码随想录算法训练营第四十一天| 343. 整数拆分、96.不同的二叉搜索树

整数拆分 题目链接&#xff1a;力扣 确定dp数组&#xff08;dp table&#xff09;以及下标的含义 dp[i]&#xff1a;分拆数字i&#xff0c;可以得到的最大乘积为dp[i]。确定递推公式 然后有两种渠道得到dp[i]&#xff1a; 一个是j * (i - j) 直接相乘。 一个是j * d…

unit4

目录 carpenterovertakeremainderobjectivepasturedespitegulfshepherdinteriorchorusoppressgrinprofessionalresistantfosterleapembarkneutralelasticcirculateintimidatechopprimarystirappraisallayoutsurvivalentertainmoanlocatepublishpacehearingexplosivecricketvolt…

stable-diffusion-webui 快捷安装教程

简介 stable-diffusion-webui 是一个用来装载Stable Diffusion 模型的网页&#xff0c;可以方便的调用模型生成图片。 stable-diffusion-webui的github地址为&#xff1a;https://github.com/AUTOMATIC1111/stable-diffusion-webui 这个库的依赖很多&#xff0c;虽然代码里面有…

NUCLEO-F411RE RT-Thread 体验 (1) - GCC环境 RT-Thread 的移植

NUCLEO-F411RE RT-Thread 体验 (1) - GCC环境 RT-Thread 的移植 1、准备工作 a、用stm32cubemx新建一个工程。 时钟配置 st-link提供8M的mco输出&#xff0c;所以配置hse 8m&#xff0c;sysclk最高100M&#xff0c;设置如下&#xff1a; 配置LED 连接pa5&#xff0c;设…

机器学习-进化算法

进化算法 遗传算法&#xff08;Genetic Algorithm&#xff0c;GA&#xff09;crossovermutation 进化策略&#xff08;Evolutionary Strategies&#xff0c;ES&#xff09;基因编程&#xff08;Genetic Programming&#xff09;Multi-objective Evolutionary Algorithms 遗传算…

certbot 申请免费SSL证书、自动续期

简介 Certbot是一个免费、开源的软件&#xff0c;是Let’s Encrypt的客户端&#xff0c;Let’s Encrypt是证书颁发机构&#xff0c;它们之间使用ACME协议通信&#xff0c;Certbot是Lets Encrypt众多客户端的其中之一&#xff0c;Let’s Encrypt官网推荐CertBot&#xff0c;它能…

AIGC:关于人工智能的那些事

文章目录 前言人工智能发展史起步阶段&#xff1a;20世纪50年代至70年代知识工程阶段&#xff1a;20世纪80年代至90年代数据驱动阶段&#xff1a;2000年至今 人工智能包括哪些技术学习人工智能需要掌握的知识如何开发一个人工智能系统如何开发一个人脸识别系统人工智能未来发展…

mysql密码登录失败、服务启动失败和1045-Access denied for user ‘root‘@‘localhost‘

一、问题&#xff1a; 1.打开 navicate&#xff0c;双击localhost_3306&#xff0c;出现报错2002 - Can’t connect to server on ‘localhost’(10061) 2.查看mysql是否启动 控制面板——管理工具——服务 找到mysql服务&#xff0c;发现无法启动。 3.winR运行cmd&#xf…

windows install pandoc

文章目录 下载安装测试使用 下载 https://github.com/jgm/pandoc/releases 安装 pandoc-3.1.3-windows-x86_64.msi 直接双击一路默认即可。 但安装后并没有得到该命令&#xff0c;我们需要配置环境变量&#xff0c;找到安装的命令位置 C:\Users\XH\AppData\Local\Pandoc\p…

驱动多文件编译和驱动命令行传参

目录 1. 驱动的多文件编译 1.1. 准备两个文件 1.2. 修改Makefile文件 1.3. 执行Make命令生成.ko文件 2. 驱动模块传递参数 2.1. 传递一个参数 2.1.1. 函数原型分析 2.1.2. 撰写.c文件 2.1.3. 撰写makefile 2.1.4. 编译makefile并验证 2.2. 传递多个参数并使用modeinf…

线程的创建和使用(二)

1、线程的类和方法 Thread类是JVM用来管理线程的一个类&#xff0c;换句话说&#xff0c;每个线程都有唯一一个的Thread对象与之关联。 1.1、Thread的常见方法 方法说明Thread()创建线程对象Thread(Runnable target)使用Runnable对象创建线程对象Thread(String name)创建线程…

【SpringCloud-5】gateway网关

网关是干啥用的就不用再说了。 sringcloud中的网关&#xff0c;第一代是zuul&#xff0c;但是性能比较差&#xff08;1.x是阻塞式的&#xff0c;2.x是基于Netty的&#xff09;&#xff0c;然后有了第二代GateWay&#xff0c;基于Reactor模型 异步非阻塞。 springcloud网关就是一…