Add OG tags to layout.html.erb
This commit is contained in:
parent
c512d65d5d
commit
4b56d60fe7
|
@ -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)
|
||||
|
|
|
@ -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' %>
|
||||
|
|
|
@ -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 %>
|
||||
|
|
Loading…
Reference in New Issue