From 3548a90e62ed6e8f24d896fa15c62c477c841e97 Mon Sep 17 00:00:00 2001 From: Jeremy Edberg Date: Wed, 25 Mar 2009 15:32:35 -0700 Subject: [PATCH] add canonical links and descriptions to the meta tags --- r2/r2/controllers/listingcontroller.py | 1 + r2/r2/lib/pages/pages.py | 9 +++++++-- r2/r2/templates/base.html | 4 ++++ r2/r2/templates/reddit.html | 9 +++++++++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/r2/r2/controllers/listingcontroller.py b/r2/r2/controllers/listingcontroller.py index 91c3467f4..68b3394a4 100644 --- a/r2/r2/controllers/listingcontroller.py +++ b/r2/r2/controllers/listingcontroller.py @@ -95,6 +95,7 @@ class ListingController(RedditController): show_sidebar = self.show_sidebar, nav_menus = self.menus, title = self.title(), + description = c.site.description, infotext = self.infotext, **self.render_params).render() return res diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index ae539b9c8..584b6c693 100644 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -78,9 +78,12 @@ class Reddit(Wrapped): def __init__(self, space_compress = True, nav_menus = None, loginbox = True, infotext = '', content = None, title = '', robots = None, - show_sidebar = True, **context): + canonical = None, description = None, show_sidebar = True, + **context): Wrapped.__init__(self, **context) self.title = title + self.description = description + self.canonical = canonical self.robots = robots self.infotext = infotext self.loginbox = True @@ -432,7 +435,9 @@ class LinkInfoPage(Reddit): self.link = self.link_listing.things[0] link_title = ((self.link.title) if hasattr(self.link, 'title') else '') + canonical = "%s%s" % (add_sr(self.link.permalink), "?sort=top") if comment: + canonical = "%s%s" % (add_sr(comment.make_permalink_slow()), "?sort=top") if comment._deleted and not c.user_is_admin: author = _("[deleted]") else: @@ -443,7 +448,7 @@ class LinkInfoPage(Reddit): else: params = {'title':_force_unicode(link_title), 'site' : c.site.name} title = strings.link_info_title % params - Reddit.__init__(self, title = title, *a, **kw) + Reddit.__init__(self, title = title, canonical=canonical, *a, **kw) def build_toolbars(self): base_path = "/%s/%s/" % (self.link._id36, title_to_url(self.link.title)) diff --git a/r2/r2/templates/base.html b/r2/r2/templates/base.html index 360fedcdf..6db2fd37f 100644 --- a/r2/r2/templates/base.html +++ b/r2/r2/templates/base.html @@ -33,6 +33,7 @@ + ${self.Description()} ${self.robots()} @@ -73,6 +74,9 @@ ${title} +<%def name="Description()"> + + <%def name="keywords()"> reddit, reddit.com, vote, comment, submit diff --git a/r2/r2/templates/reddit.html b/r2/r2/templates/reddit.html index 018d6b836..aec026652 100644 --- a/r2/r2/templates/reddit.html +++ b/r2/r2/templates/reddit.html @@ -36,6 +36,12 @@ %endif +<%def name="Description()"> + %if thing.description: + + %endif + + <%def name="stylesheet()"> <% from r2.lib.template_helpers import static, get_domain %> @@ -73,6 +79,9 @@ %endif + %if thing.canonical: + + %endif <%def name="javascript()">