From ccbe3bea79da2d87647d977d0ec55e2a3235d0d9 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Mon, 31 May 2021 14:03:19 +0300 Subject: [PATCH] UX: Improve style of GitHub PR body in emails (#13198) On the web, we display only an excerpt in a monospace font and the rest of the body is hidden under ellipsis. The email displayed both of them and it did not use the same style. This commit leaves only the excerpt in emails and makes it use a monospace font to display it. --- lib/email/styles.rb | 3 +++ spec/components/email/styles_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/email/styles.rb b/lib/email/styles.rb index 2c2c207ca0f..73c6e08329c 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -139,8 +139,11 @@ module Email style('.github-info div', "display: inline; margin-right: 10px;") style('.github-icon-container', 'float: left;') style('.github-icon-container *', 'fill: #646464; width: 40px; height: 40px;') + style('.github-body-container', 'font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; margin-top: 1em !important;') style('.onebox-avatar-inline', ONEBOX_INLINE_AVATAR_STYLE) + @fragment.css('.github-body-container .excerpt').remove + @fragment.css('aside.quote blockquote > p').each do |p| p['style'] = 'padding: 0;' end diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb index d5767310e12..55fe5187ef8 100644 --- a/spec/components/email/styles_spec.rb +++ b/spec/components/email/styles_spec.rb @@ -185,6 +185,15 @@ describe Email::Styles do fragment = html_fragment('') expect(fragment.to_s.squish).to match(/^$/) end + + it "removes GitHub excerpts" do + stub_request(:head, "https://github.com/discourse/discourse/pull/1253").to_return(status: 200, body: "", headers: {}) + stub_request(:get, "https://api.github.com/repos/discourse/discourse/pulls/1253").to_return(status: 200, body: onebox_response("githubpullrequest")) + + onebox = Oneboxer.onebox("https://github.com/discourse/discourse/pull/1253") + fragment = html_fragment(onebox) + expect(fragment.css(".github-body-container .excerpt")).to be_empty + end end context "replace_secure_media_urls" do