Hexo+Butterfly系列:主题魔改(二) 您所在的位置:网站首页 收藏按钮图标怎么设置 Hexo+Butterfly系列:主题魔改(二)

Hexo+Butterfly系列:主题魔改(二)

#Hexo+Butterfly系列:主题魔改(二) | 来源: 网络整理| 查看: 265

此文档是基于 Butterfly文档 整理的,请知悉!

更换主题

Hexo官网上提供了丰富的主题资源 https://hexo.io/themes/ ,具体操作请查看你选的主题官方文档(GitHub或主题网站会提供)。

我选了Butterfly主题,Butterfly博客地址:https://butterfly.js.org/ 。这个网站还提供Butterfly文档:https://butterfly.js.org/archives/ 。对应的GitHub地址:https://github.com/jerryc127/hexo-theme-butterfly 。我们应该先熟悉这些文档,再修改主题。

修改主题之前先看下Hexo项目结构:

.deploy_git:部署到Gitee的文件夹,存放生成的静态页面node_modules: 依赖包public:部署到本地的文件夹,存放生成的静态页面scaffolds:生成文章的md模板source:存放文章md文件、图片、样式文件等一些资源themes:主题,Hexo 会根据主题来生成静态页面_config.landscape.yml:主题配置文件,用来修改主题,landscape是Hexo主题其中之一_config.yml:网站配置文件

打开WebStorm,选择创建好的Hexo项目,直接在终端中输入下列命令:

1git clone -b master https://gitee.com/immyw/hexo-theme-butterfly.git themes/butterfly

Github在国内网速不太稳,下载失败就继续输入命令,直到下载成功为止,如下图:

在WebStorm打开网站配置文件 _config.yml,修改默认主题:

1theme: butterfly

在WebStorm,把themes/butterfly目录下_config.yml复制到Hexo根目录下并改名为_comfig.butterfly.yml,作为Hexo的主题配置文件,操作如下:

如果没有 pug 以及 stylus 的渲染器,需要安装,在WebStorm终端输入:

1npm install hexo-renderer-pug hexo-renderer-stylus --save

如果有升级需求,请参考:https://butterfly.js.org/posts/21cfbf15/ 升级建议。

测试主题是否成功更换,WebStorm终端输入下列命令:

1hexo s

访问 http://localhost:4000/ ,Hexo Butterfly主题页面效果如下图:

标签页实现流程

前往你的 Hexo 博客的根目录

输入hexo new page tags

你会找到source/tags/index.md这个文件

修改这个文件:

记得添加 type: “tags”

12345---title: 标签date: 2018-01-05 00:00:00type: "tags"---

分类页实现流程

前往你的 Hexo 博客的根目录

输入hexo new page categories

你会找到source/categories/index.md这个文件

修改这个文件:

记得添加 type: “categories”

12345---title: 分类date: 2018-01-05 00:00:00type: "categories"---

友情链接实现流程

前往你的 Hexo 博客的根目录

输入 hexo new page link

你会找到source/link/index.md这个文件

修改这个文件:

记得添加 type: “link”

12345---title: 友情链接date: 2018-06-07 22:17:49type: "link"---

友情链接界面可以由用户自己自定义,只需要在友情链接的md档设置就行,以普通的Markdown格式书写。

123456789101112131415{% sitegroup %}{% site Butterfly官方, url=https://butterfly.js.org/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300218387.png, avatar=https://butterfly.js.org/img/avatar.png %}{% site 小康博客, url=https://www.antmoe.com/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300218028.png, avatar=https://cdn.jsdelivr.net/npm/kang-static@latest/avatar.jpg %}{% site 小冰博客, url=https://zfe.space/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300217925.png, avatar=https://zfe.space/images/headimage.png %}{% site guole's Blog, url=https://guole.fun/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300217423.png, avatar=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300220191.jpeg %}{% site Akilar の糖果屋, url=https://akilar.top/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300216048.png, avatar=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300224803.png %}{% site HEO, url=https://blog.zhheo.com/, screenshot=https://gitee.com/zhu-dongya/blog-img/raw/master/202111300228509.png, avatar=https://blog.zhheo.com/img/avatar.png %}{% endsitegroup %}图库实现流程

图库页面只是普通的页面,你只需要hexo new page gallery创建你的页面就行

然后在gallery使用标签外挂 galleryGroup,具体用法请查看对应的内容。

12345{% galleryGroup '壁纸' '收藏的一些壁纸' '/Gallery/wallpaper' https://i.loli.net/2019/11/10/T7Mu8Aod3egmC4Q.png %}{% galleryGroup '漫威' '关于漫威的图片' '/Gallery/marvel' https://i.loli.net/2019/12/25/8t97aVlp4hgyBGu.jpg %}{% galleryGroup 'OH MY GIRL' '关于OH MY GIRL的图片' '/Gallery/ohmygirl' https://i.loli.net/2019/12/25/hOqbQ3BIwa6KWpo.jpg %}

子页面也是普通的页面,你只需要hexo n page xxxxx 创建你的页面就行

然后使用标签外挂 gallery,具体用法请查看对应的内容。

12345678910{% gallery %}![](https://i.loli.net/2019/12/25/Fze9jchtnyJXMHN.jpg)![](https://i.loli.net/2019/12/25/ryLVePaqkYm4TEK.jpg)![](https://i.loli.net/2019/12/25/gEy5Zc1Ai6VuO4N.jpg)![](https://i.loli.net/2019/12/25/d6QHbytlSYO4FBG.jpg)![](https://i.loli.net/2019/12/25/6nepIJ1xTgufatZ.jpg)![](https://i.loli.net/2019/12/25/E7Jvr4eIPwUNmzq.jpg)![](https://i.loli.net/2019/12/25/mh19anwBSWIkGlH.jpg)![](https://i.loli.net/2019/12/25/2tu9JC8ewpBFagv.jpg){% endgallery %}404页面效果预览

实现流程

主题内置了一个简单的404页面,可在主题配置文件中开启

本地预览时,访问出错的网站是不会跳到404页面的。

如需本地预览,请访问 http://localhost:4000/404.html

12345# A simple 404 pageerror_404: enable: true subtitle: "页面没有找到" background:

站点信息实现流程

修改网站各种资料,例如标题、副标题和邮箱等个人资料,请修改博客根目录的_config.yml

导航菜单实现流程

修改 主题配置文件

123456789Home: / || fas fa-homeArchives: /archives/ || fas fa-archiveTags: /tags/ || fas fa-tagsCategories: /categories/ || fas fa-folder-openList||fas fa-list: Music: /music/ || fas fa-music Movie: /movies/ || fas fa-videoLink: /link/ || fas fa-linkAbout: /about/ || fas fa-heart

必须是 /xxx/,后面||分开,然后写图标名。

如果不希望显示图标,图标名可不写

注意: 导航的文字可自行更改

例如:

12345678910111213# 导航菜单menu: 首页: / || fas fa-home 文章||fa fas fa-book: 归档: /archives/ || fas fa-archive 标签: /tags/ || fas fa-tags 分类: /categories/ || fas fa-folder-open 生活||fa fa-heartbeat: 图书: /book/ || fas fa-book 电影: /movies/ || fas fa-video 相册: /gallery/ || fas fa-images 友链: /link/ || fas fa-link 关于: /about/ || fas fa-heart

查看效果:

代码块风格实现流程

参考:Butterfly 安裝文檔(三) 主題配置-1 | 代码

修改 主题配置文件

1highlight_theme: light

我选的是mac:

代码块mac风格效果如下:

社交图标实现流程

Butterfly支持 font-awesome v5图标.

书写格式 图标名:url || 描述性文字

123social: fab fa-github: https://github.com/xxxxx || Github fas fa-envelope: mailto:[email protected] || Email

图标名可在这寻找

img

主页文章节选

自动节选和文章页description

实现流程

因为主题UI的关系,主页文章节选只支持自动节选和文章页description。

在butterfly里,有四种可供选择

description: 只显示description

both: 优先选择description,如果没有配置description,则显示自动节选的内容

auto_excerpt:只显示自动节选false: 不显示文章内容

修改 主题配置文件_config.butterfly.yml

123index_post_content: method: 3 length: 500 # if you set method to 2 or 3, the length need to config

description在front-matter里添加

img

顶部图实现流程

如果不要显示顶部图(banner),可直接在主题配置文件配置 disable_top_img: true

上面是顶部图,主题配置文件改为disable_top_img: true即可关掉顶部图,效果图如下:

其他的请参考:Butterfly 安装文档(三) 主题配置-1 | 顶部图

文章置顶效果预览

实现流程

想要在首页置顶某篇文章,只需在文章头部信息添加以下内容:

1sticky: 1

数字越大,置顶优先级就越高。

文章封面实现流程

在文章修改:

img

排版问题请参考:Butterfly 安装文档(三) 主题配置-1 | 文章封面

我觉得Butterfly排版挺好看的,就不修改了。

文章页相关配置

参考:Butterfly 安装文档(三) 主题配置-1 | 文章页相关配置

文章meta显示

修改主题配置文件:

12345678910111213post_meta: page: date_type: both # created or updated or both 主页文章日期是创建日或者更新日或都显示 date_format: relative # date/relative 显示日期还是相对日期 categories: true # true or false 主页是否显示分类 tags: true # true or false 主页是否显示标籤 label: true # true or false 显示描述性文字 post: date_type: both # created or updated or both 文章页日期是创建日或者更新日或都显示 date_format: relative # date/relative 显示日期还是相对日期 categories: true # true or false 文章页是否显示分类 tags: true # true or false 文章页是否显示标籤 label: true # true or false 显示描述性文字

我不改了,按默认配置显示。

文章版权

参考:Butterfly 安装文档(三) 主题配置-1 | 文章版权

不修改,按默认的来。

文章打赏

参考:Butterfly 安装文档(三) 主题配置-1 | 打赏

TOC 目录

在文章页,会有一个目录,用于显示TOC。

修改主题配置文件:

1234toc: enable: true # 是否显示TOC number: true # 是否显示章节数 style_simple: true # 是否开启简洁模式(侧边栏只显示TOC)相关文章

相关文章推荐的原理是根据文章tags的比重来推荐

默认的主题配置文件:

1234related_post: enable: true # 是否开启 limit: 6 # 显示推荐文章数目 date_type: created # or created or updated 文章日期显示创建日或者更新日

如果6个文章的tags都是一样的,剩下的5个文章都会推荐给你看:

img

文章锚点

开启文章锚点后,当你在文章页进行滚动时,文章链接会根据标题ID进行替换(注意: 每替换一次,会留下一个历史记录。 所以如果一篇文章有很多锚点的话,网页的历史记录会很多。 )

修改主题配置文件

123# anchor# when you scroll in post , the url will update according to header id.anchor: true

我已经把false改为true。

文章过期提醒

可设置是否显示文章过期提醒,以更新时间为基准。

修改主题配置文件

12345678# Displays outdated notice for a post (文章过期提醒)noticeOutdate: enable: true style: flat # style: simple/flat limit_day: 365 # When will it be shown position: top # position: top/bottom message_prev: 距离上次更新已经过了 message_next: 天,文章所描述的內容可能已经发生变化,请留意

limit_day: 距离更新时间多少天才显示文章过期提醒

message_prev : 天数之前的文字

message_next:天数之后的文字

我已经改为true,还改了提示。

文章标签按钮(分页)

可设置标签的逻辑,也可以关闭标签显示

主题配置文件

123456# post_pagination (分页)# value: 1 || 2 || false# 1: The 'next post' will link to old post# 2: The 'next post' will link to new post# false: disable paginationpost_pagination: falsepost_pagination: false 关闭标签按钮post_pagination: 1 下一篇显示的是旧文章post_pagination: 2 下一篇显示的是新文章

我改为

123456# post_pagination (分页)# value: 1 || 2 || false# 1: The 'next post' will link to old post 下一篇显示的是旧文章# 2: The 'next post' will link to new post 下一篇显示的是新文章# false: disable paginationpost_pagination: 2 # 下一篇新文章头像实现流程

修改 主题配置文件

123avatar: img: /img/avatar.png effect: true # 头像会一直转圈

我修改为

1234# Avatar (头像)avatar: img: https://portrait.gitee.com/uploads/avatars/user/465/1396027_zhu-dongya_1637328344.png # /img/avatar.png 图片放在source/img目录下 effect: false # 是否开启头像一直转圈复制相关配置实现流程

可配置网站是否可以复製、复製的内容是否添加版权信息

修改主题配置文件

1234567# copy settings# copyright: Add the copyright information after copied content (复製的内容后面加上版权信息)copy: enable: true copyright: enable: true limit_count: 50enable 是否开启网站复製权限copyright 复製的内容后面加上版权信息enable 是否开启复製版权信息添加limit_count 字数限制,当复製文字大于这个字数限制时,将在复製的内容后面加上版权信息

我把默认的limit_count: 50改为limit_count: 200

Footer 设置实现流程

博客年份

since是一个来展示你站点起始时间的选项。它位于页面的最底部。

修改 主题配置文件

1234footer: owner: enable: true since: 2018

我改为:

123456footer: owner: enable: true since: 2020 # 博客年份 custom_text: Hi, welcome to my blog! copyright: true # Copyright of theme and framework右下角按钮简体繁体互换

右下角会有简繁转换按钮。

修改 主题配置文件

123456789101112translate: enable: true # 默认按钮显示文字(网站是简体,应设置为'default: 繁') default: 简 #网站默认语言,1: 繁体中文, 2: 简体中文 defaultEncoding: 1 #延迟时间,若不在前, 要设定延迟翻译时间, 如100表示100ms,默认为0 translateDelay: 0 #当文字是简体时,按钮显示的文字 msgToTraditionalChinese: "繁" #当文字是繁体时,按钮显示的文字 msgToSimplifiedChinese: "简"

我把true改为false,把简繁互关功能关掉

夜间模式

右下角会有夜间模式按钮

修改 主题配置文件

123456# dark modedarkmode: enable: true # dark mode和 light mode切换按钮 button: true autoChangeMode: false

V2.0.0 开始增加一个选项,可开启自动切换light mode 和 dark mode

autoChangeMode: 1 跟随系统而变化,不支持的浏览器/系统将按照时间晚上6点到早上6点之间切换为 dark mode

autoChangeMode: 2 只按照时间 晚上6点到早上6点之间切换为 dark mode,其余时间为light mode

autoChangeMode: false 取消自动切换

閲读模式

閲读模式下会去掉除文章外的内容,避免干扰閲读。

只会出现在文章页面,右下角会有閲读模式按钮。

修改主题配置文件

1readmode: true改变字体大小按钮

可以改变字体大小(最小隻能到 10px,最大隻能到 20px)

修改 主题配置文件

12# Change font sizechange_font_size: true

我把默认的false改为true

侧边栏设置主页侧边排版

可自行决定哪个项目需要显示,可决定位置,也可以设置不显示侧边栏。

修改 主题配置文件

1234567891011121314151617181920212223242526272829303132333435363738394041424344aside: enable: true hide: true # 除了主页,其他页都隐藏侧边栏 button: true mobile: true # display on mobile position: right # left or right card_author: # 作者卡片 enable: true description: button: enable: false # 我把访问GitHub按钮关了 icon: fab fa-github text: Follow Me link: https://github.com/zhu-dongya card_announcement: # 公告卡片 enable: true content: Hey gus, welcome to my blog. card_recent_post: # 最新文章 enable: true limit: 5 # if set 0 will show all sort: date # date or updated sort_order: # Don't modify the setting unless you know how it works card_categories: # 分类卡片 enable: true limit: 8 # if set 0 will show all expand: none # none/true/false sort_order: # Don't modify the setting unless you know how it works card_tags: # 标签卡片 enable: true limit: 40 # if set 0 will show all color: true # 是否开启标签颜色 sort_order: # Don't modify the setting unless you know how it works card_archives: # 时间归档 enable: false # 我给关了 type: monthly # yearly or monthly format: MMMM YYYY # eg: YYYY年MM月 order: -1 # Sort of order. 1, asc for ascending; -1, desc for descending limit: 8 # if set 0 will show all sort_order: # Don't modify the setting unless you know how it works card_webinfo: # 网站资讯,显示文章数目、访客数、总访问量、最后更新时间 enable: true post_count: true last_push_date: true sort_order: # Don't modify the setting unless you know how it works

访问人数 busuanzi (UV 和 PV)

访问 busuanzi 的官方网站查看更多的介绍。

修改 主题配置文件

1234busuanzi: site_uv: false # 是否开启本站访客数 site_pv: false # 是否开始本站总访问量 page_pv: false # 是否开启文章页阅读量

我都改为false,反正没人逛我的网站🤣

运行时间

修改 主题配置文件

123456runtimeshow: enable: true publish_date: 6/7/2018 00:00:00 ##网页开通时间 #格式: 月/日/年 时间 #也可以写成 年/月/日 时间

我把默认的false改为true,并加上时间

自定义添加栏目

参考:自定义侧边栏

标记插件(Tag Plugins)实现流程

标签外挂是Hexo独有的功能,并不是标准的Markdown格式。

以下的写法,只适用于Butterfly主题,用在其它主题上不会有效果,甚至可能会报错。使用前请留意

标签外挂虽然能为主题带来一些额外的功能和UI方面的强化,但是,标签外挂也有明显的限制,使用时请留意。

修改 主题配置文件

123456789101112note: # Note tag style values: # - simple bs-callout old alert style. Default. # - modern bs-callout new (v2-v3) alert style. # - flat flat callout style with background, like on Mozilla or StackOverflow. # - disabled disable all CSS styles import of note tag. style: simple icons: false border_radius: 3 # Offset lighter of background in % for modern and flat styles (modern: -12 | 12; flat: -18 | 6). # Offset also applied to label tag variables. This option can work with disabled note tag. light_bg_offset: 0

参考:Butterfly 安裝文檔(三) 主題配置-1 | 标记插件

标记插件很有用,Markdown经常会用到,值得看一看。

美化/特效

参考:Butterfly 安裝文檔(四) 主題配置-2 | 美化/特效

自定义主题色

可以修改大部分UI顏色,修改 主題配置文件:

123456789101112131415# 主题色theme_color: enable: true main: "#F44E5A" # 粉红色 paginator: "#F44E5A" # 分页器 button_hover: "#FF7242" # 按钮悬停 text_selection: "#F44E5A" # 文本选择 link_color: "#99a9bf" meta_color: "#858585" hr_color: "#A4D8FA" code_foreground: "#F47466" # 代码前景 code_background: "rgba(27, 31, 35, .05)" # 代码背景 toc_color: "#F44E5A" # TOC目录颜色 blockquote_padding_color: "#F44E5A" # 块引用填充颜色 blockquote_background_color: "#F44E5A" # 块引用背景颜色

上面是我改的。

背景特效

butterfly提供三种效果:静止彩带、动态彩带、canvas_nest

我选的是动态彩条,修改主题配置文件:

123canvas_fluttering_ribbon: # 动态彩带 enable: true mobile: false # false 手机端不显示 true 手机端显示页面美化

会改变ol、ul、h1-h5的样式,修改 主题配置文件:

123456# 美化页面显示beautify: enable: true field: post # site表示只在文章页生效/post表示在全站生效 title-prefix-icon: '\f0c1' title-prefix-icon-color: "#F47466"自定义字体和字体大小

修改主题配置:

1234567# Global font settings# Don't modify the following settings unless you know how they work (非必要不要修改)font: global-font-size: 16px # 站点字体太小了,我调到16px code-font-size: font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Lato, Roboto, "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif code-font-family: consolas, Menlo, "PingFang SC", "Microsoft JhengHei", "Microsoft YaHei", sans-serif字数统计实现流程

要为配上字数统计特性, 你需要如下几个步骤:

打开 hexo 工作目录

输入:npm install hexo-wordcount —save or yarn add hexo-wordcount

修改 :主题配置文件

12345wordcount: enable: true post_wordcount: true min2read: true total_wordcount: true

图片大图查看模式实现流程

butterfly主题提供两个模式:fancybox、medium_zoom

fancybox:放大图片查看时带有关闭、左右查看等一些操作按钮,需要点击空白处或者关闭按钮才能回到文章页。

medium_zoom:不带任何操作按钮,看完点击大图就能回到文章页。

显然medium_zoom很符合我的需求。

修改主题配置文件:

123456789# medium-zoom# https://github.com/francoischalifour/medium-zoommedium_zoom: true# fancybox# http://fancyapps.com/fancybox/3/fancybox: false注意:看上面fancybox和medium_zoom只能开启一个Instantpage 预加载实现流程

当鼠标悬停到链接上超过 65 毫秒时,Instantpage 会对该链接进行预加载,可以提升访问速度。

修改主题配置文件:

123# https://instant.page/# prefetch (预加载)instantpage: trueInject(引入外部css/js文件)实现流程

如想添加额外的js/css/meta等等东西,可以在Inject里添加,支持添加到head(标签之前)和bottom(标签之前)。

请注意:以标准的html格式添加内容

主题配置文件例如:

12345inject: head: - bottom: -

留意: 如果你的網站根目錄不是’/‘,使用本地圖片時,需加上你的根目錄。例如:網站是https://yoursite.com/blog,引用css/xx.css,則設置為

图片懒加载实现流程

修改主题配置文件:

12345lazyload: enable: true field: site # site全站/post文章页 placeholder: blur: falseiconfont实现流程

Butterfly主题内置了Font Awesome V5图标,目前已更新到 5.13.0,总共有1,588个免费图标。 由于是国外的图标网站,对于国内的一些网站Icon并不支持。 如有需要,你可以引入其它的图标服务商。

参考:Butterfly 安裝文檔(六) 進階教程 | iconfont

分享实现流程

主题配置文件:

123456# Share.js# https://github.com/overtrue/share.js# 分享sharejs: enable: true sites: facebook,twitter,wechat,weibo,qq

我把true改为false,即把分享按钮取消,看下图:

更换网站背景

参考:Hexo 博客之 butterfly 主题优雅更换背景)

注意:如果网站背景还是不生效,请在主题配置文件background后面补上 “#efefef”:

12345# Website Background (設置網站背景)# can set it to color or image (可設置圖片 或者 顔色)# The formal of image: url(http://xxxxxx.com/xxx.jpg)background: "#efefef"


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有