]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Fixed a test suite induced bug and lengthened excerpts on hp
authorAidan Cornelius-Bell <[email protected]>
Tue, 7 Jan 2025 01:51:40 +0000 (12:21 +1030)
committerAidan Cornelius-Bell <[email protected]>
Tue, 7 Jan 2025 01:51:40 +0000 (12:21 +1030)
app/models/post.rb
app/models/user.rb

index c8a25c1ee7b4b024fb81350b2760fe5be6e21ebd..071139e5806776ea99e7d98e5b793020fe1e4c8c 100644 (file)
@@ -1,6 +1,6 @@
 class Post < ApplicationRecord
   include UrlTitleFetchable
-  
+
   validates :post_type, presence: true, inclusion: { in: %w[dispatch bookmark] }
   validates :title, presence: true
   validates :slug, presence: true, uniqueness: true, if: :dispatch?
@@ -23,10 +23,10 @@ class Post < ApplicationRecord
             else
               all
             end
-            
+
     posts.order(published_at: :desc).page(page).per(per_page)
   end
-  
+
   def rss_time
     published_at.strftime("%a, %d %b %Y %H:%M:%S %Z") if published_at
   end
@@ -38,11 +38,11 @@ class Post < ApplicationRecord
   def bookmark?
     post_type == 'bookmark'
   end
-  
+
   def short_dispatch?
-    dispatch? && 
-    content.present? && 
-    content.split.size <= 150 && 
+    dispatch? &&
+    content.present? &&
+    content.split.size <= 150 &&
     !content.strip.start_with?("Dear friends,")
   end
 
@@ -52,18 +52,19 @@ class Post < ApplicationRecord
 
   def format_tags
     return "" if tags.blank?
-    
+
     tags.split(/\s*(?:,|\s+and)\s*/).map { |tag| "<code>#{tag.strip}</code>" }.join(', ') + '.'
   end
 
-  def generate_excerpt(max_length = 210)
+  def generate_excerpt(max_length = 1040, take = 10)
     return "" if content.blank?
-  
+
     stripped_content = ActionController::Base.helpers.strip_tags(content)
-    excerpt = stripped_content.split('.').first || stripped_content[0...max_length]
+    excerpt = stripped_content.split('.') if stripped_content.split('.')
+    excerpt = excerpt.take(take)
+    excerpt = excerpt.join(',')
     excerpt = excerpt[0...max_length] if excerpt.length > max_length
     excerpt.gsub!("Dear friends,", "")
-    excerpt.gsub!(/\s+/, ' ')
     excerpt.strip
   end
 
@@ -72,19 +73,19 @@ class Post < ApplicationRecord
   def set_slug
     self.slug = title.present? ? title.parameterize : nil
   end
-  
+
   def set_published_at
     self.published_at ||= Time.current
   end
-  
+
   private
-  
+
   def set_title_from_url
     return unless bookmark? && url.present? && title.blank?
-    
+
     Rails.logger.debug("Attempting to fetch title for URL: #{url}")
     fetched_title = fetch_title_from_url(url)
-    
+
     if fetched_title.present?
       Rails.logger.debug("Successfully fetched title: #{fetched_title}")
       self.title = fetched_title
index 234479d08bbdbb972a552f8033863c48b192a081..fde16a6fed5d6c70714ce659892e28409a6d2672 100644 (file)
@@ -4,9 +4,7 @@ class User < ApplicationRecord
   devise :database_authenticatable, :registerable,
          :recoverable, :rememberable, :validatable,
          :confirmable, :lockable, :two_factor_authenticatable, :two_factor_backupable,
-         otp_secret_encryption_key: ENV.fetch('ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY') do
-            Rails.application.credentials.dig(:active_record_encryption, :primary_key) || 'test_key_1_'*4
-         end
+         otp_secret_encryption_key: Rails.application.credentials.dig(:active_record_encryption, :primary_key)
 
   encrypts :otp_secret
   attr_accessor :otp_plain_secret