diff options
author | Yorhel <git@yorhel.nl> | 2022-09-23 13:19:56 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2022-09-28 09:35:55 +0200 |
commit | 91b1931420806c661210f3f8299846eade131686 (patch) | |
tree | 9b2cc1b27f20e017f56e76795db0880b5cb10e02 /lib/VNWeb/Releases | |
parent | fc923381de7dfed7de0969c35a5e010bd6055417 (diff) |
Display preferred release title on VN pages + do that selection in Perl
Having a Perl implementation of the title selection algortihm saves a
round-trip to the database for some pages.
Diffstat (limited to 'lib/VNWeb/Releases')
-rw-r--r-- | lib/VNWeb/Releases/Lib.pm | 5 | ||||
-rw-r--r-- | lib/VNWeb/Releases/Page.pm | 7 |
2 files changed, 6 insertions, 6 deletions
diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm index ecf643c9..2629207c 100644 --- a/lib/VNWeb/Releases/Lib.pm +++ b/lib/VNWeb/Releases/Lib.pm @@ -1,6 +1,7 @@ package VNWeb::Releases::Lib; use VNWeb::Prelude; +use VNWeb::LangPref 'langpref_titles'; use Exporter 'import'; our @EXPORT = qw/enrich_release_elm releases_by_vn enrich_release sort_releases release_row_/; @@ -156,8 +157,8 @@ sub release_row_ { abbr_ class => "icons rt$r->{rtype}", title => $r->{rtype}, ''; }; td_ class => 'tc4', sub { - # TODO: Read user preferences to see whether to display the 'title' or 'latin' here. - a_ href => "/$r->{id}", title => $lang ? $lang->{latin} : $r->{alttitle}||$r->{title}, $lang ? $lang->{title} : $r->{title}; + my($title, $alttitle) = $lang ? langpref_titles $lang->{lang}, [$lang] : @{$r}{'title', 'alttitle'}; + a_ href => "/$r->{id}", title => $alttitle||$title, $title; my $note = join ' ', $r->{official} ? () : 'unofficial', $mtl ? 'machine translation' : (), $r->{patch} ? 'patch' : (); b_ class => 'grayedout', " ($note)" if $note; }; diff --git a/lib/VNWeb/Releases/Page.pm b/lib/VNWeb/Releases/Page.pm index cbbfd4c1..5a63ff14 100644 --- a/lib/VNWeb/Releases/Page.pm +++ b/lib/VNWeb/Releases/Page.pm @@ -2,7 +2,7 @@ package VNWeb::Releases::Page; use VNWeb::Prelude; use VNWeb::Releases::Lib; -use VNWeb::LangPref 'sql_releases_hist'; +use VNWeb::LangPref 'langpref_titles'; sub enrich_item { @@ -11,7 +11,7 @@ sub enrich_item { enrich_merge pid => 'SELECT id AS pid, name, original FROM producers WHERE id IN', $r->{producers}; enrich_merge vid => 'SELECT id AS vid, title, alttitle FROM vnt WHERE id IN', $r->{vn}; - $r->{titles} = [ sort { ($a->{mtl}?1:0) <=> ($b->{mtl}?1:0) || $a->{lang} cmp $b->{lang} } $r->{titles}->@* ]; + $r->{titles} = [ sort { ($b->{lang} eq $r->{olang}) cmp ($a->{lang} eq $r->{olang}) || ($a->{mtl}?1:0) <=> ($b->{mtl}?1:0) || $a->{lang} cmp $b->{lang} } $r->{titles}->@* ]; $r->{platforms} = [ sort map $_->{platform}, $r->{platforms}->@* ]; $r->{vn} = [ sort { $a->{title} cmp $b->{title} || idcmp($a->{vid}, $b->{vid}) } $r->{vn}->@* ]; $r->{producers} = [ sort { $a->{name} cmp $b->{name} || idcmp($a->{pid}, $b->{pid}) } $r->{producers}->@* ]; @@ -268,8 +268,7 @@ TUWF::get qr{/$RE{rrev}} => sub { my $r = db_entry tuwf->captures('id','rev'); return tuwf->resNotFound if !$r; - enrich_merge chid => sql('SELECT chid, x.title, x.alttitle FROM (', sql_releases_hist(), ') x WHERE chid IN'), $r if $r->{chrev} != $r->{maxrev}; - enrich_merge id => sql('SELECT id, title, alttitle FROM releasest WHERE id IN'), $r if $r->{chrev} == $r->{maxrev}; + @{$r}{'title', 'alttitle'} = langpref_titles $r->{olang}, $r->{titles}; enrich_item $r; enrich_extlinks r => $r; |