Hexo博客技巧:添加GitHub徽标

2023-11-10 05:10
文章标签 技巧 博客 hexo github 徽标

本文主要是介绍Hexo博客技巧:添加GitHub徽标,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

GitHub 徽标

1.GitHub 徽标可以直接通过 shields.io 在线生成。

2.理论上可以放在页面的任何地方。教程案例是添加在页脚。

3.工具网站包括:

  • 徽标生成网站:shields
  • 图标查询网站:simpleicons
  • html 压缩网站:htmlpack
  • 转义字符查询
    在这里插入图片描述

具体步骤

  1. 通过 shields.io 在线生成。

    • label: 标签,徽标左侧内容
    • message: 信息,徽标右侧内容
    • color: 色值,支持支持十六进制、rgb、rgba、hsl、hsla 和 css 命名颜色。十六进制记得删除前面的 #号
  2. 输入相关信息后,点击 make badge 即可得到徽标的 URL。可以用 img 标签引用,写法简单。不过正式写法建议用 object 标签引用,写法示例如下。

    HTML
    <!-- label=Frame,Message=Hexo,color=blue -->
    https://img.shields.io/badge/Frame-Hexo-blue
    <!-- 在页面上可以使用img标签来引用 -->
    <img src="https://img.shields.io/badge/Frame-Hexo-blue">
    <!-- 部分属性例如link需要用object标签来引用 -->
    <object data="https://img.shields.io/badge/Frame-Hexo-blue?link=https://hexo.io"></object>
    

拓展写法示例

填写说明

仅仅如此肯定是不能令人满意的,还可以继续添加样式。
shields.io 提供直接在 URL 内添加样式属性的功能。使用 ? 引用,使用 & 连接各属性。

属性说明示例
style徽标样式,默认提供了五种样式: plastic,flat,flat-square, for-the-badge,social?style=flat-square
label覆盖默认的左侧文本 (空格或特殊字符需要转 URL 编码!)?label=healthinesses
logo给左侧标签前插入图标 可以访问 simpleicons 查询图标?logo=Hexo
logo自定义图标, 限制较多,不推荐?logo=data:image/png;base64,url
logoColor设置徽标的颜色 (支持十六进制、rgb、 rgba、hsl、hsla 和 css 命名颜色)。 支持命名徽标, 但不支持自定义徽标。?logoColor=violet
logoWidth给图标提供的水平空间?logoWidth=40
link徽标指向的链接, 此时需要用 object 标签 引用才能生效 写法看示例代码?link=http://example.com
labelColor左侧部分背景色, (支持十六进制、rgb、 rgba、hsl、hsla 和 css 命名颜色)?labelColor=abcdef 或者?colorA=abcdef
color右侧部分背景色, (支持十六进制、rgb、 rgba、hsl、hsla 和 css 命名颜色)?color=fedcba 或者?colorB=fedcba

示例源码

<!-- 普通样式 -->
<img src="https://img.shields.io/badge/Frame-Hexo-blue">
<!-- 五种style预览 -->
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&style=plastic">
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&style=flat">
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&style=flat-square">
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&style=for-the-badge">
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&style=social">
<!-- 添加图标和自定义label -->
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&label=框架">
<!-- 添加图标和图标宽度 -->
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&logoWidth=30">
<!-- 图标、label、message三部分颜色自定义 -->
<img src="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&label=框架&logoColor=violet&labalColor=#1fd041&color=rgb(222, 31, 31)">
<!-- 给标签添加链接 -->
<object data="https://img.shields.io/badge/Frame-Hexo-blue?logo=Hexo&link=https://hexo.io/&https://hexo.io/zh-cn/docs/"></object>
<!-- 也可以通过嵌套a标签来实现添加链接 -->
<a target="_blank" href="https://hexo.io" title="框架采用Hexo"><img src="https://img.shields.io/badge/Frame-Hexo-blue"></a>

样式示例

在这里插入图片描述

  1. [Blogroot]\_config.butterfly.ymlfooter 配置项中添加徽标,注意事先压缩一下,使他们只留一行。为了不至于太过紧凑,设置一下行内间隔属性 margin-inline

    DIFFfooter:owner:enable: truesince: 2016
    -       custom_text:
    +       custom_text: <p><a style="margin-inline:5px" target="_blank" href="https://hexo.io/"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo"></a><a style="margin-inline:5px" target="_blank" href="https://butterfly.js.org/"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用butterfly"></a><a style="margin-inline:5px" target="_blank" href="https://www.jsdelivr.com/"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用JsDelivr为静态资源提供CDN加速"></a><a style="margin-inline:5px" target="_blank" href="https://vercel.com/ "><img src="https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&logo=Vercel" title="本站采用双线部署,默认线路托管于Vercel"></a><a style="margin-inline:5px" target="_blank" href="https://vercel.com/ "><img src="https://img.shields.io/badge/Hosted-Coding-0cedbe?style=flat&logo=Codio" title="本站采用双线部署,联通线路托管于Coding"></a><a style="margin-inline:5px" target="_blank" href="https://github.com/"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHub" title="本站项目由Gtihub托管"></a><a style="margin-inline:5px" target="_blank" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img src="https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Claris" title="本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可"></a></p>copyright: false # Copyright of theme and frameworkICP: # Chinese ICP License
    

插件化写法

  1. 修改[Blogroot]\themes\butterfly\layout\includes\footer.pug,添加页脚标签循环节:

    DIFFif theme.footer.custom_text.footer_custom_text!=`${theme.footer.custom_text}`//v3.4.0以下版本可能还有ICP的配置项。此处只要保证p和上方的if缩进平级就好。
    +   p#ghbdages
    +     if theme.ghbdage.enable
    +       each item in theme.ghbdage.bdageitem
    +         a.github-badge(target='_blank' href=url_for(item.link)  style='margin-inline:5px')
    +           img(src=url_for(item.shields) title=item.massage)
    
  2. [Blogroot]\_config.butterfly.yml中添加相关配置项:

    YML
    ghbdage:enable: truebdageitem:- link: https://hexo.io/  # 标签跳转链接shields: https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo #shields的API链接,填法参考本篇教程message: 博客框架为Hexo_v5.3.0 #鼠标悬停时显示的信息- link: https://butterfly.js.org/shields: https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefendermessage: 主题版本Butterfly_v3.4.2- link: https://www.jsdelivr.com/shields: https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivrmessage: 本站使用JsDelivr为静态资源提供CDN加速- link: https://vercel.com/shields: https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&logo=Vercelmessage: 本站采用双线部署,默认线路托管于Vercel- link: https://vercel.com/shields: https://img.shields.io/badge/Hosted-Coding-0cedbe?style=flat&logo=Codiomessage: 本站采用双线部署,联通线路托管于Coding- link: https://github.com/shields: https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHubmessage: 本站项目由Gtihub托管- link: http://creativecommons.org/licenses/by-nc-sa/4.0/shields: https://img.shields.io/badge/Copyright-BY--NC--SA%204.0-d42328?style=flat&logo=Clarismessage: 本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可
    

外挂标签

考虑到对 shields.io 的全部参数支持,外挂标签使用 object 标签来引用。

  1. 新建[Blogroot]\themes\butterfly\scripts\tag\ghbdage.js

    function bdage (args) {args = args.join(' ').split('||')let base= args[0]?args[0].split(','):''let right = base[0]?encodeURI(base[0].trim()):''let left = base[1]?encodeURI(base[1].trim()):''let logo = base[2]?base[2].trim():''let message = args[1]?args[1].split(','):''let color = message[0]?message[0].trim():'orange'let link = message[1]?message[1].trim():''let title = message[2]?message[2].trim():''let option = args[2]?args[2].trim():''return `<object title="${title}" standby="loading..." data="https://img.shields.io/badge/${left}-${right}-orange?logo=${logo}&color=${color}&link=${link}&${option}"></object>`
    }
    hexo.extend.tag.register('bdage',bdage);
    

具体用法

标签用法

{% bdage [right],[left],[logo]||[color],[link],[title]||[option] %}

配置参数

left:徽标左边的信息,必选参数。
right: 徽标右边的信息,必选参数,
logo:徽标图标,图标名称详见simpleicons,可选参数。
color:徽标右边的颜色,可选参数。
link:指向的链接,可选参数。
title:徽标的额外信息,可选参数。主要用于优化 SEO,但object标签不会像a标签一样在鼠标悬停显示title信息。
option:自定义参数,支持shields.io的全部 API 参数支持,具体参数可以参看上文中的拓展写法示例。形式为name1=value2&name2=value2

样式预览

在这里插入图片描述

示例源码

本外挂标签的参数分为三组,用 || 分割。

1.基本参数,定义徽标左右文字和图标

{% bdage Theme,Butterfly %}
{% bdage Frame,Hexo,hexo %}

2.信息参数,定义徽标右侧内容背景色,指向链接

{% bdage CDN,JsDelivr,jsDelivr||abcdef,https://www.jsdelivr.com/,本站使用JsDelivr为静态资源提供CDN加速 %}
//如果是跨顺序省略可选参数,仍然需要写个逗号,用作分割
{% bdage Source,GitHub,GitHub||,https://github.com/ %}

3.拓展参数,支持 shields 的 API 的全部参数内容

{% bdage Hosted,Vercel,Vercel||brightgreen,https://vercel.com/,本站采用双线部署,默认线路托管于Vercel||style=social&logoWidth=20 %}
//如果是跨顺序省略可选参数组,仍然需要写双竖线||用作分割
{% bdage Hosted,Vercel,Vercel||||style=social&logoWidth=20&logoColor=violet %}

拓展内容 - 使用纯 css 实现仿徽标样式

这一段参考自 paddylin-Butterfly 脚底自定义标签

在使用徽标时,偶尔会遇到需要在内部写入动态内容的情况,这时候再使用 shields.io 提供的标签就无法满足我们的需求了。所以就要使用 HTML 语言配合 CSS 来仿写标签。

html源码

<div class="github-badge"><a style="color:#fff" href="https://hexo.io/" target="_blank" title="由 Hexo 强力驱动"><span class="badge-subject"><!-- fa图标,也支持阿里图标 --><i class="fa fa-copyright"></i>Powered</span><span class="badge-value bg-blue">Hexo</span></a>
</div>

css样式

/*标签整体样式*/
.github-badge {margin-left: 5px;display: inline-block;border-radius: 4px;text-shadow: none;color: #fff;line-height: 15px;background-color: #abbac3;margin-bottom: 5px;font-size: 12px;
}
/* 超链接下划线隐藏 */
.github-badge a {text-decoration: none;
}
/* 标签左侧样式 */
.github-badge .badge-subject {background-color: #4d4d4d;padding: 4px 4px 4px 6px;border-top-left-radius: 4px;border-bottom-left-radius: 4px;
}
/* 标签右侧样式 */
.github-badge .badge-value {padding: 4px 6px 4px 4px;border-top-right-radius: 4px;border-bottom-right-radius: 4px;
}
/* 标签背景色,随意自定义,渐变色也可以 */
.github-badge .bg-blue {background-color: #007ec6;
}.github-badge .bg-green {background-color: #4dc820;
}.github-badge .bg-orange {background-color: orange;
}.github-badge .bg-gradient {background: linear-gradient(to right, #3ca5f6, #a86af9);
}.github-badge .bg-violet {background-color: #8833d7;
}

结语

本文来自Akilar:Add Github Badge

End


这篇关于Hexo博客技巧:添加GitHub徽标的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/380523

相关文章

MySQL 多列 IN 查询之语法、性能与实战技巧(最新整理)

《MySQL多列IN查询之语法、性能与实战技巧(最新整理)》本文详解MySQL多列IN查询,对比传统OR写法,强调其简洁高效,适合批量匹配复合键,通过联合索引、分批次优化提升性能,兼容多种数据库... 目录一、基础语法:多列 IN 的两种写法1. 直接值列表2. 子查询二、对比传统 OR 的写法三、性能分析

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Java中的雪花算法Snowflake解析与实践技巧

《Java中的雪花算法Snowflake解析与实践技巧》本文解析了雪花算法的原理、Java实现及生产实践,涵盖ID结构、位运算技巧、时钟回拨处理、WorkerId分配等关键点,并探讨了百度UidGen... 目录一、雪花算法核心原理1.1 算法起源1.2 ID结构详解1.3 核心特性二、Java实现解析2.

深度解析Python装饰器常见用法与进阶技巧

《深度解析Python装饰器常见用法与进阶技巧》Python装饰器(Decorator)是提升代码可读性与复用性的强大工具,本文将深入解析Python装饰器的原理,常见用法,进阶技巧与最佳实践,希望可... 目录装饰器的基本原理函数装饰器的常见用法带参数的装饰器类装饰器与方法装饰器装饰器的嵌套与组合进阶技巧

Go语言代码格式化的技巧分享

《Go语言代码格式化的技巧分享》在Go语言的开发过程中,代码格式化是一个看似细微却至关重要的环节,良好的代码格式化不仅能提升代码的可读性,还能促进团队协作,减少因代码风格差异引发的问题,Go在代码格式... 目录一、Go 语言代码格式化的重要性二、Go 语言代码格式化工具:gofmt 与 go fmt(一)

如何在Mac上彻底删除Edge账户? 手动卸载Edge浏览器并清理残留文件技巧

《如何在Mac上彻底删除Edge账户?手动卸载Edge浏览器并清理残留文件技巧》Mac上的Edge账户里存了不少网站密码和个人信息,结果同事一不小心打开了,简直尴尬到爆炸,想要卸载edge浏览器并清... 如果你遇到 Microsoft Edge 浏览器运行迟缓、频繁崩溃或网页加载异常等问题,可以尝试多种方

qt5cored.dll报错怎么解决? 电脑qt5cored.dll文件丢失修复技巧

《qt5cored.dll报错怎么解决?电脑qt5cored.dll文件丢失修复技巧》在进行软件安装或运行程序时,有时会遇到由于找不到qt5core.dll,无法继续执行代码,这个问题可能是由于该文... 遇到qt5cored.dll文件错误时,可能会导致基于 Qt 开发的应用程序无法正常运行或启动。这种错

mtu设置多少网速最快? 路由器MTU设置最佳网速的技巧

《mtu设置多少网速最快?路由器MTU设置最佳网速的技巧》mtu设置多少网速最快?想要通过设置路由器mtu获得最佳网速,该怎么设置呢?下面我们就来看看路由器MTU设置最佳网速的技巧... 答:1500 MTU值指的是在网络传输中数据包的最大值,合理的设置MTU 值可以让网络更快!mtu设置可以优化不同的网

MySQL JSON 查询中的对象与数组技巧及查询示例

《MySQLJSON查询中的对象与数组技巧及查询示例》MySQL中JSON对象和JSON数组查询的详细介绍及带有WHERE条件的查询示例,本文给大家介绍的非常详细,mysqljson查询示例相关知... 目录jsON 对象查询1. JSON_CONTAINS2. JSON_EXTRACT3. JSON_TA

github打不开的问题分析及解决

《github打不开的问题分析及解决》:本文主要介绍github打不开的问题分析及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、找到github.com域名解析的ip地址二、找到github.global.ssl.fastly.net网址解析的ip地址三