Browse Source

bin/notes-tag-summary: check if tag is in pinboard index

main
Brennen Bearnes 5 months ago
parent
commit
506574901d
1 changed files with 36 additions and 2 deletions
  1. +36
    -2
      home/bin/notes-tag-summary

+ 36
- 2
home/bin/notes-tag-summary View File

@ -23,6 +23,7 @@ use warnings;
use strict;
use 5.10.0;
use Carp;
use Cwd;
use Data::Dumper;
use DBI;
@ -65,6 +66,28 @@ my $HOME = File::HomeDir->my_home;
}
}
sub on_pinboard {
state %lines = map { $_ => 1 } file_get_contents_arr(
File::Spec->catfile($HOME, 'notes', 'pinboard-tag-index')
);
my ($tag) = @_;
return exists $lines{$tag};
}
sub file_get_contents_arr {
my ($file) = @_;
open my $fh, '<', $file
or croak "Couldn't open $file: $!\n";
chomp(my @lines = <$fh>);
close $fh or croak "Couldn't close $file: $!";
return @lines;
}
# Total count of pages that link to this tag:
my $link_count = query_onerow(
'SELECT COUNT(*) AS COUNT FROM links WHERE target = ?',
@ -73,12 +96,18 @@ my $link_count = query_onerow(
# Count of pages that link to this tag and are log entries:
my $log_count = query_onerow(
'SELECT COUNT(*) AS COUNT FROM links WHERE target = ? AND page LIKE "log/%"',
'SELECT COUNT(*) AS COUNT FROM links WHERE target = ? AND page LIKE "log/%"',
$tag
)->{COUNT};
my @display_pages;
my $pages_sth = query('SELECT page FROM links WHERE target = ? AND page NOT LIKE "log/%" AND PAGE NOT LIKE "diary/%"', $tag);
my $pages_sth = query(
'SELECT page FROM links
WHERE target = ?
AND page NOT LIKE "log/%"
AND PAGE NOT LIKE "diary/%"',
$tag
);
while (my $row = $pages_sth->fetchrow_hashref()) {
push @display_pages, $row->{page};
}
@ -90,6 +119,11 @@ print "\n";
say "${bg}pages$reset: " . join ' ', @display_pages;
print "\n";
if (on_pinboard($tag)) {
say "${bg}on pinboard${reset}";
print "\n";
}
my $wikifile = File::Spec->catfile($HOME, 'notes', 'vimwiki', "$tag.wiki");
if (-f $wikifile) {
print `head $wikifile`;


Loading…
Cancel
Save