word: restrict by priority level
authorMischa POSLAWSKY <perl@shiar.org>
Fri, 29 May 2020 05:14:37 +0000 (07:14 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Sat, 6 Jun 2020 01:49:20 +0000 (03:49 +0200)
Default to commonly known concepts (level 3) unless overridden by ?v.

tools/mkwordlist
tools/word.pg.sql
word.plp

index d4dfaa245cf8e28e563b4bc4c47f9ca64aefdecd..5e965fed73c4894740d12fb4f4a849756171f8d8 100755 (executable)
@@ -1,4 +1,4 @@
 #!/bin/sh
 psql sheet -XAt -c "
        SELECT json_object_agg(coalesce(form, ''), forms) FROM _cat_words
-" | sed 's/:/=>/g'
+" | sed 's/ : / => /g'
index 22ff113cc86d1c5a8850ad33a5f188392017e6f0..1dc4f5bc68c8b3ed107967e6c69b9eaaa8a9d613 100644 (file)
@@ -25,7 +25,10 @@ COMMENT ON COLUMN word.thumb      IS 'ImageMagick convert options to create thum
 COMMENT ON COLUMN word.wptitle    IS 'reference Wikipedia article';
 
 CREATE OR REPLACE FUNCTION exportform(word) RETURNS text AS $$
-       SELECT (CASE WHEN $1.cover THEN '*' ELSE '' END) || array_to_string($1.form || $1.alt, '/');
+       SELECT concat(
+               $1.prio || CASE WHEN $1.cover THEN 'c' ELSE '' END || ':',
+               array_to_string($1.form || $1.alt, '/')
+       );
 $$ LANGUAGE SQL IMMUTABLE;
 
 CREATE OR REPLACE VIEW _cat_words AS
index dd5985aee07a33eea02901a6bb4ddac3efabb85e..ac596b5969d1de15d064dc77f9f22276451af8b1 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,8 @@
 <(common.inc.plp)><:
 
 my $wordlist = 'wordlist.eng.inc.pl';
+my $limit = $get{v} // (exists $get{v} ? 4 : 3);
+
 Html({
        title => 'words cheat sheet',
        version => '1.0',
@@ -61,7 +63,6 @@ figure:hover > figcaption {
 </style>
 EOT
 });
-
 :>
 <h1>Words</h1>
 
@@ -92,11 +93,13 @@ sub showimg {
 sub printimgs {
        say '<ul>';
        for my $row (@_) {
+               my ($level, $mark, $title) = split /([a-z]*):/, $row, 2;
                my @type;
                push @type, 'parent' if defined $table->{$row};
-               push @type, 'large'  if $row =~ /^\*/;
+               push @type, 'large'  if $mark;
+               push @type, 'level'.($level || 0);
                printf '<li%s>', @type ? sprintf ' class="%s"', join ' ', @type : '';
-               print showimg($row =~ s/^\*//r);
+               print showimg($title) if $level <= $limit;
                printimgs(@{$_}) for $table->{$row} // ();
                print '</li>';
        }