user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: reduce empty <a>, use "id" instead of "name" attributes
Date: Mon,  6 Jul 2015 20:54:59 +0000	[thread overview]
Message-ID: <1436216099-27853-1-git-send-email-e@80x24.org> (raw)

This is probably more compliant, and saves us a few bytes
on the uncompressed HTML.
---
 lib/PublicInbox/View.pm | 18 +++++++-----------
 t/view.t                |  2 +-
 2 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 3695bb2..bc4c7ac 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -54,8 +54,8 @@ sub index_entry {
 	my $header_obj = $mime->header_obj;
 
 	my $mid_raw = $header_obj->header_raw('Message-ID');
-	my $name = anchor_for($mid_raw);
-	$seen->{$name} = "#$name"; # save the anchor for later
+	my $id = anchor_for($mid_raw);
+	$seen->{$id} = "#$id"; # save the anchor for later
 
 	my $mid = PublicInbox::Hval->new_msgid($mid_raw);
 	my $from = PublicInbox::Hval->new_oneline($mime->header('From'))->raw;
@@ -78,13 +78,9 @@ sub index_entry {
 	}
 	$ts = POSIX::strftime($fmt, gmtime($ts));
 
-	$rv .= "$pfx<a\nname=\"$name\"></a>" .
-		"<a\nname=\"s$midx\"></a>" .
-		"<b>$subj</b>\n$pfx";
-
+	$rv .= "$pfx<b\nid=\"$id\">$subj</b>\n$pfx";
 	$rv .= "- by $from @ $ts - ";
-
-	$rv .= "<a\nhref=\"#s$next\">next</a>";
+	$rv .= "<a\nid=\"s$midx\"\nhref=\"#s$next\">next</a>";
 	if ($prev >= 0) {
 		$rv .= "/<a\nhref=\"#s$prev\">prev</a>";
 	}
@@ -153,7 +149,7 @@ sub index_entry {
 		}
 		$rv .= " <a\nhref=\"$anchor\">parent</a>";
 	}
-	$rv .= " <a\nhref=\"?r=$first#$name\">threadlink</a>";
+	$rv .= " <a\nhref=\"?r=$first#$id\">threadlink</a>";
 
 	$rv . "\n\n";
 }
@@ -269,7 +265,7 @@ sub add_text_body_full {
 		my $cur = $1;
 		my @lines = split(/\n/, $cur);
 		if (@lines > MAX_INLINE_QUOTED) {
-			"<a\nname=q${part_nr}_" . $n++ . ">$cur</a>";
+			"<a\nid=q${part_nr}_" . $n++ . ">$cur</a>";
 		} else {
 			$cur;
 		}
@@ -382,7 +378,7 @@ sub anchor_for {
 	my ($msgid) = @_;
 	$msgid =~ s/\A\s*<?//;
 	$msgid =~ s/>?\s*\z//;
-	Digest::SHA::sha1_hex($msgid);
+	'm' . Digest::SHA::sha1_hex($msgid);
 }
 
 1;
diff --git a/t/view.t b/t/view.t
index 1851793..63de49b 100644
--- a/t/view.t
+++ b/t/view.t
@@ -47,7 +47,7 @@ EOF
 	like($html, qr!<a\nhref="\.\./m/hello%40!s, "MID link present");
 	like($html, qr/hello world\b/, "body present");
 	like($html, qr/&gt; keep this inline/, "short quoted text is inline");
-	like($html, qr/<a\nname=[^>]+>&gt; Long and wordy/,
+	like($html, qr/<a\nid=[^>]+>&gt; Long and wordy/,
 		"long quoted text is anchored");
 
 	# short page
-- 
EW


                 reply	other threads:[~2015-07-06 20:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436216099-27853-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).