Add canonical URL anchors to the HTML of most entry/comment pages.

        Patch by afuna. 

diffs (73 lines):

diff -r f6f8ca5311a9 -r cbf80d2d289a cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm        Wed Jul 22 01:52:33 2009 +0000
+++ b/cgi-bin/LJ/S2/EntryPage.pm        Wed Jul 22 01:56:19 2009 +0000
@@ -54,6 +54,12 @@ sub EntryPage
     
     my $next_url = S2::Builtin::LJ::Entry__get_link( $opts->{ctx}, $s2entry, 
"nav_next" )->{url};
     $p->{head_content} .= qq{<link rel="next" href="$next_url" />\n} if 
$next_url;
+
+    # canonical link to the entry or comment thread
+    my $canonical_url = $permalink;
+    my $threadid = $get->{thread} + 0;
+    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
+    $p->{head_content} .= qq{<link rel="canonical" href="$canonical_url" />\n};
 
     # quickreply js libs
     LJ::need_res(qw(
diff -r f6f8ca5311a9 -r cbf80d2d289a cgi-bin/LJ/S2/ReplyPage.pm
--- a/cgi-bin/LJ/S2/ReplyPage.pm        Wed Jul 22 01:52:33 2009 +0000
+++ b/cgi-bin/LJ/S2/ReplyPage.pm        Wed Jul 22 01:56:19 2009 +0000
@@ -42,6 +42,13 @@ sub ReplyPage
     return if $opts->{'handler_return'};
     return if $opts->{'redir'};
     my $ditemid = $entry->ditemid;
+
+    # canonical link to the entry or comment thread
+    my $canonical_url = $entry->url;
+    my $replytoid = $get->{replyto} ? $get->{replyto} + 0 : 0;
+    $canonical_url .= "?thread=$replytoid#t$replytoid" if $replytoid;
+    $p->{head_content} .= qq{<link rel="canonical" href="$canonical_url" />\n};
+
     $p->{'head_content'} .= $LJ::COMMON_CODE{'chalresp_js'};
 
     LJ::need_res('stc/display_none.css');
@@ -56,7 +63,6 @@ sub ReplyPage
     # setup the replying item
     my $replyto = $s2entry;
     my $editid = $get->{edit} ? $get->{edit} : 0;
-    my $replytoid = $get->{replyto} ? $get->{replyto} : 0;
     my $parpost;
 
     my $comment;
diff -r f6f8ca5311a9 -r cbf80d2d289a htdocs/talkpost.bml
--- a/htdocs/talkpost.bml       Wed Jul 22 01:52:33 2009 +0000
+++ b/htdocs/talkpost.bml       Wed Jul 22 01:56:19 2009 +0000
@@ -132,6 +132,12 @@ body<=
     my $ditemid = $init->{'ditemid'};
     my $talkurl = LJ::journal_base($u) . "/$ditemid.html";
     my $entry = LJ::Entry->new($u, ditemid => $ditemid);
+
+    # canonical link to the entry or comment thread
+    my $canonical_url = $entry->url;
+    my $threadid = $GET{replyto} + 0;
+    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
+    $head .= qq{<link rel="canonical" href="$canonical_url" />\n};
 
     $parpost ||= $item;  # if there's no parent post, remote is reply to 
top-level item
 
diff -r f6f8ca5311a9 -r cbf80d2d289a htdocs/talkread.bml
--- a/htdocs/talkread.bml       Wed Jul 22 01:52:33 2009 +0000
+++ b/htdocs/talkread.bml       Wed Jul 22 01:56:19 2009 +0000
@@ -113,6 +113,12 @@ body<=
     }
 
     my $entry = LJ::Entry->new($u, ditemid => $ditemid);
+
+    # canonical link to the entry or comment thread
+    my $canonical_url = $entry->url;
+    my $threadid = $GET{thread} + 0;
+    $canonical_url .= "?thread=$threadid#t$threadid" if $threadid;
+    $$head .= qq{<link rel="canonical" href="$canonical_url" />\n};
 
     $u->preload_props("opt_blockrobots", "adult_content") if $u->is_visible;
     if (!$u->is_visible || $u->should_block_robots || ($entry && 
$entry->should_block_robots)) {
_______________________________________________
dw-changelog mailing list
[email protected]
http://lists.dwscoalition.org/mailman/listinfo/dw-changelog

Reply via email to