From 745b9e5485100c98cc73d1ff90661b43ade9404a Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Tue, 17 Oct 2023 17:14:40 -0400 Subject: Added OpenGraph data for blog posts --- app/controllers/blogs_controller.rb | 15 +++++++++++++++ app/views/layouts/application.html.haml | 1 + 2 files changed, 16 insertions(+) (limited to 'app') diff --git a/app/controllers/blogs_controller.rb b/app/controllers/blogs_controller.rb index 39a578a..0d218ae 100644 --- a/app/controllers/blogs_controller.rb +++ b/app/controllers/blogs_controller.rb @@ -1,3 +1,5 @@ +require 'redcarpet/render_strip' + class BlogsController < ApplicationController def summary @@ -21,6 +23,19 @@ class BlogsController < ApplicationController raise ActiveRecord::RecordNotFound unless @blog raise ActiveRecord::RecordNotFound unless @blog.published + + body = Redcarpet::Markdown.new(Redcarpet::Render::StripDown).render(@blog.body) + + set_meta_tags(og: { + title: @blog.title, + type: "article", + description: (body.length <= 300 ? body : body[0..299]), + url: blog_url(@blog, host: "www.fourisland.com"), + article: { + published_time: @blog.published_at.iso8601, + modified_time: @blog.updated_at.iso8601 + } + }) end end diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 92546d1..32afb5d 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -5,6 +5,7 @@ = csrf_meta_tags = stylesheet_link_tag 'main', media: 'all', 'data-turbolinks-track': 'reload' = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' + = display_meta_tags og: { site_name: "Four Island" } %body#main-body - if flash[:alert] %div#flash.flash-alert= flash[:alert] -- cgit 1.4.1