word: identify rows by id number
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 15 Jun 2020 22:34:40 +0000 (00:34 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 20 Oct 2020 20:49:11 +0000 (22:49 +0200)
With the addition of more entries, names are no longer unique:
for example pink (colour and flower) in multiple categories.

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

index b88cd1bdd1adf23a525f7c6715f541864d2e0617..e1729a380bf99b624bc1369e0d3633a14f9d1d4a 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
 echo 'use utf8;'
 psql sheet -XAt -c "
-       SELECT json_object_agg(coalesce(form, ''), forms) FROM _cat_words
+       SELECT json_object_agg(coalesce(id::text, ''), forms) FROM _cat_words
 " | sed 's/ : / => /g'
index 3a0f158b5124f6dcd2d26590c61955ca4224471d..3c05c3865b6405ca4d00330d826053b67a65df18 100644 (file)
@@ -42,7 +42,8 @@ COMMENT ON COLUMN word.creator    IS 'user responsible for initial submit';
 
 CREATE OR REPLACE FUNCTION exportform(word) RETURNS text AS $$
        SELECT concat(
-               $1.prio || CASE WHEN $1.cover THEN 'c' ELSE '' END || ':',
+               $1.id, ':',
+               $1.prio, CASE WHEN $1.cover THEN 'c' ELSE '' END, ':',
                array_to_string($1.form || $1.alt, '/')
        );
 $$ LANGUAGE SQL IMMUTABLE;
index 1af9c75cc9075bc496d739b688f57a444552c270..78e46a573afb3806fc59b39b6512438554345b28 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -55,19 +55,19 @@ sub showimg {
 sub printimgs {
        say '<ul>';
        for my $row (@_) {
-               my ($level, $mark, $title) = split /([a-z]*):/, $row, 2;
+               my ($id, $level, $title) = split /:/, $row, 3;
                my @type;
-               push @type, 'parent' if defined $table->{$row};
-               push @type, 'large'  if $mark;
+               push @type, 'parent' if defined $table->{$id};
+               push @type, 'large'  if $level =~ s/c$//;
                push @type, 'level'.($level || 0);
                printf '<li%s>', @type ? sprintf ' class="%s"', join ' ', @type : '';
                print showimg($title) if $level <= $limit;
-               printimgs(@{$_}) for $table->{$row} // ();
+               printimgs(@{$_}) for $table->{$id} // ();
                print '</li>';
        }
        say '</ul>';
 }
 
 say '<section class="gallery">';
-printimgs(@{$table->{''}});
+printimgs($table->{''}->[0]);
 say '</section>';