diff --git a/Envfile b/Envfile index 9603fb9ba..74c81c86a 100644 --- a/Envfile +++ b/Envfile @@ -79,6 +79,7 @@ variable :BUFFER_FACEBOOK_ID, :String, default: "Optional" variable :BUFFER_LINKEDIN_ID, :String, default: "Optional" variable :BUFFER_PROFILE_ID, :Integer, default: 0 variable :BUFFER_TWITTER_ID, :String, default: "Optional" +variable :BUFFER_LISTINGS_PROFILE, :String, default: "Optional" # Cloudinary for image resizing and cache?? variable :CLOUDINARY_API_KEY, :String, default: "Optional" diff --git a/app/controllers/internal/buffer_updates_controller.rb b/app/controllers/internal/buffer_updates_controller.rb index 6bdfe73f1..413753f14 100644 --- a/app/controllers/internal/buffer_updates_controller.rb +++ b/app/controllers/internal/buffer_updates_controller.rb @@ -1,16 +1,23 @@ class Internal::BufferUpdatesController < Internal::ApplicationController def create - article = Article.find(params[:article_id]) + article_id = params[:article_id] + article = Article.find(article_id) if article_id.present? fb_post = params[:fb_post] tweet = params[:tweet] - if params[:social_channel] == "main_twitter" - Bufferizer.new(article, tweet).main_teet! + listing_id = params[:listing_id] + listing = ClassifiedListing.find(params[:listing_id]) if listing_id.present? + case params[:social_channel] + when "main_twitter" + Bufferizer.new("article", article, tweet).main_tweet! render body: nil - elsif params[:social_channel] == "satellite_twitter" - Bufferizer.new(article, tweet).satellite_tweet! + when "satellite_twitter" + Bufferizer.new("article", article, tweet).satellite_tweet! render body: nil - elsif params[:social_channel] == "facebook" - Bufferizer.new(article, fb_post).facebook_post! + when "facebook" + Bufferizer.new("article", article, fb_post).facebook_post! + render body: nil + when "listings_twitter" + Bufferizer.new("listing", listing, tweet).listings_tweet! render body: nil end end diff --git a/app/controllers/social_previews_controller.rb b/app/controllers/social_previews_controller.rb index c6eafeeda..a9cc76acc 100644 --- a/app/controllers/social_previews_controller.rb +++ b/app/controllers/social_previews_controller.rb @@ -23,14 +23,27 @@ class SocialPreviewsController < ApplicationController def user @user = User.find(params[:id]) || not_found - respond_to do |format| format.html do render layout: false end format.png do html = render_to_string(formats: :html, layout: false) - redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto"), status: :found + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: :found + end + end + end + + def listing + @listing = ClassifiedListing.find(params[:id]) || not_found + define_categories + respond_to do |format| + format.html do + render layout: false + end + format.png do + html = render_to_string(formats: :html, layout: false) + redirect_to HtmlCssToImage.fetch_url(html: html, css: PNG_CSS, google_fonts: "Roboto|Roboto+Condensed"), status: :found end end end @@ -62,4 +75,24 @@ class SocialPreviewsController < ApplicationController end end end + + private + + def define_categories + cat_info = { + "collabs": ["Collaborators Wanted", "#5AE8D9"], + "cfp": ["Call For Proposal", "#f58f8d"], + "forhire": ["Available For Hire", "#b78cf4"], + "education": ["Education", "#5AABE8"], + "jobs": ["Now Hiring", "#53c3ad"], + "mentors": ["Offering Mentorship", "#A69EE8"], + "mentees": ["Looking For Mentorship", "#88aedb"], + "forsale": ["Stuff For Sale", "#d0adfb"], + "events": ["Upcoming Event", "#f8b3d0"], + "misc": ["Miscellaneous", "#6393FF"], + "products": ["Products & Tools", "#5AE8D9"] + } + @category = cat_info[@listing.category.to_sym][0] + @cat_color = cat_info[@listing.category.to_sym][1] + end end diff --git a/app/helpers/social_image_helper.rb b/app/helpers/social_image_helper.rb index 83b71aa41..9cb6daf64 100644 --- a/app/helpers/social_image_helper.rb +++ b/app/helpers/social_image_helper.rb @@ -13,6 +13,10 @@ module SocialImageHelper end end + def listing_social_image_url(listing) + listing_social_preview_url(listing, format: :png) + end + def article_social_image_url(article) image = user_defined_image(article) if image.present? diff --git a/app/labor/bufferizer.rb b/app/labor/bufferizer.rb index d7becb35c..4aba188ed 100644 --- a/app/labor/bufferizer.rb +++ b/app/labor/bufferizer.rb @@ -1,35 +1,49 @@ class Bufferizer - attr_accessor :article, :text - def initialize(article, text) - @article = article + attr_accessor :post_type, :post, :text + def initialize(post_type, post, text) + if post_type == "article" + @article = post + else + @listing = post + end @text = text end def satellite_tweet! - article.tags.find_each do |tag| - BufferUpdate.buff!(article.id, twitter_buffer_text, tag.buffer_profile_id_code, "twitter", tag.id) if tag.buffer_profile_id_code.present? + @article.tags.find_each do |tag| + BufferUpdate.buff!(@article.id, twitter_buffer_text, tag.buffer_profile_id_code, "twitter", tag.id) if tag.buffer_profile_id_code.present? end - article.update(last_buffered: Time.current) + @article.update(last_buffered: Time.current) end - def main_teet! - BufferUpdate.buff!(article.id, twitter_buffer_text, ApplicationConfig["BUFFER_TWITTER_ID"], "twitter", nil) - article.update(last_buffered: Time.current) + def main_tweet! + BufferUpdate.buff!(@article.id, twitter_buffer_text, ApplicationConfig["BUFFER_TWITTER_ID"], "twitter", nil) + @article.update(last_buffered: Time.current) end def facebook_post! - BufferUpdate.buff!(article.id, fb_buffer_text, ApplicationConfig["BUFFER_FACEBOOK_ID"], "facebook") - BufferUpdate.buff!(article.id, fb_buffer_text, ApplicationConfig["BUFFER_LINKEDIN_ID"], "linkedin") - article.update(facebook_last_buffered: Time.current) + BufferUpdate.buff!(@article.id, fb_buffer_text, ApplicationConfig["BUFFER_FACEBOOK_ID"], "facebook") + BufferUpdate.buff!(@article.id, fb_buffer_text, ApplicationConfig["BUFFER_LINKEDIN_ID"], "linkedin") + @article.update(facebook_last_buffered: Time.current) + end + + def listings_tweet! + buffer_listings_id = ApplicationConfig["BUFFER_LISTINGS_PROFILE"] + BufferUpdate.send_to_buffer(listings_twitter_text, buffer_listings_id) + @listing.update(last_buffered: Time.current) end private def twitter_buffer_text - "#{text} https://dev.to#{article.path}" if text.size <= 255 + "#{text} https://dev.to#{@article.path}" if text.size <= 255 end def fb_buffer_text - "#{text} https://dev.to#{article.path}" + "#{text} https://dev.to#{@article.path}" + end + + def listings_twitter_text + "#{text} https://dev.to#{@listing.path}" if text.size <= 255 end end diff --git a/app/models/buffer_update.rb b/app/models/buffer_update.rb index 852c8dfc5..2daaf82a4 100644 --- a/app/models/buffer_update.rb +++ b/app/models/buffer_update.rb @@ -1,6 +1,5 @@ class BufferUpdate < ApplicationRecord belongs_to :article - validate :validate_body_text_recent_uniqueness validates :status, inclusion: { in: %w[pending sent_direct confirmed dismissed] } diff --git a/app/models/classified_listing.rb b/app/models/classified_listing.rb index 045bfb4dd..a3a472bf0 100644 --- a/app/models/classified_listing.rb +++ b/app/models/classified_listing.rb @@ -5,7 +5,6 @@ class ClassifiedListing < ApplicationRecord belongs_to :user, optional: true belongs_to :organization, optional: true - before_save :evaluate_markdown before_create :create_slug before_validation :modify_inputs diff --git a/app/views/classified_listings/index.html.erb b/app/views/classified_listings/index.html.erb index 6f39bdeb9..665990486 100644 --- a/app/views/classified_listings/index.html.erb +++ b/app/views/classified_listings/index.html.erb @@ -4,37 +4,44 @@ - - - - - + <% if @displayed_classified_listing %> + + + + + + + <% else %> + + + + + + + <% end %> - - - <% end %>