且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何动态检查远程字体图标是否存在?

更新时间:2023-11-25 23:40:10

因此,我实际执行此操作的唯一方法是分析Devicons提供的图标列表。

所以我在帮助器方法的数组中手动创建了一个列表,然后在其中执行了nil检查。

所以看起来是这样的:

  def language_icon(language)
    devicons = ["amazonwebservices", "android", "angularjs", "apache", "appcelerator", "apple", "atom", "backbonejs",
      "bitbucket", "bootstrap", "bower", "c", "chrome", "codeigniter", "coffeescript", "confluence", "cplusplus", "csharp",
      "css3", "d3js", "debian", "django", "docker", "doctrine", "dot-net", "drupal", "erlang", "firefox", "foundation", "gimp",
      "git", "github", "gitlab", "go", "grunt", "gulp", "heroku", "html5", "ie10", "illustrator", "inkscape", "java", "javascript",
      "jeet", "jetbrains", "jquery", "krakenjs", "laravel", "less", "linux", "meteor", "mongodb", "moodle", "mysql", "nginx",
      "nodejs", "nodewebkit", "orale", "photoshop", "php", "phpstorm", "postgresql", "python", "rails", "react", "redhat", "redis",
      "ruby", "safari", "sass", "sourcetree", "ssh", "symfony", "travis", "trello", "ubuntu", "vim", "windows8", "wordpress", "yii", "zend"]

    if devicons.include?(language)
      content_tag(:i, "", class: "devicon-#{language}-plain")
    else
      content_tag(:i, "", class: "fa fa-diamond")
    end
  end

这就像一个护身符。

我希望这对其他人有帮助!