Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize rendering webmaster verifications #456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/jekyll-seo-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class SeoTag < Liquid::Tag
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

Expand Down
4 changes: 4 additions & 0 deletions lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def title
end
# rubocop:enable Metrics/CyclomaticComplexity

def webmaster_verifications
Webmaster.render(site["webmaster_verifications"])
end

def name
return @name if defined?(@name)

Expand Down
27 changes: 27 additions & 0 deletions lib/jekyll-seo-tag/webmaster.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 1 addition & 23 deletions lib/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down