diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-01-09 14:17:44 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-09 14:17:44 +0900 |
commit | 69ca787bd26c0306cdfde25de76036686fc39f4f (patch) | |
tree | 3cbfdf0c128265f049b08435b8e1a943e781d033 /guides | |
parent | c512d65d5d014562672902a8f53392b941d255a1 (diff) | |
parent | 4b56d60fe7da01d5680008b0301a3377d522a94d (diff) | |
download | rails-69ca787bd26c0306cdfde25de76036686fc39f4f.tar.gz rails-69ca787bd26c0306cdfde25de76036686fc39f4f.tar.bz2 rails-69ca787bd26c0306cdfde25de76036686fc39f4f.zip |
Merge pull request #34860 from toshimaru/make-guides-sns-friendly
Make Ruby on Rails Guides SNS-friendly
Diffstat (limited to 'guides')
-rw-r--r-- | guides/rails_guides/markdown.rb | 8 | ||||
-rw-r--r-- | guides/source/index.html.erb | 5 | ||||
-rw-r--r-- | guides/source/layout.html.erb | 9 |
3 files changed, 18 insertions, 4 deletions
diff --git a/guides/rails_guides/markdown.rb b/guides/rails_guides/markdown.rb index a98aa8fe66..018f49ffd0 100644 --- a/guides/rails_guides/markdown.rb +++ b/guides/rails_guides/markdown.rb @@ -3,6 +3,7 @@ require "redcarpet" require "nokogiri" require "rails_guides/markdown/renderer" +require "rails-html-sanitizer" module RailsGuides class Markdown @@ -20,6 +21,7 @@ module RailsGuides @raw_body = body extract_raw_header_and_body generate_header + generate_description generate_title generate_body generate_structure @@ -82,6 +84,11 @@ module RailsGuides @header = engine.render(@raw_header).html_safe end + def generate_description + sanitizer = Rails::Html::FullSanitizer.new + @description = sanitizer.sanitize(@header).squish + end + def generate_structure @headings_for_index = [] if @body.present? @@ -165,6 +172,7 @@ module RailsGuides def render_page @view.content_for(:header_section) { @header } + @view.content_for(:description) { @description } @view.content_for(:page_title) { @title } @view.content_for(:index_section) { @index } @view.render(layout: @layout, html: @body.html_safe) diff --git a/guides/source/index.html.erb b/guides/source/index.html.erb index 76f01fea0a..10e388774c 100644 --- a/guides/source/index.html.erb +++ b/guides/source/index.html.erb @@ -1,6 +1,5 @@ -<% content_for :page_title do %> -Ruby on Rails Guides -<% end %> +<% content_for :page_title, "Ruby on Rails Guides" %> +<% content_for :description, "Ruby on Rails Guides" %> <% content_for :header_section do %> <%= render 'welcome' %> diff --git a/guides/source/layout.html.erb b/guides/source/layout.html.erb index 1f42d72756..65a003fceb 100644 --- a/guides/source/layout.html.erb +++ b/guides/source/layout.html.erb @@ -3,7 +3,7 @@ <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> - <title><%= yield(:page_title) || 'Ruby on Rails Guides' %></title> + <title><%= yield(:page_title) %></title> <link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbolinks-track="reload"> <link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print"> <link rel="stylesheet" type="text/css" href="stylesheets/syntaxhighlighter/shCore.css" data-turbolinks-track="reload"> @@ -14,6 +14,13 @@ <script src="javascripts/turbolinks.js" data-turbolinks-track="reload"></script> <script src="javascripts/guides.js" data-turbolinks-track="reload"></script> <script src="javascripts/responsive-tables.js" data-turbolinks-track="reload"></script> + <meta property="og:title" content="<%= yield(:page_title) %>" /> + <meta name="description" content="<%= yield(:description) %>" /> + <meta property="og:description" content="<%= yield(:description) %>" /> + <meta property="og:locale" content="en_US" /> + <meta property="og:site_name" content="Ruby on Rails Guides" /> + <meta property="og:image" content="https://avatars.githubusercontent.com/u/4223" /> + <meta property="og:type" content="website" /> </head> <body class="guide"> <% if @edge %> |