+ my $max = $ctx->{max} || MAX_PER_PAGE;
+
+ my $title = ascii_html($feed_opts->{description} || '');
+ my ($footer, $param, $last);
+ my $state = { ctx => $ctx, seen => {}, anchor_idx => 0, fh => $fh };
+ my $srch = $ctx->{srch};
+
+ my $top = "<b>$title</b> (<a\nhref=\"new.atom\">Atom feed</a>)";
+
+ if ($srch) {
+ $top = qq{<form\naction=""><pre>$top} .
+ qq{ <input\nname=q\ntype=text />} .
+ qq{<input\ntype=submit\nvalue=search />} .
+ q{</pre></form><pre>}
+ } else {
+ $top = '<pre>' . $top . "\n";
+ }
+
+ $fh->write("<html><head><title>$title</title>" .
+ "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
+ "href=\"new.atom\"\ntype=\"application/atom+xml\"/>" .
+ PublicInbox::Hval::STYLE .
+ "</head><body>$top");
+
+ # if the 'r' query parameter is given, it is a legacy permalink
+ # which we must continue supporting:
+ my $cgi = $ctx->{cgi};
+ if ($cgi && !$cgi->param('r') && $srch) {
+ $state->{srch} = $srch;
+ $last = PublicInbox::View::emit_index_topics($state);
+ $param = 'o';
+ } else {
+ $last = emit_index_nosrch($ctx, $state);
+ $param = 'r';
+ }
+ $footer = nav_footer($cgi, $last, $feed_opts, $state, $param);