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 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'app/controllers') 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 -- cgit 1.4.1