Skip to content

Commit a0f9cd3

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 e596a3b commit a0f9cd3

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ public function scoreboardDataZipAction(
100100
return $this->dj->getScoreboardZip($request, $requestStack, $contest, $this->scoreboardService);
101101
}
102102

103+
#[Route(path: '/dynamic-css', name: 'get_dynamic_css')]
104+
public function dynamicCSS(): Response {
105+
$response = new Response();
106+
$response->headers->set('Content-Type', 'text/css');
107+
$response->setContent($this->renderView('public/dynamic.css.twig', $this->dj->getDynamicCSS()));
108+
return $response;
109+
}
110+
103111
/**
104112
* Get the contest from the request, if any
105113
*/

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 getDynamicCSS(): 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('get_dynamic_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
@@ -578,24 +578,6 @@
578578
{% endif %}
579579
{% endif %}
580580
581-
<style>
582-
{% for color,i in backgroundColors %}
583-
{% set colorClass = color | replace({"#": "_"}) %}
584-
585-
.cl{{ colorClass }} {
586-
background-color: {{ color }};
587-
}
588-
589-
{% set cMin = color|hexColorToRGBA(0) %}
590-
{% set cMax = color|hexColorToRGBA(1) %}
591-
592-
.cl{{ colorClass }} .forceWidth.toolong:after {
593-
background: linear-gradient(to right,
594-
{{ cMin }} 0%,
595-
{{ cMax }} 96%);
596-
}
597-
{% endfor %}
598-
</style>
599581
<script>
600582
document.querySelectorAll(".forceWidth:not(.toolong)").forEach(el => {
601583
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)