github徽标

  • github徽标可以直接通过shields.io在线生成。
  • 理论上可以放在页面的任何地方。教程案例是添加在页脚。
  • 工具网站包括:
    1. 徽标生成网站:shields.io
    2. 图标查询网站:simpleicons
    3. html压缩网站:htmlpack

预览结果展示:

image

具体实现步骤:(简单实现)

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

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

    <!-- 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>
  3. 拓展写法示例

    • 属性说明
    • 仅仅如此肯定是不能令人满意的,还可以继续添加样式。shields.io提供直接在URL内添加样式属性的功能。使用?引用,使用&连接各属性。
属性 说明 示例
style 徽标样式,默认提供了五种样式: plastic,flat,flat-square, for-the-badge,social ?style=flat-square
label 覆盖默认的左侧文本 (空格或特殊字符需要转 URL 编码!) ?label=healthinesses
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>
  • 样式预览
    image
  1. 在主题配置文件_config.ymlfooter配置项中添加徽标,注意事先压缩一下,使他们只留一行。为了不至于太过紧凑,用 (空格的转义字符)隔开。
    # Footer Settings
    # --------------------------------------
    footer:
    owner:
    enable: true
    since: 2022
    # 设置页脚徽标
    custom_text: <div>🦸‍♂️目在当下,活在当下</div>
    <div>🦾成为自己想成为的人!</div>
    <p><a target="_blank" href="https://hexo.io/"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo"></a>&nbsp;<a target="_blank" href="https://demo.jerryc.me/"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用butterfly"></a>&nbsp;<a target="_blank" href="https://github.com/ "><img src="https://img.shields.io/badge/CDN-Github%26SM.MS-brightgreen?style=flat&logo=Shelly" title="本站使用github和sm.ms为静态资源提供CDN加速"></a> &nbsp;</a>&nbsp;<a target="_blank" href="https://github.com/"><img src="https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHub" title="本站项目由Gtihub托管"></a>&nbsp;<a 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: true # Copyright of theme and framework

插件化写法(较上复杂)

  1. 修改BlogRoot/node_modules/hexo-theme-butterfly/layout/includes/footer.pug,添加页脚标签循环节:
        if 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. 在主题配置文件_config.butterfly.yml中添加相关配置项:
    ghbdage:
    enable: true
    bdageitem:
    - 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://demo.jerryc.me/
    shields: https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender
    message: 主题版本Butterfly_v3.4.2
    - link: https://metroui.org.ua/index.html
    shields: https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr
    message: 本站使用JsDelivr为静态资源提供CDN加速
    - link: https://vercel.com/
    shields: https://img.shields.io/badge/Hosted-Vervel-brightgreen?style=flat&logo=Vercel
    message: 本站采用双线部署,默认线路托管于Vercel
    - link: https://vercel.com/
    shields: https://img.shields.io/badge/Hosted-Coding-0cedbe?style=flat&logo=Codio
    message: 本站采用双线部署,联通线路托管于Coding
    - link: https://github.com/
    shields: https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHub
    message: 本站项目由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=Claris
    message: 本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可

重点(目前博客在用)

  • 我们也可以调用组件来实现这些功能(页脚添加github徽标以及网页运行时间)
  • 安装插件,在博客根目录[Blogroot]下打开终端,运行以下指令:
    npm install hexo-butterfly-footer-beautify --save
  • 添加配置信息,以下为写法示例:
    • 在站点配置文件_config.yml或者主题配置文件_config.butterfly.yml中添加
      # footer_beautify
      # 页脚计时器:[Native JS Timer](https://akilar.top/posts/b941af/)
      # 页脚徽标:[Add Github Badge](https://akilar.top/posts/e87ad7f8/)
      footer_beautify:
      enable:
      timer: true # 计时器开关
      bdage: true # 徽标开关
      priority: 5 #过滤器优先权
      enable_page: all # 应用页面
      exclude: #屏蔽页面
      # - /posts/
      # - /about/
      layout: # 挂载容器类型
      type: id
      name: footer-wrap
      index: 0
      # 计时器部分配置项
      runtime_js: https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.js
      runtime_css: https://npm.elemecdn.com/hexo-butterfly-footer-beautify@1.0.0/lib/runtime.css
      # 徽标部分配置项
      swiperpara: 3 #若非0,则开启轮播功能,每行徽标个数
      bdageitem:
      - link: https://hexo.io/ #徽标指向网站链接
      shields: https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo #徽标API
      message: 博客框架为Hexo_v5.4.0 #徽标提示语
      - link: https://butterfly.js.org/
      shields: https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender
      message: 主题版本Butterfly_v3.8.2
      - link: https://www.jsdelivr.com/
      shields: https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr
      message: 本站使用JsDelivr为静态资源提供CDN加速
      - link: https://vercel.com/
      shields: https://img.shields.io/badge/Hosted-Vercel-brightgreen?style=flat&logo=Vercel
      message: 本站采用双线部署,默认线路托管于Vercel
      - link: https://vercel.com/
      shields: https://img.shields.io/badge/Hosted-Coding-0cedbe?style=flat&logo=Codio
      message: 本站采用双线部署,联通线路托管于Coding
      - link: https://github.com/
      shields: https://img.shields.io/badge/Source-Github-d021d6?style=flat&logo=GitHub
      message: 本站项目由Github托管
      - 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=Claris
      message: 本站采用知识共享署名-非商业性使用-相同方式共享4.0国际许可协议进行许可
      swiper_css: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.css
      swiper_js: https://npm.elemecdn.com/hexo-butterfly-swiper/lib/swiper.min.js
      swiperbdage_init_js: https://npm.elemecdn.com/hexo-butterfly-footer-beautify/lib/swiperbdage_init.min.js

当然,这里的外部js和css的引用也可以下载下来,然后再放到博客的根目录下主题文件夹里面的source文件夹里面的内置css文件夹中,然后再本地相对链接中调用即可

参数释义:

参数 备选值/类型 释义
priority number 【可选】过滤器优先级,数值越小,执行越早,默认为10,选填
enable.timer true/false 【必选】计时器控制开关
enable.bdage true/false 【必选】徽标控制开关
enable_page path 【可选】填写想要应用的页面,如根目录就填’/‘,分类页面就填’/categories/‘。若要应用于所有页面,就填all,默认为all
exclude path 【可选】填写想要屏蔽的页面,可以多个。仅当enable_page为’all’时生效。写法见示例。原理是将屏蔽项的内容逐个放到当前路径去匹配,若当前路径包含任一屏蔽项,则不会挂载。
layout.type id/class 【可选】挂载容器类型,填写id或class,不填则默认为id
layout.name text 【必选】挂载容器名称
layout.index 0和正整数 【可选】前提是layout.type为class,因为同一页面可能有多个class,此项用来确认究竟排在第几个顺位
runtime_js url 【必选】页脚计时器脚本,可以下载上文填写示例的链接,参照注释和教程:Native JS Timer自行修改。
runtime_css url 【可选】自定义样式,预留开发者接口,可自行下载。
swiperpara number 【可选】若非零,则开启轮播功能,此项表示每行最多容纳徽标个数,用来应对徽标过多显得页脚拥挤的问题
bdageitem.link url 【可选】页脚徽标指向的网站链接
bdageitem.shields url 【必选】页脚徽标对应的API,API具体写法示例参照教程Add Github Badge
bdageitem.message text 【可选】页脚徽标悬停时显示的信息
swiper_css url 【可选】swiper的依赖
swiper_js url 【可选】swiper的依赖
swiperbdage_init_js url 【可选】swiper初始化方法

这篇博客引用了作者为”唐志远和akilar“的文章
原文链接为:唐志远の博客,akilar的糖果屋