Skip to content

Commit e13e01b

Browse files
authored
Merge pull request #171 from joyofrails/feat/metatags
Adopt metatags for articles for better social media sharing
2 parents 2e1170a + 1beba5c commit e13e01b

File tree

13 files changed

+92
-13
lines changed

13 files changed

+92
-13
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ gem "phlex-rails", group: [:default, :wasm] # An object-oriented alternative to
3737
gem "commonmarker", require: false
3838
gem "invisible_captcha", group: [:default, :wasm] # Unobtrusive and flexible spam protection for Rails apps [https://github.com/markets/invisible_captcha]
3939
gem "color_conversion", group: [:default, :wasm] # A ruby gem to perform color conversions [https://github.com/devrieda/color_conversion]
40+
gem "meta-tags", group: [:default, :wasm] # Search Engine Optimization (SEO) for Ruby on Rails applications. [https://github.com/kpumuk/meta-tags]
4041

4142
gem "bootsnap", require: false # Reduces boot times through caching; required in config/boot.rb [https://github.com/Shopify/bootsnap]
4243

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ GEM
271271
net-smtp
272272
marcel (1.0.4)
273273
matrix (0.4.2)
274+
meta-tags (2.22.0)
275+
actionpack (>= 6.0.0, < 8.1)
274276
mime-types (3.5.2)
275277
mime-types-data (~> 3.2015)
276278
mime-types-data (3.2024.0305)
@@ -571,6 +573,7 @@ DEPENDENCIES
571573
js
572574
letter_opener
573575
litestream
576+
meta-tags
574577
mission_control-jobs
575578
phlex-rails
576579
postmark-rails
106 KB
Loading
62.9 KB
Loading

app/content/layouts/article.html.erb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
<% set_meta_tags(
2+
title: current_page.data.title!,
3+
description: current_page.data.description,
4+
keywords: %w[rails hotwire],
5+
index: true,
6+
icon: "/favicon.ico",
7+
og: {
8+
title: :title,
9+
description: :description,
10+
type: "article",
11+
url: current_page.url,
12+
site_name: "Joy of Rails",
13+
locale: "en_US",
14+
image: current_page.data.meta_image && asset_url(current_page.data.meta_image)
15+
},
16+
twitter: {
17+
card: current_page.data.meta_image ? "summary_large_image" : "summary",
18+
site: "@joyofrails",
19+
}
20+
) %>
121
<%= render "application/skip_to_content" %>
222
<%= render_layout "application" do %>
323
<article itemscope itemtype="http://schema.org/Article">

app/content/pages/articles/custom-color-schemes-with-ruby-on-rails.html.mdrb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description: You can edit the color scheme of this website right in content of t
66
summary: You can edit the color scheme of this website right in content of this blog post. Play with the controls while we highlight the benefits of Rails, Hotwire, and CSS variables.
77
published: 2024-07-15
88
image: articles/custom-color-schemes-with-ruby-on-rails/rainbows.jpg
9+
meta_image: articles/custom-color-schemes-with-ruby-on-rails/screenshot.jpg
910
uuid: d99f045b-f3f7-4408-811e-9701b1a13ce8
1011
tags:
1112
- Rails

app/content/pages/articles/introducing-joy-of-rails.html.mdrb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ published: '2024-05-02'
88
toc: false
99
uuid: 4106248b-ae8f-40a3-9853-48b91d815a71
1010
image: articles/introducing-joy-of-rails/adventure-world.gif
11+
meta_image: articles/introducing-joy-of-rails/screenshot.jpg
1112
tags:
1213
- Rails
1314
---

app/javascript/css/components/code.scss

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,21 @@
4040

4141
& .code-title {
4242
font-weight: 600;
43-
/* color: rgb(209 213 219 / var(--tw-text-opacity)); */
4443
display: block;
4544
text-align: center;
4645
line-height: 1;
4746

4847
& a {
4948
font-family: var(--sans-serif);
50-
font-weight: normal;
5149
gap: 0.25rem;
5250
align-items: center;
5351
display: flex;
54-
color: var(--joy-text);
52+
font-weight: bold;
53+
color: var(--joy-light);
54+
text-decoration: none;
55+
& svg {
56+
fill: var(--joy-light);
57+
}
5558
}
5659
}
5760
}

app/views/components/pages/header.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,8 @@ def initialize(title: nil, description: nil, published_on: nil, updated_on: nil)
1414
def view_template
1515
header(class: "page-header") do
1616
div(class: "container header-content") do
17-
if @title_block
18-
h1(&@title_block)
19-
else
20-
h1 { @title }
21-
end
17+
title = @title_block ? capture(&@title_block) : @title
18+
h1 { title }
2219
p(class: "description") { @description } if @description
2320
if @published_on || @updated_on
2421
span(class: "block") do

app/views/layouts/application.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html class="motion-safe:scroll-smooth">
33
<head>
4-
<title>Joy of Rails</title>
4+
<%= display_meta_tags site: "Joy of Rails" %>
55
<meta name="viewport" content="width=device-width,initial-scale=1">
66
<meta name="apple-mobile-web-app-capable" content="yes">
77
<%= render "application/google_fonts" %>
@@ -22,7 +22,6 @@
2222
<%= vite_javascript_tag "application.js", media: "all", "data-turbo-track": "reload" %>
2323

2424
<%= auto_discovery_link_tag(:rss, feed_index_url, {title: "joyofrails.com"}) %>
25-
2625
<script type="text/javascript" defer data-domain="joyofrails.com" src="https://plausible.io/js/script.tagged-events.outbound-links.js"></script>
2726
<script type="text/javascript">window.plausible = window.plausible || function() { (window.plausible.q = window.plausible.q || []).push(arguments) }</script>
2827
<%= yield :head %>

0 commit comments

Comments
 (0)