From 5245e4a90d6e4bb59f1471c8cef522a821d0db65 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Fri, 29 Oct 2021 00:25:42 +0530 Subject: [PATCH] Optimize rendering webmaster verifications --- lib/jekyll-seo-tag.rb | 1 + lib/jekyll-seo-tag/drop.rb | 4 ++++ lib/jekyll-seo-tag/webmaster.rb | 27 +++++++++++++++++++++++++++ lib/template.html | 24 +----------------------- 4 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 lib/jekyll-seo-tag/webmaster.rb diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index 2edafd7d..f76fe216 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -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 diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 157babd4..87177e7f 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -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) diff --git a/lib/jekyll-seo-tag/webmaster.rb b/lib/jekyll-seo-tag/webmaster.rb new file mode 100644 index 00000000..7b2578f0 --- /dev/null +++ b/lib/jekyll-seo-tag/webmaster.rb @@ -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| + %() if META_KEYS.include?(key) + end.join("\n") + end + end + private_constant :Webmaster + end +end diff --git a/lib/template.html b/lib/template.html index 8bc25d5a..fbe30880 100755 --- a/lib/template.html +++ b/lib/template.html @@ -88,29 +88,7 @@ {% endif %} {% if site.webmaster_verifications %} - {% if site.webmaster_verifications.google %} - - {% endif %} - - {% if site.webmaster_verifications.bing %} - - {% endif %} - - {% if site.webmaster_verifications.alexa %} - - {% endif %} - - {% if site.webmaster_verifications.yandex %} - - {% endif %} - - {% if site.webmaster_verifications.baidu %} - - {% endif %} - - {% if site.webmaster_verifications.facebook %} - - {% endif %} + {{ seo_tag.webmaster_verifications }} {% elsif site.google_site_verification %} {% endif %}