Refactor hash function for tag background color calculation

Changed the hashing algorithm used to calculate tag background colors in the Twig extension.
This commit is contained in:
Jeroen De Meerleer 2024-05-22 11:25:18 +02:00
parent 4b3c4f1755
commit 67df2666a6
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6

View File

@ -52,7 +52,7 @@ class AppExtension extends AbstractExtension
$results = [];
preg_match_all('/\[([A-Za-z0-9 \-]+)\]/', $text, $results);
foreach ($results[0] as $key=>$result) {
$background = substr(md5($results[0][$key]), 0, 6);
$background = substr(hash('murmur3a', $results[0][$key]), 0, 6);
$color = $this->lightOrDark($background) == 'dark' ? 'ffffff' : '000000';
$text = str_replace($results[0][$key], '<span class="tag" data-background-color="#' . $background . '" data-color="#' . $color . '">' . $results[1][$key] . '</span>', $text);
}