]> gitweb.mndrdr.org Git - arelpe.git/commitdiff
Bookmarks now include posts for a weekly summary, uses date sorting like the home...
authorAidan Cornelius-Bell <[email protected]>
Fri, 22 Nov 2024 22:40:12 +0000 (09:10 +1030)
committerAidan Cornelius-Bell <[email protected]>
Fri, 22 Nov 2024 22:40:12 +0000 (09:10 +1030)
app/jobs/weekly_bookmarks_digest_job.rb
app/mailers/digest_mailer.rb
app/views/digest_mailer/weekly_bookmarks_digest.html.erb

index 87e7f747a880d83ddf202fbff43856bf8f731d7e..b38746fafb10aac96268157565130e697208185a 100644 (file)
@@ -4,7 +4,7 @@ class WeeklyBookmarksDigestJob < ApplicationJob
   def perform(user = nil)
     start_date = 1.week.ago.beginning_of_week
     end_date = Time.current.end_of_week
-    bookmarks = Post.bookmarks.where(created_at: start_date..end_date)
+    bookmarks = Post.where(created_at: start_date..end_date)
     # or do User.find_each do |user| for everyone, but that'll break fastmail
     if user.present?
       DigestMailer.weekly_bookmarks_digest(user, bookmarks).deliver_now
index 92e1ab08c0dbfcfe0cdf385732cb3d911d5b2313..803c44d8671d63458d85a544a3c59c9ed2f8f8bc 100644 (file)
@@ -7,6 +7,6 @@ class DigestMailer < ApplicationMailer
   def weekly_bookmarks_digest(user, bookmarks)
     @user = user
     @bookmarks = bookmarks
-    mail(to: @user.email, subject: 'mind reader :: weekly bookmarks digest')
+    mail(to: @user.email, subject: 'mind reader :: weekly digest')
   end
 end
index 03fc0bab734ca1a5f8db9bf0b30ab5cabf450a72..ace210cd9067bfc8462ee0f22622a4ce9b7fefe8 100644 (file)
@@ -1,19 +1,28 @@
-<h1>Your weekly bookmarks digest</h1>
+<p>Dear <%= @user.first_name %>,</p>
 
-<p>Hello <%= @user.first_name %>,</p>
+<p>Here's what's new from mind reader this week:</p>
 
-<p>Here are the bookmarks added this week:</p>
+<% @bookmarks.group_by { |bookmark| bookmark.created_at.to_date }.each do |date, bookmarks| %>
+  <p>On <%= date.strftime('%B %e, %Y') %>:</p>
 
-<ul>
-  <% @bookmarks.each do |bookmark| %>
-    <li>
-      <strong><%= link_to bookmark.title, bookmark.url %></strong>
-      <% if bookmark.content.present? %>
-        <br><em><%= bookmark.content %></em>
-      <% end %>
-    </li>
-  <% end %>
-</ul>
+  <ul>
+    <% bookmarks.each do |bookmark| %>
+      <li>
+        <% if bookmark.url.present? %>
+          <strong><a href="<%= bookmark.url %>" target="_blank"><%= bookmark.title %></a></strong>
+        <% else %>
+          <strong><%= bookmark.title %></strong>
+        <% end %>
+        <% if bookmark.content.present? %>
+          <br><em><%= bookmark.content %></em>
+        <% end %>
+        <% if bookmark.created_at.present? %>
+          <br><small>Added at <%= bookmark.created_at.strftime('%l:%M%P') %></small>
+        <% end %>
+      </li>
+    <% end %>
+  </ul>
+<% end %>
 
 <p>Have a great weekend,<br>
-Aidan.</p>
\ No newline at end of file
+Aidan.</p>