天天看點

Add Github Badgegithub徽标具體步驟插件化寫法外挂标簽拓展内容-使用純css實作仿徽标樣式

github徽标

  1. github徽标可以直接通過shields.io線上生成。
  2. 理論上可以放在頁面的任何地方。教程案例是添加在頁腳。
  3. 工具網站包括:
    • 徽标生成網站:shields
    • 圖示查詢網站:simpleicons
    • html壓縮網站:htmlpack
    • 轉義字元查詢預覽效果

具體步驟

通過shields.io線上生成。

輸入相關資訊後,點選

make badge

即可得到徽标的URL。可以用img标簽引用,寫法簡單。不過正式寫法建議用object标簽引用,寫法示例如下。

拓展寫法示例

[Blogroot]\_config.butterfly.yml

footer

配置項中添加徽标,注意事先壓縮一下,使他們隻留一行。為了不至于太過緊湊,設定一下行内間隔屬性

margin-inline

插件化寫法

修改

[Blogroot]\themes\butterfly\layout\includes\footer.pug

,添加頁腳标簽循環節:

[Blogroot]\_config.butterfly.yml

中添加相關配置項:

外挂标簽

考慮到對shields.io的全部參數支援,外挂标簽使用

object

标簽來引用。

建立

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);           

複制

具體用法

拓展内容-使用純css實作仿徽标樣式

這一段參考自paddylin-Butterfly腳底自定義标簽

在使用徽标時,偶爾會遇到需要在内部寫入動态内容的情況,這時候再使用shields.io提供的标簽就無法滿足我們的需求了。是以就要使用

HTML

語言配合

CSS

來仿寫标簽。

  • html源碼
  • css樣式
  • 标簽預覽
<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>           

複制

/*标簽整體樣式*/
.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;
}           

複制

Powered Hexo