2 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # Generates NEWS, NEWS.atom, and NEWS.html files using release emails
5 # this uses unstable internal APIs of public-inbox, and this script
6 # needs to be updated if they change.
11 use PublicInbox::MsgTime qw(msg_datestamp);
12 use PublicInbox::MID qw(mids mid_escape);
13 my $dst = shift @ARGV or die "Usage: $0 <NEWS|NEWS.atom|NEWS.html>";
17 my $dir = 'Documentation/RelNotes';
18 my $base_url = 'https://public-inbox.org/meta';
19 my $html_url = 'https://public-inbox.org/NEWS.html';
20 my $atom_url = 'https://public-inbox.org/NEWS.atom';
21 my $addr = 'meta@public-inbox.org';
23 my $latest = shift(@releases) or die 'no releases?';
24 my $mime_latest = release2mime($latest);
25 my $mtime = msg_datestamp($mime_latest->header_obj);
29 open $out, '>', $tmp or die;
30 mime2txt($out, $mime_latest);
31 for my $v (@releases) {
32 print $out "\n" or die;
33 mime2txt($out, release2mime($v));
35 } elsif ($dst eq 'NEWS.atom' || $dst eq 'NEWS.html') {
36 open $out, '>', $tmp or die;
37 my $ibx = Plack::Util::inline_object(
38 description => sub { 'public-inbox releases' },
39 over => sub { undef },
40 search => sub { 1 }, # for WwwStream:_html_top
41 base_url => sub { "$base_url/" },
43 $ibx->{-primary_address} = $addr;
46 -upfx => "$base_url/",
49 if ($dst eq 'NEWS.html') {
50 html_start($out, $ctx);
51 mime2html($out, $mime_latest, $ctx);
52 while (defined(my $v = shift(@releases))) {
53 mime2html($out, release2mime($v), $ctx);
56 } elsif ($dst eq 'NEWS.atom') {
57 my $astream = atom_start($out, $ctx, $mtime);
58 for my $v (reverse(@releases)) {
59 mime2atom($out, $astream, release2mime($v), $ctx);
61 mime2atom($out, $astream, $mime_latest, $ctx);
62 print $out '</feed>' or die;
64 die "BUG: Unrecognized $dst\n";
67 die "Unrecognized $dst\n";
71 utime($mtime, $mtime, $tmp) or die;
72 rename($tmp, $dst) or die;
76 my $f = "$dir/$_[0].eml";
77 open(my $fh, '<', $f) or die "open($f): $!";
78 PublicInbox::MIME->new(do { local $/; <$fh> });
82 my ($out, $mime) = @_;
83 my $title = $mime->header_str('Subject');
84 $title =~ s/^\s*\[\w+\]\s*//g; # [ANNOUNCE] or [ANN]
85 my $dtime = msg_datestamp($mime->header_obj);
86 $title .= ' - ' . PublicInbox::View::fmt_ts($dtime) . ' UTC';
87 print $out $title, "\n" or die;
88 my $uline = '=' x length($title);
89 print $out $uline, "\n\n" or die;
91 my $mid = mids($mime)->[0];
92 print $out 'Link: ', $base_url, '/', mid_escape($mid), "/\n\n" or die;
93 print $out $mime->body_str or die;
97 my ($out, $mime, $ctx) = @_;
98 my $smsg = bless { mime => $mime }, 'PublicInbox::SearchMsg';
99 print $out PublicInbox::View::index_entry($smsg, $ctx, 1) or die;
103 my ($out, $ctx) = @_;
104 require PublicInbox::WwwStream;
105 $ctx->{www} = Plack::Util::inline_object(style => sub { '' });
106 my $www_stream = PublicInbox::WwwStream->new($ctx);
107 print $out $www_stream->_html_top, '<pre>' or die;
111 print $out <<EOF or die;
112 git clone $PublicInbox::WwwStream::CODE_URL
118 my ($out, $ctx, $mtime) = @_;
119 require PublicInbox::WwwAtomStream;
120 # WwwAtomStream stats this dir for mtime
121 my $astream = PublicInbox::WwwAtomStream->new($ctx);
122 delete $ctx->{emit_header};
123 my $ibx = $ctx->{-inbox};
124 my $title = PublicInbox::WwwAtomStream::title_tag($ibx->description);
125 my $updated = PublicInbox::WwwAtomStream::feed_updated(gmtime($mtime));
126 print $out <<EOF or die;
127 <?xml version="1.0" encoding="us-ascii"?>
129 xmlns="http://www.w3.org/2005/Atom"
130 xmlns:thr="http://purl.org/syndication/thread/1.0">$title<link
133 href="$html_url"/><link
135 href="$atom_url"/><id>$atom_url</id>$updated
141 my ($out, $astream, $mime, $ctx) = @_;
142 my $smsg = bless { mime => $mime }, 'PublicInbox::SearchMsg';
143 if (defined(my $str = $astream->feed_entry($smsg))) {
144 print $out $str or die;