From 1b4b2c7b8b2f2df8f114617d2e875eaf5c839ce0 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 1 Sep 2015 08:55:26 +0000 Subject: completely revamp URL structure to shorten permalinks This allows common /m/ links to be used without a prefix, saving 2 precious bytes for permalinks and raw messages. Old URLs continue to redirect. --- lib/PublicInbox/View.pm | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'lib/PublicInbox/View.pm') diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index a30bf70a..2be16b43 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -80,7 +80,7 @@ sub index_entry { $anchor = $seen->{$anchor_idx}; } if ($srch) { - $subj = "$subj"; + $subj = "$subj"; } if ($root_anchor && $root_anchor eq $id) { $subj = "$subj"; @@ -101,9 +101,9 @@ sub index_entry { $fh->write($rv .= "\n\n"); my ($fhref, $more_ref); - my $mhref = "${path}m/$href/"; + my $mhref = "${path}$href/"; if ($level > 0) { - $fhref = "${path}f/$href/"; + $fhref = "${path}$href/f/"; $more_ref = \$more; } # scan through all parts, looking for displayable text @@ -112,7 +112,7 @@ sub index_entry { }); $mime->body_set(''); - my $txt = "${path}m/$href/raw"; + my $txt = "${path}$href/raw"; $rv = "\n$more raw "; $rv .= html_footer($mime, 0, undef, $ctx); @@ -120,7 +120,7 @@ sub index_entry { unless (defined $anchor) { my $v = PublicInbox::Hval->new_msgid($irt); $v = $v->as_href; - $anchor = "${path}m/$v/"; + $anchor = "${path}$v/"; $seen->{$anchor_idx} = $anchor; } $rv .= " parent"; @@ -160,8 +160,8 @@ sub emit_thread_html { my $next = ""; $next .= $final_anchor == 1 ? 'only message in' : 'end of'; $next .= " thread, back to index\n"; - $next .= "download: mbox.gz"; - $next .= " / Atom feed\n\n"; + $next .= "download: mbox.gz"; + $next .= " / Atom feed\n\n"; $fh->write("
" . PRE_WRAP . $next . $foot . ""); $fh->close; @@ -349,8 +349,8 @@ sub headers_to_html_header { } elsif ($h eq 'Subject') { $title[0] = $v->as_html; if ($srch) { - $rv .= "$h: "; + my $p = $full_pfx ? '' : '../'; + $rv .= "$h: "; $rv .= $v->as_html . "\n"; next; } @@ -359,7 +359,7 @@ sub headers_to_html_header { } $rv .= 'Message-ID: <' . $mid->as_html . '> '; - my $raw_ref = $full_pfx ? 'raw' : "../../m/$mid_href/raw"; + my $raw_ref = $full_pfx ? 'raw' : '../raw'; $rv .= "(raw)\n"; if ($srch) { $rv .= "References: [see below]\n"; @@ -373,7 +373,7 @@ sub headers_to_html_header { } sub thread_inline { - my ($dst, $ctx, $cur) = @_; + my ($dst, $ctx, $cur, $full_pfx) = @_; my $srch = $ctx->{srch}; my $mid = mid_compress(mid_clean($cur->header('Message-ID'))); my $res = $srch->get_thread($mid); @@ -383,9 +383,10 @@ sub thread_inline { $$dst .= "\n[no followups, yet]\n"; return; } + my $upfx = $full_pfx ? '' : '../'; $$dst .= "\n\n~$nr messages in thread: ". - "(expand)\n"; + "(expand)\n"; my $subj = $srch->subject_path($cur->header('Subject')); my $state = { seen => { $subj => 1 }, @@ -393,7 +394,7 @@ sub thread_inline { cur => $mid, }; for (thread_results(load_results($res))->rootset) { - inline_dump($dst, $state, $_, 0); + inline_dump($dst, $state, $upfx, $_, 0); } $state->{next_msg}; } @@ -461,19 +462,20 @@ sub html_footer { my $href = "mailto:$to?In-Reply-To=$irt&Cc=${cc}&Subject=$subj"; my $srch = $ctx->{srch} if $ctx; - my $idx = $standalone ? " index" : ''; + my $upfx = $full_pfx ? '../' : '../../'; + my $idx = $standalone ? "index" : ''; if ($idx && $srch) { - my $next = thread_inline(\$idx, $ctx, $mime); + my $next = thread_inline(\$idx, $ctx, $mime, $full_pfx); $irt = $mime->header('In-Reply-To'); if (defined $irt) { $irt = PublicInbox::Hval->new_msgid($irt); $irt = $irt->as_href; - $irt = "parent "; + $irt = "parent "; } else { $irt = ' ' x length('parent '); } if ($next) { - $irt .= "next "; + $irt .= "next "; } else { $irt .= ' '; } @@ -564,7 +566,7 @@ sub _msg_date { } sub _inline_header { - my ($dst, $state, $mime, $level) = @_; + my ($dst, $state, $upfx, $mime, $level) = @_; my $pfx = ' ' x $level; my $cur = $state->{cur}; @@ -601,7 +603,7 @@ sub _inline_header { $s = $s->as_html; } my $m = PublicInbox::Hval->new_msgid($mid); - $m = '../' . $m->as_href . '/'; + $m = $upfx . '../' . $m->as_href . '/'; if (defined $s) { $$dst .= "$pfx` $s\n" . "$pfx $f @ $d\n"; @@ -611,14 +613,14 @@ sub _inline_header { } sub inline_dump { - my ($dst, $state, $node, $level) = @_; + my ($dst, $state, $upfx, $node, $level) = @_; return unless $node; return if $state->{stopped}; if (my $mime = $node->message) { - _inline_header($dst, $state, $mime, $level); + _inline_header($dst, $state, $upfx, $mime, $level); } - inline_dump($dst, $state, $node->child, $level+1); - inline_dump($dst, $state, $node->next, $level); + inline_dump($dst, $state, $upfx, $node->child, $level+1); + inline_dump($dst, $state, $upfx, $node->next, $level); } 1; -- cgit v1.2.3-24-ge0c7