Optimize rendering webmaster verifications

This commit is contained in:
Ashwin Maroli 2021-10-29 00:25:42 +05:30
parent 41b23937a9
commit 5245e4a90d
4 changed files with 33 additions and 23 deletions

View File

@ -12,6 +12,7 @@ module Jekyll
autoload :UrlHelper, "jekyll-seo-tag/url_helper"
autoload :Drop, "jekyll-seo-tag/drop"
autoload :Filters, "jekyll-seo-tag/filters"
autoload :Webmaster, "jekyll-seo-tag/webmaster"
attr_accessor :context

View File

@ -73,6 +73,10 @@ module Jekyll
end
# rubocop:enable Metrics/CyclomaticComplexity
def webmaster_verifications
Webmaster.render(site["webmaster_verifications"])
end
def name
return @name if defined?(@name)

View File

@ -0,0 +1,27 @@
# frozen_string_literal: true
module Jekyll
class SeoTag
class Webmaster
META_MAP = {
"alexa" => "alexaVerifyID",
"baidu" => "baidu-site-verification",
"bing" => "msvalidate.01",
"facebook" => "facebook-domain-verification",
"google" => "google-site-verification",
"yandex" => "yandex-verification",
}.freeze
META_KEYS = Set.new(META_MAP.keys).freeze
private_constant :META_MAP, :META_KEYS
def self.render(data)
return unless data.is_a?(Hash)
@render ||= data.map do |key, value|
%(<meta name="#{META_MAP[key]}" content="#{value}" />) if META_KEYS.include?(key)
end.join("\n")
end
end
private_constant :Webmaster
end
end

View File

@ -88,29 +88,7 @@
{% endif %}
{% if site.webmaster_verifications %}
{% if site.webmaster_verifications.google %}
<meta name="google-site-verification" content="{{ site.webmaster_verifications.google }}" />
{% endif %}
{% if site.webmaster_verifications.bing %}
<meta name="msvalidate.01" content="{{ site.webmaster_verifications.bing }}" />
{% endif %}
{% if site.webmaster_verifications.alexa %}
<meta name="alexaVerifyID" content="{{ site.webmaster_verifications.alexa }}" />
{% endif %}
{% if site.webmaster_verifications.yandex %}
<meta name="yandex-verification" content="{{ site.webmaster_verifications.yandex }}" />
{% endif %}
{% if site.webmaster_verifications.baidu %}
<meta name="baidu-site-verification" content="{{ site.webmaster_verifications.baidu }}" />
{% endif %}
{% if site.webmaster_verifications.facebook %}
<meta name="facebook-domain-verification" content="{{ site.webmaster_verifications.facebook }}" />
{% endif %}
{{ seo_tag.webmaster_verifications }}
{% elsif site.google_site_verification %}
<meta name="google-site-verification" content="{{ site.google_site_verification }}" />
{% endif %}