Skip to content

Commit 0694502

Browse files
authored
Merge pull request rails#53811 from p8/guides/canonical-link
Add canonical link tag to guides head
2 parents 7a9b725 + 669ba9a commit 0694502

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

guides/rails_guides/generator.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,14 @@ def generate_guide(guide, output_file)
186186

187187
view = ActionView::Base.with_empty_template_cache.with_view_paths(
188188
[@source_dir],
189-
edge: @edge,
190-
version: @version,
191-
epub: "epub/#{epub_filename}",
192-
language: @language,
193-
direction: @direction,
194-
uuid: SecureRandom.uuid,
195-
digest_paths: @digest_paths
189+
edge: @edge,
190+
version: @version,
191+
epub: "epub/#{epub_filename}",
192+
language: @language,
193+
direction: @direction,
194+
uuid: SecureRandom.uuid,
195+
digest_paths: @digest_paths,
196+
canonical_url: canonical_url(output_file)
196197
)
197198
view.extend(Helpers)
198199

@@ -223,6 +224,12 @@ def generate_guide(guide, output_file)
223224
end if !dry_run?
224225
end
225226

227+
def canonical_url(path)
228+
url = "https://guides.rubyonrails.org/"
229+
url += path unless path == "index.html"
230+
url
231+
end
232+
226233
def warn_about_broken_links(html)
227234
anchors = extract_anchors(html)
228235
check_fragment_identifiers(html, anchors)

guides/source/layout.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
<link rel="apple-touch-icon" href="images/icon.png">
1515

16+
<link rel="canonical" href="<%= @canonical %>">
17+
1618
<script src="<%= digest_path('javascripts/@hotwired--turbo.js') %>" data-turbo-track="reload"></script>
1719
<script src="<%= digest_path('javascripts/clipboard.js') %>" data-turbo-track="reload"></script>
1820
<script src="<%= digest_path('javascripts/guides.js') %>" data-turbo-track="reload"></script>

0 commit comments

Comments
 (0)