← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:commit-to-MP-link-previews into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:commit-to-MP-link-previews into launchpad:master.

Commit message:
Add opengraph_description as an overridable attribute

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1885116 in Launchpad itself: "og:description tag on MPs could use commit message if no description is found"
  https://bugs.launchpad.net/launchpad/+bug/1885116

For more details, see:
https://code.launchpad.net/~twom/launchpad/+git/launchpad/+merge/386840

Some pages may wish to override the description displayed via opengraph to something that makes more sense in context.

Add this as an attribute on the base view, use the new property in the Merge Proposal template and view.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:commit-to-MP-link-previews into launchpad:master.
diff --git a/lib/lp/app/templates/base-layout.pt b/lib/lp/app/templates/base-layout.pt
index 08df3dc..4eb0133 100644
--- a/lib/lp/app/templates/base-layout.pt
+++ b/lib/lp/app/templates/base-layout.pt
@@ -50,8 +50,8 @@
         tal:condition="view/page_description | nothing"
         tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />
       <meta property="og:description"
-        tal:condition="view/page_description | nothing"
-        tal:attributes="content view/page_description/fmt:strip-email/fmt:shorten/500" />
+        tal:condition="view/opengraph_description | nothing"
+        tal:attributes="content view/opengraph_description/fmt:strip-email/fmt:shorten/500" />
     </tal:view>
 
     <tal:comment condition="nothing">
diff --git a/lib/lp/code/browser/branchmergeproposal.py b/lib/lp/code/browser/branchmergeproposal.py
index 6d33f97..ff86b13 100644
--- a/lib/lp/code/browser/branchmergeproposal.py
+++ b/lib/lp/code/browser/branchmergeproposal.py
@@ -767,6 +767,12 @@ class BranchMergeProposalView(LaunchpadFormView, UnmergedRevisionsMixin,
             mp, description, title, edit_view='+edit-description')
 
     @property
+    def opengraph_description(self):
+        if self.context.commit_message:
+            return self.context.commit_message
+        return self.page_description
+
+    @property
     def edit_commit_message_link_class(self):
         if self.context.commit_message:
             return "hidden"
diff --git a/lib/lp/services/webapp/publisher.py b/lib/lp/services/webapp/publisher.py
index fccb857..a3b8e70 100644
--- a/lib/lp/services/webapp/publisher.py
+++ b/lib/lp/services/webapp/publisher.py
@@ -369,6 +369,17 @@ class LaunchpadView(UserAttributeCache):
         return getattr(self.context, 'description', None)
 
     @property
+    def opengraph_description(self):
+        """Return a string for the description used in the OpenGraph metadata
+
+        Some pages may wish to override the values used in the OpenGraph
+        metadata to provide more useful link previews.
+
+        Default to the page_description in the base views.
+        """
+        return self.page_description
+
+    @property
     def template(self):
         """The page's template, if configured in zcml."""
         return self.index

Follow ups