Skip to content

Commit

Permalink
[tag_list] fix sorting for tag lists, fixes #1355
Browse files Browse the repository at this point in the history
  • Loading branch information
shish committed Dec 14, 2024
1 parent 1f0ad73 commit 8b366b4
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions ext/tag_list/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ protected function get_tag_list_preamble(): HTMLElement
);
}

/**
* @param array<array{tag: string, count: int}> $tag_infos
* @param string[] $search
*/
private function get_tag_list_html(array $tag_infos, string $sort, array $search = []): HTMLElement
{
if ($sort === TagListConfig::SORT_ALPHABETICAL) {
usort($tag_infos, fn ($a, $b) => strcasecmp($a['tag'], $b['tag']));
}

$table = $this->get_tag_list_preamble();
foreach ($tag_infos as $row) {
$table->appendChild(self::build_tag_row($row, $search));
}
return $table;
}

/**
* @param array<array{tag: string, count: int}> $tag_infos
*/
Expand All @@ -43,7 +60,7 @@ public function display_split_related_block(Page $page, array $tag_infos): void
global $config;

if ($config->get_string(TagListConfig::RELATED_SORT) == TagListConfig::SORT_ALPHABETICAL) {
asort($tag_infos);
usort($tag_infos, fn ($a, $b) => strcasecmp($a['tag'], $b['tag']));
}

if (Extension::is_enabled(TagCategoriesInfo::KEY)) {
Expand All @@ -68,7 +85,7 @@ public function display_split_related_block(Page $page, array $tag_infos): void
$tag_categories_count[$category] += 1;
}

asort($tag_categories_html);
ksort($tag_categories_html);
foreach (array_keys($tag_categories_html) as $category) {
if ($category == '') {
$category_display_name = 'Tags';
Expand All @@ -84,23 +101,6 @@ public function display_split_related_block(Page $page, array $tag_infos): void
}
}

/**
* @param array<array{tag: string, count: int}> $tag_infos
* @param string[] $search
*/
private function get_tag_list_html(array $tag_infos, string $sort, array $search = []): HTMLElement
{
if ($sort == TagListConfig::SORT_ALPHABETICAL) {
asort($tag_infos);
}

$table = $this->get_tag_list_preamble();
foreach ($tag_infos as $row) {
$table->appendChild(self::build_tag_row($row, $search));
}
return $table;
}

/**
* @param array<array{tag: string, count: int}> $tag_infos
*/
Expand Down

0 comments on commit 8b366b4

Please sign in to comment.