Class: BetterSeo::Generators::AmpGenerator
- Inherits:
-
Object
- Object
- BetterSeo::Generators::AmpGenerator
- Defined in:
- lib/better_seo/generators/amp_generator.rb
Instance Attribute Summary collapse
-
#canonical_url ⇒ Object
Returns the value of attribute canonical_url.
-
#description ⇒ Object
Returns the value of attribute description.
-
#image ⇒ Object
Returns the value of attribute image.
-
#structured_data ⇒ Object
Returns the value of attribute structured_data.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(canonical_url: nil, title: nil, description: nil, image: nil, structured_data: nil) ⇒ AmpGenerator
constructor
A new instance of AmpGenerator.
-
#to_amp_script_tag ⇒ Object
Generate AMP runtime script tag.
-
#to_boilerplate ⇒ Object
Generate AMP boilerplate CSS.
-
#to_custom_css(css) ⇒ Object
Wrap custom CSS in amp-custom style tag.
-
#to_meta_tags ⇒ Object
Generate meta tags for AMP page.
-
#to_structured_data ⇒ Object
Generate structured data script tag.
Constructor Details
#initialize(canonical_url: nil, title: nil, description: nil, image: nil, structured_data: nil) ⇒ AmpGenerator
Returns a new instance of AmpGenerator.
10 11 12 13 14 15 16 |
# File 'lib/better_seo/generators/amp_generator.rb', line 10 def initialize(canonical_url: nil, title: nil, description: nil, image: nil, structured_data: nil) @canonical_url = canonical_url @title = title @description = description @image = image @structured_data = structured_data end |
Instance Attribute Details
#canonical_url ⇒ Object
Returns the value of attribute canonical_url.
8 9 10 |
# File 'lib/better_seo/generators/amp_generator.rb', line 8 def canonical_url @canonical_url end |
#description ⇒ Object
Returns the value of attribute description.
8 9 10 |
# File 'lib/better_seo/generators/amp_generator.rb', line 8 def description @description end |
#image ⇒ Object
Returns the value of attribute image.
8 9 10 |
# File 'lib/better_seo/generators/amp_generator.rb', line 8 def image @image end |
#structured_data ⇒ Object
Returns the value of attribute structured_data.
8 9 10 |
# File 'lib/better_seo/generators/amp_generator.rb', line 8 def structured_data @structured_data end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/better_seo/generators/amp_generator.rb', line 8 def title @title end |
Instance Method Details
#to_amp_script_tag ⇒ Object
Generate AMP runtime script tag
27 28 29 |
# File 'lib/better_seo/generators/amp_generator.rb', line 27 def to_amp_script_tag '<script async src="https://cdn.ampproject.org/v0.js"></script>' end |
#to_boilerplate ⇒ Object
Generate AMP boilerplate CSS
19 20 21 22 23 24 |
# File 'lib/better_seo/generators/amp_generator.rb', line 19 def to_boilerplate boilerplate = <<~HTML <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript> HTML boilerplate.strip end |
#to_custom_css(css) ⇒ Object
Wrap custom CSS in amp-custom style tag
57 58 59 60 61 |
# File 'lib/better_seo/generators/amp_generator.rb', line 57 def to_custom_css(css) return "" if css.nil? || css.empty? %(<style amp-custom>\n#{css}\n</style>) end |
#to_meta_tags ⇒ Object
Generate meta tags for AMP page
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/better_seo/generators/amp_generator.rb', line 32 def = [] << %(<link rel="canonical" href="#{escape_html(@canonical_url)}">) if @canonical_url << %(<meta property="og:title" content="#{escape_html(@title)}">) if @title if @description << %(<meta name="description" content="#{escape_html(@description)}">) << %(<meta property="og:description" content="#{escape_html(@description)}">) end << %(<meta property="og:image" content="#{escape_html(@image)}">) if @image .join("\n") end |
#to_structured_data ⇒ Object
Generate structured data script tag
50 51 52 53 54 |
# File 'lib/better_seo/generators/amp_generator.rb', line 50 def to_structured_data return "" unless @structured_data %(<script type="application/ld+json">\n#{JSON.generate(@structured_data)}\n</script>) end |