Module: BiteMediaSeo::LocalSeoSchema
- Defined in:
- lib/bitemediaseo/local_seo_schema.rb,
lib/bitemediaseo/local_seo_schema/version.rb
Constant Summary collapse
- DEFAULT_TYPE =
"ProfessionalService"- ALLOWED_LOCAL_TYPES =
%w[ LocalBusiness Organization ProfessionalService Store ].freeze
- VERSION =
"1.0.0"
Class Method Summary collapse
- .create_local_business(options) ⇒ Object
- .create_service(options) ⇒ Object
- .for_bitemediaseo ⇒ Object
- .script_tag(schema) ⇒ Object
- .to_json_ld(schema, pretty: false) ⇒ Object
Class Method Details
.create_local_business(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bitemediaseo/local_seo_schema.rb', line 19 def create_local_business() validate_hash!(, "options") type = optional_text([:type] || ["type"], "type") || DEFAULT_TYPE unless ALLOWED_LOCAL_TYPES.include?(type) raise ArgumentError, "Unsupported Schema.org type: #{type}" end compact_hash( "@context" => "https://schema.org", "@type" => type, "name" => require_text([:name] || ["name"], "name"), "url" => validate_url([:url] || ["url"], "url"), "description" => optional_text([:description] || ["description"], "description"), "telephone" => optional_text([:telephone] || ["telephone"], "telephone"), "priceRange" => optional_text([:price_range] || [:priceRange] || ["priceRange"], "priceRange"), "areaServed" => optional_text([:area_served] || [:areaServed] || ["areaServed"], "areaServed"), "address" => postal_address([:address] || ["address"]), "geo" => geo_coordinates([:geo] || ["geo"]), "sameAs" => same_as([:same_as] || [:sameAs] || ["sameAs"]) ) end |
.create_service(options) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bitemediaseo/local_seo_schema.rb', line 42 def create_service() validate_hash!(, "options") provider = [:provider] || ["provider"] provider = create_local_business(provider) if provider.is_a?(Hash) compact_hash( "@context" => "https://schema.org", "@type" => "Service", "name" => require_text([:name] || ["name"], "name"), "url" => validate_url([:url] || ["url"], "url"), "description" => optional_text([:description] || ["description"], "description"), "serviceType" => optional_text([:service_type] || [:serviceType] || ["serviceType"], "serviceType"), "areaServed" => optional_text([:area_served] || [:areaServed] || ["areaServed"], "areaServed"), "provider" => provider ) end |
.for_bitemediaseo ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/bitemediaseo/local_seo_schema.rb', line 60 def for_bitemediaseo create_service( name: "Pozycjonowanie stron Szczecin - BiteMediaSEO", url: "https://bitemediaseo.pl/", description: "Pozycjonowanie stron w Szczecinie: SEO lokalne, AI/GEO, audyty i transparentne raporty.", service_type: "Pozycjonowanie stron internetowych", area_served: "Szczecin, Polska", provider: { name: "BiteMediaSEO", url: "https://bitemediaseo.pl/", type: "ProfessionalService", description: "Agencja SEO wspierajaca widocznosc firm w Google, mapach i odpowiedziach AI.", area_served: "Szczecin, Polska", address: { addressLocality: "Szczecin", addressCountry: "PL" } } ) end |
.script_tag(schema) ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'lib/bitemediaseo/local_seo_schema.rb', line 86 def script_tag(schema) json = to_json_ld(schema) safe_json = json .gsub("<", "\\u003c") .gsub(">", "\\u003e") .gsub("&", "\\u0026") %(<script type="application/ld+json">#{safe_json}</script>) end |
.to_json_ld(schema, pretty: false) ⇒ Object
81 82 83 84 |
# File 'lib/bitemediaseo/local_seo_schema.rb', line 81 def to_json_ld(schema, pretty: false) validate_hash!(schema, "schema") pretty ? JSON.pretty_generate(schema) : JSON.generate(schema) end |