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

相关文章

Python通过模块化开发优化代码的技巧分享

《Python通过模块化开发优化代码的技巧分享》模块化开发就是把代码拆成一个个“零件”,该封装封装,该拆分拆分,下面小编就来和大家简单聊聊python如何用模块化开发进行代码优化吧... 目录什么是模块化开发如何拆分代码改进版:拆分成模块让模块更强大:使用 __init__.py你一定会遇到的问题模www.

Python将博客内容html导出为Markdown格式

《Python将博客内容html导出为Markdown格式》Python将博客内容html导出为Markdown格式,通过博客url地址抓取文章,分析并提取出文章标题和内容,将内容构建成html,再转... 目录一、为什么要搞?二、准备如何搞?三、说搞咱就搞!抓取文章提取内容构建html转存markdown

MyBatis 动态 SQL 优化之标签的实战与技巧(常见用法)

《MyBatis动态SQL优化之标签的实战与技巧(常见用法)》本文通过详细的示例和实际应用场景,介绍了如何有效利用这些标签来优化MyBatis配置,提升开发效率,确保SQL的高效执行和安全性,感... 目录动态SQL详解一、动态SQL的核心概念1.1 什么是动态SQL?1.2 动态SQL的优点1.3 动态S

电脑win32spl.dll文件丢失咋办? win32spl.dll丢失无法连接打印机修复技巧

《电脑win32spl.dll文件丢失咋办?win32spl.dll丢失无法连接打印机修复技巧》电脑突然提示win32spl.dll文件丢失,打印机死活连不上,今天就来给大家详细讲解一下这个问题的解... 不知道大家在使用电脑的时候是否遇到过关于win32spl.dll文件丢失的问题,win32spl.dl

电脑报错cxcore100.dll丢失怎么办? 多种免费修复缺失的cxcore100.dll文件的技巧

《电脑报错cxcore100.dll丢失怎么办?多种免费修复缺失的cxcore100.dll文件的技巧》你是否也遇到过“由于找不到cxcore100.dll,无法继续执行代码,重新安装程序可能会解... 当电脑报错“cxcore100.dll未找到”时,这通常意味着系统无法找到或加载这编程个必要的动态链接库

如何关闭 Mac 触发角功能或设置修饰键? mac电脑防止误触设置技巧

《如何关闭Mac触发角功能或设置修饰键?mac电脑防止误触设置技巧》从Windows换到iOS大半年来,触发角是我觉得值得吹爆的MacBook效率神器,成为一大说服理由,下面我们就来看看mac电... MAC 的「触发角」功能虽然提高了效率,但过于灵敏也让不少用户感到头疼。特别是在关键时刻,一不小心就可能触

前端bug调试的方法技巧及常见错误

《前端bug调试的方法技巧及常见错误》:本文主要介绍编程中常见的报错和Bug,以及调试的重要性,调试的基本流程是通过缩小范围来定位问题,并给出了推测法、删除代码法、console调试和debugg... 目录调试基本流程调试方法排查bug的两大技巧如何看控制台报错前端常见错误取值调用报错资源引入错误解析错误

mysql线上查询之前要性能调优的技巧及示例

《mysql线上查询之前要性能调优的技巧及示例》文章介绍了查询优化的几种方法,包括使用索引、避免不必要的列和行、有效的JOIN策略、子查询和派生表的优化、查询提示和优化器提示等,这些方法可以帮助提高数... 目录避免不必要的列和行使用有效的JOIN策略使用子查询和派生表时要小心使用查询提示和优化器提示其他常

Apache伪静态(Rewrite).htaccess文件详解与配置技巧

《Apache伪静态(Rewrite).htaccess文件详解与配置技巧》Apache伪静态(Rewrite).htaccess是一个纯文本文件,它里面存放着Apache服务器配置相关的指令,主要的... 一、.htAccess的基本作用.htaccess是一个纯文本文件,它里面存放着Apache服务器

Spring中@Lazy注解的使用技巧与实例解析

《Spring中@Lazy注解的使用技巧与实例解析》@Lazy注解在Spring框架中用于延迟Bean的初始化,优化应用启动性能,它不仅适用于@Bean和@Component,还可以用于注入点,通过将... 目录一、@Lazy注解的作用(一)延迟Bean的初始化(二)与@Autowired结合使用二、实例解