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 --- Gemfile | 1 + Gemfile.lock | 3 +++ app/controllers/blogs_controller.rb | 15 +++++++++++++++ app/views/layouts/application.html.haml | 1 + 4 files changed, 20 insertions(+) diff --git a/Gemfile b/Gemfile index 3044a2f..887f7eb 100644 --- a/Gemfile +++ b/Gemfile @@ -82,3 +82,4 @@ gem 'rouge' gem 'akismet' gem 'active_storage_validations' gem "image_processing", ">= 1.2" +gem "meta-tags" diff --git a/Gemfile.lock b/Gemfile.lock index 4ba3db9..18f75fe 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -198,6 +198,8 @@ GEM net-pop net-smtp marcel (1.0.2) + meta-tags (2.19.0) + actionpack (>= 3.2.0, < 7.2) method_source (1.0.0) mime-types (3.5.1) mime-types-data (~> 3.2015) @@ -373,6 +375,7 @@ DEPENDENCIES js-routes lingo! listen (>= 3.0.5, < 3.2) + meta-tags mini_racer mysql2 normalize-rails 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