Skip to content

Commit e982562

Browse files
committed
Move all inline style to dedicated endpoint
We rendered the <style> within the <body> which is not valid. By moving it to a dedicated endpoint we also save a bit of bandwith as this is content which stays static during the contest.
1 parent 0891e22 commit e982562

File tree

6 files changed

+43
-19
lines changed

6 files changed

+43
-19
lines changed

.github/jobs/webstandard.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ if [ "$TEST" = "w3cval" ]; then
113113
unzip -q vnu.linux.zip
114114
section_end
115115
116-
FLTR='--filterpattern .*autocomplete.*|.*style.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*|.*obsolete.*'
116+
FLTR='--filterpattern .*autocomplete.*|.*role=tab.*|.*descendant.*|.*Stray.*|.*attribute.*|.*Forbidden.*|.*stream.*|.*obsolete.*'
117117
for typ in html css svg
118118
do
119119
section_start "Analyse with $typ"

webapp/src/Controller/PublicController.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ public function scoreboardDataZipAction(
100100
return $this->dj->getScoreboardZip($request, $requestStack, $contest, $this->scoreboardService);
101101
}
102102

103+
#[Route(path: '/scoreboard-category-color.css', name: 'scoreboard_category_color_css')]
104+
public function scoreboardCategoryColorCss(Request $request): Response {
105+
$content = $this->renderView('public/scoreboard_category_color.css.twig', $this->dj->getScoreboardCategoryColorCss());
106+
$response = new Response();
107+
$response->headers->set('Content-Type', 'text/css');
108+
// See: https://symfony.com/doc/current/http_cache/validation.html
109+
$response->setEtag(md5($content));
110+
$response->setPublic();
111+
$response->isNotModified($request);
112+
$response->setContent($content);
113+
return $response;
114+
}
115+
103116
/**
104117
* Get the contest from the request, if any
105118
*/

webapp/src/Service/DOMJudgeService.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use App\Entity\Submission;
2828
use App\Entity\Team;
2929
use App\Entity\TeamAffiliation;
30+
use App\Entity\TeamCategory;
3031
use App\Entity\Testcase;
3132
use App\Entity\User;
3233
use App\Utils\FreezeData;
@@ -1532,6 +1533,15 @@ public function getScoreboardZip(
15321533
return Utils::streamZipFile($tempFilename, 'scoreboard.zip');
15331534
}
15341535

1536+
/**
1537+
* @return array{'backgroundColors', array<TeamCategory>}
1538+
*/
1539+
public function getScoreboardCategoryColorCss(): array {
1540+
$backgroundColors = array_map(fn($x) => ( $x->getColor() ?? '#FFFFFF' ), $this->em->getRepository(TeamCategory::class)->findAll());
1541+
$backgroundColors = array_merge($backgroundColors, ['#FFFF99']);
1542+
return ['backgroundColors' => $backgroundColors];
1543+
}
1544+
15351545
private function allowJudge(ContestProblem $problem, Submission $submission, Language $language, bool $manualRequest): bool
15361546
{
15371547
if (!$problem->getAllowJudge() || !$language->getAllowJudge()) {

webapp/templates/base.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<link rel="stylesheet" href="{{ asset("css/bootstrap.min.css") }}">
1111
<link rel="stylesheet" href="{{ asset("css/fontawesome-all.min.css") }}">
12+
<link rel="stylesheet" href="{{ path('scoreboard_category_color_css') }}">
1213
<script src="{{ asset("js/jquery.min.js") }}"></script>
1314
<script src="{{ asset("js/jquery.debounce.min.js") }}"></script>
1415
<script src="{{ asset("js/bootstrap.bundle.min.js") }}"></script>

webapp/templates/partials/scoreboard_table.html.twig

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -581,24 +581,6 @@
581581
{% endif %}
582582
{% endif %}
583583
584-
<style>
585-
{% for color,i in backgroundColors %}
586-
{% set colorClass = color | replace({"#": "_"}) %}
587-
588-
.cl{{ colorClass }} {
589-
background-color: {{ color }};
590-
}
591-
592-
{% set cMin = color|hexColorToRGBA(0) %}
593-
{% set cMax = color|hexColorToRGBA(1) %}
594-
595-
.cl{{ colorClass }} .forceWidth.toolong:after {
596-
background: linear-gradient(to right,
597-
{{ cMin }} 0%,
598-
{{ cMax }} 96%);
599-
}
600-
{% endfor %}
601-
</style>
602584
<script>
603585
document.querySelectorAll(".forceWidth:not(.toolong)").forEach(el => {
604586
if (el instanceof Element && el.scrollWidth > el.offsetWidth) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{% autoescape false %}
2+
{% for i,color in backgroundColors %}
3+
{% set colorClass = color | replace({"#": "_"}) %}
4+
5+
.cl{{ colorClass }} {
6+
background-color: {{ color }};
7+
}
8+
9+
{% set cMin = color|hexColorToRGBA(0) %}
10+
{% set cMax = color|hexColorToRGBA(1) %}
11+
12+
.cl{{ colorClass }} .forceWidth.toolong:after {
13+
background: linear-gradient(to right,
14+
{{ cMin }} 0%,
15+
{{ cMax }} 96%);
16+
}
17+
{% endfor %}
18+
{% endautoescape %}

0 commit comments

Comments
 (0)