1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # *-extinbox commands of lei
5 package PublicInbox::LeiExtinbox;
8 use parent qw(Exporter);
9 our @EXPORT = qw(lei_ls_extinbox lei_add_extinbox lei_forget_extinbox);
12 my ($self, @argv) = @_;
13 my $stor = $self->_lei_store(0);
14 my $cfg = $self->_lei_cfg(0);
16 my ($OFS, $ORS) = $self->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
18 for my $sec (grep(/\Aextinbox\./, @{$cfg->{-section_order}})) {
19 my $loc = substr($sec, length('extinbox.'));
20 $boost{$loc} = $cfg->{"$sec.boost"};
24 # highest boost first, but stable for alphabetic tie break
25 for (sort { $boost{$b} <=> $boost{$a} } sort keys %boost) {
26 # TODO: use miscidx and show docid so forget/set is easier
27 print $out $_, $OFS, 'boost=', $boost{$_}, $ORS;
31 sub lei_add_extinbox {
32 my ($self, $url_or_dir) = @_;
33 my $cfg = $self->_lei_cfg(1);
34 if ($url_or_dir !~ m!\Ahttps?://!) {
35 $url_or_dir = File::Spec->canonpath($url_or_dir);
37 my $new_boost = $self->{opt}->{boost} // 0;
38 my $key = "extinbox.$url_or_dir.boost";
39 my $cur_boost = $cfg->{$key};
40 return if defined($cur_boost) && $cur_boost == $new_boost; # idempotent
41 $self->lei_config($key, $new_boost);
42 my $stor = $self->_lei_store(1);
43 # TODO: add to MiscIdx
47 sub lei_forget_extinbox {