From e9125c8d1658895cb45385630c87f82abc8a8935 Mon Sep 17 00:00:00 2001 From: Aidan Cornelius-Bell Date: Sat, 23 Nov 2024 09:10:12 +1030 Subject: [PATCH] Bookmarks now include posts for a weekly summary, uses date sorting like the home page, might migrate to this over 'every dispatch as a post' not sure yet. --- app/jobs/weekly_bookmarks_digest_job.rb | 2 +- app/mailers/digest_mailer.rb | 2 +- .../weekly_bookmarks_digest.html.erb | 37 ++++++++++++------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/app/jobs/weekly_bookmarks_digest_job.rb b/app/jobs/weekly_bookmarks_digest_job.rb index 87e7f74..b38746f 100644 --- a/app/jobs/weekly_bookmarks_digest_job.rb +++ b/app/jobs/weekly_bookmarks_digest_job.rb @@ -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 diff --git a/app/mailers/digest_mailer.rb b/app/mailers/digest_mailer.rb index 92e1ab0..803c44d 100644 --- a/app/mailers/digest_mailer.rb +++ b/app/mailers/digest_mailer.rb @@ -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 diff --git a/app/views/digest_mailer/weekly_bookmarks_digest.html.erb b/app/views/digest_mailer/weekly_bookmarks_digest.html.erb index 03fc0ba..ace210c 100644 --- a/app/views/digest_mailer/weekly_bookmarks_digest.html.erb +++ b/app/views/digest_mailer/weekly_bookmarks_digest.html.erb @@ -1,19 +1,28 @@ -

Your weekly bookmarks digest

+

Dear <%= @user.first_name %>,

-

Hello <%= @user.first_name %>,

+

Here's what's new from mind reader this week:

-

Here are the bookmarks added this week:

+<% @bookmarks.group_by { |bookmark| bookmark.created_at.to_date }.each do |date, bookmarks| %> +

On <%= date.strftime('%B %e, %Y') %>:

- + +<% end %>

Have a great weekend,
-Aidan.

\ No newline at end of file +Aidan.

-- 2.39.5