Add schema.org markup to SEO-enabled posts (#36075)

This commit is contained in:
Eugen Rochko
2025-09-12 11:12:07 +02:00
committed by GitHub
parent b59e06fba7
commit 30b31a89e6
6 changed files with 194 additions and 0 deletions

16
app/lib/seo/adapter.rb Normal file
View File

@@ -0,0 +1,16 @@
# frozen_string_literal: true
class SEO::Adapter < ActiveModelSerializers::Adapter::Base
def self.default_key_transform
:camel_lower
end
def self.transform_key_casing!(value, _options)
SEO::CaseTransform.camel_lower(value)
end
def serializable_hash(options = nil)
serialized_hash = serializer.serializable_hash(serialization_options(options))
self.class.transform_key_casing!(serialized_hash, instance_options)
end
end

View File

@@ -0,0 +1,36 @@
# frozen_string_literal: true
module SEO::CaseTransform
PREFIX_KEYS = %w(
context
id
type
).freeze
class << self
def camel_lower_cache
@camel_lower_cache ||= {}
end
def camel_lower(value)
case value
when Array
value.map { |item| camel_lower(item) }
when Hash
value.deep_transform_keys! { |key| camel_lower(key) }
when Symbol
camel_lower(value.to_s).to_sym
when String
camel_lower_cache[value] ||= begin
if PREFIX_KEYS.include?(value.to_s)
"@#{value}"
else
value.underscore.camelize(:lower)
end
end
else
value
end
end
end
end