Skip to content

Instantly share code, notes, and snippets.

@schadenfred
Created March 24, 2025 18:20
Show Gist options
  • Save schadenfred/dd2b2f56f7c4ca6fcc81b2dd8c015c2e to your computer and use it in GitHub Desktop.
Save schadenfred/dd2b2f56f7c4ca6fcc81b2dd8c015c2e to your computer and use it in GitHub Desktop.
meta-tags
```
$ bundle add meta-tags
```
in config/locales/en.yml
```
en:
metatags: &metatags
canonical: handsomefencer.club
canonical: "#{params}"
charset: utf-8
description: Navy SEALs I Have Met in Hollywood
keywords:
- foo
- bar
site: StarBangers
title: Memoir Writing Site for Navy Special Warfare
viewport: width=device-width,initial-scale=1
index: true
static_pages:
home:
tags: &tags
title: Override title here
metatags:
<<: *metatags ## base metatags
<<: *tags ## override with visible tags above
noindex: true ## override visible tags with metatags here.
```
in app/componnts/meta_tags_component:
```
# frozen_string_literal: true
class MetaTagsComponent < ApplicationComponent
def initialize(params:, author:, record:, canonical:)
I18n.t("#{params['controller']}.#{params['action']}.metatags")
end
end
```
in app/componnts/meta_tags_component/meta_tags_component.html.erb:
```
<%= display_meta_tags @metatags %>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment