Module: MetaHelper
- Defined in:
- app/helpers/meta_helper.rb
Instance Method Summary collapse
- #build_title(*args) ⇒ Object
-
#downgrade_h1_tags(html) ⇒ Object
Converts any tags in rich-text HTML to to prevent multiple H1s when the template already defines one.
-
#effective_page_tag ⇒ Object
Returns the effective page tag: override if set, otherwise @main_tag from controller.
- #og_image_asset_url(image_id, options = {}) ⇒ Object
- #page_author(author) ⇒ Object
- #page_description(description) ⇒ Object
- #page_keywords(keywords) ⇒ Object
- #page_og_image(image_id_or_image) ⇒ Object
- #page_robot_directive(directive) ⇒ Object
-
#page_tag(page_path) ⇒ Object
Overrides the automatic page tag (set by PagesController) with a custom value.
- #page_title(*args) ⇒ Object
- #set_metas(title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS) ⇒ Object
- #swiftype_robot_exclude ⇒ Object
- #swiftype_type(type) ⇒ Object
Instance Method Details
#build_title(*args) ⇒ Object
79 80 81 82 |
# File 'app/helpers/meta_helper.rb', line 79 def build_title(*args) links = args.compact.uniq page_title links.join(' > ') end |
#downgrade_h1_tags(html) ⇒ Object
Converts any tags in rich-text HTML to to prevent
multiple H1s when the template already defines one.
86 87 88 89 90 |
# File 'app/helpers/meta_helper.rb', line 86 def (html) return html unless html.present? html.gsub(%r{<(/?)h1(\s|>)}i) { "<#{$1}h2#{$2}" } end |
#effective_page_tag ⇒ Object
Returns the effective page tag: override if set, otherwise @main_tag from controller
61 62 63 |
# File 'app/helpers/meta_helper.rb', line 61 def effective_page_tag @page_tag_override || @main_tag end |
#og_image_asset_url(image_id, options = {}) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/meta_helper.rb', line 92 def og_image_asset_url(image_id, = {}) = { format: :jpeg, background: 'ffffff', width: SOCIAL_IMAGE_WIDTH, height: SOCIAL_IMAGE_HEIGHT, crop_mode: 'cm-extract', thumbnail: true }.merge() image_asset_url(image_id, **) end |
#page_author(author) ⇒ Object
12 13 14 |
# File 'app/helpers/meta_helper.rb', line 12 def () content_for(:author) { } end |
#page_description(description) ⇒ Object
6 7 8 9 10 |
# File 'app/helpers/meta_helper.rb', line 6 def page_description(description) return unless description.present? content_for(:description) { description.truncate(375, separator: /[\s\|]/, omission: '') } end |
#page_keywords(keywords) ⇒ Object
2 3 4 |
# File 'app/helpers/meta_helper.rb', line 2 def page_keywords(keywords) content_for(:keywords) { keywords } end |
#page_og_image(image_id_or_image) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/meta_helper.rb', line 37 def page_og_image(image_id_or_image) return if @og_image_set return unless image_id_or_image.present? image_asset_url = og_image_asset_url(image_id_or_image) || DEFAULT_SOCIAL_ICON content_for(:og_image) { image_asset_url } @og_image_set = true nil end |
#page_robot_directive(directive) ⇒ Object
65 66 67 68 69 |
# File 'app/helpers/meta_helper.rb', line 65 def page_robot_directive(directive) return unless directive.present? content_for(:robots_directive) { directive } end |
#page_tag(page_path) ⇒ Object
Overrides the automatic page tag (set by PagesController) with a custom value.
Only needed when the page tag should differ from the URL-based default.
Usage: page_tag('custom/path') outputs: for-custom-path-page
51 52 53 54 55 56 57 58 |
# File 'app/helpers/meta_helper.rb', line 51 def page_tag(page_path) return if @page_tag_override_set return unless page_path.present? @page_tag_override = DigitalAsset.page_tag_for(page_path) @page_tag_override_set = true nil end |
#page_title(*args) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/meta_helper.rb', line 26 def page_title(*args) page_title = [args].flatten.map(&:to_s).map(&:presence).compact.uniq.join(' | ') return unless page_title.present? # Check the length of our page_title, if not too long and no WarmlyYours present in the name, add the company locale add_title_info = " | #{company_locale}" page_title << add_title_info if (page_title.size + add_title_info.size) <= 60 && !page_title.match?(/WarmlyYours/i) @page_title = page_title content_for(:title) { page_title } end |
#set_metas(title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'app/helpers/meta_helper.rb', line 16 def ( title: DEFAULT_PAGE_TITLE, description: DEFAULT_PAGE_TITLE, keywords: DEFAULT_PAGE_KEYWORDS ) page_title title page_description description page_keywords keywords end |
#swiftype_robot_exclude ⇒ Object
75 76 77 |
# File 'app/helpers/meta_helper.rb', line 75 def swiftype_robot_exclude content_for(:swiftype_robot) { 'noindex, nofollow' } end |
#swiftype_type(type) ⇒ Object
71 72 73 |
# File 'app/helpers/meta_helper.rb', line 71 def swiftype_type(type) content_for(:swiftype_type) { type } end |