代码之家  ›  专栏  ›  技术社区  ›  Nikolas Charalambidis

定制GitHub动态颜色徽章

  •  1
  • Nikolas Charalambidis  · 技术社区  · 6 年前

    shields.io

    我能够使用JSON响应将文本解析为 badge 并将颜色设置为橙色:

    https://img.shields.io/badge/dynamic/json.svg?label=custom&url=https://jsonplaceholder.typicode.com/posts&query=$[1].id&colorB=orange
    

    enter image description here

    效果很好。。。


    但是,我想根据规则改变颜色。我可能会返回JSON中的十六进制颜色,以便解析到徽章中。我试过公众 API 得到一个随机的颜色和 测试

    http://www.colr.org/json/color/random
    

    $.colors[0].hex 并将其作为动态值和颜色放置到徽章URL中:

    https://img.shields.io/badge/dynamic/json.svg?label=custom&url=http://www.colr.org/json/color/random&query=$.colors[0].hex&colorB=$.colors[0].hex
    

    不管随机选择的颜色是什么,结果总是绿色的(最后生成的结果是绿色的) #D0BB79 :

    enter image description here

    我希望这样的东西能与 #D0BB79

    enter image description here

    Coveralls.io , Codecov.io SonarCloud.io .

    0 回复  |  直到 6 年前
        1
  •  1
  •   JGC    5 年前

    anybadge 它以阈值作为参数。这允许您在一个命令中生成具有动态颜色的徽章:

    anybadge -l pylint -v 2.22 -f pylint.svg 2=red 4=orange 8=yellow 10=green
    

    颜色可以通过十六进制颜色代码或预定义的一组颜色名称来定义。

    README.md .