Skip to content

Commit 96d377f

Browse files
authored
Merge pull request #2129 from GuillaumeGomez/improve-js
Reduce workload for web browser by removing all inline style
2 parents 61e05ec + dbb74ad commit 96d377f

File tree

3 files changed

+520
-60
lines changed

3 files changed

+520
-60
lines changed

src/gha_logs.rs

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::str::FromStr;
88
use std::sync::Arc;
99
use uuid::Uuid;
1010

11-
pub const ANSI_UP_URL: &str = "/gha_logs/ansi_up@6.0.6.min.js";
11+
pub const ANSI_UP_URL: &str = "/gha_logs/ansi_up@0.0.1-custom.js";
1212
pub const SUCCESS_URL: &str = "/gha_logs/[email protected]";
1313
pub const FAILURE_URL: &str = "/gha_logs/[email protected]";
1414

@@ -243,36 +243,58 @@ async fn process_logs(
243243
<title>{job_name} - {owner}/{repo}@{short_sha}</title>
244244
{icon_status}
245245
<style>
246-
body {{
247-
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
248-
background: #0C0C0C;
249-
color: #CCCCCC;
250-
white-space: pre;
251-
}}
252-
.timestamp {{
253-
color: #848484;
254-
text-decoration: none;
255-
}}
256-
.timestamp:hover {{
257-
text-decoration: underline;
258-
}}
259-
.error-marker {{
260-
scroll-margin-bottom: 15vh;
261-
color: #e5534b;
262-
}}
263-
.warning-marker {{
264-
color: #c69026;
265-
}}
266-
.path-marker {{
267-
color: #26c6a8;
268-
}}
246+
body {{
247+
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
248+
background: #0C0C0C;
249+
color: #CCC;
250+
white-space: pre;
251+
}}
252+
.timestamp {{
253+
color: #848484;
254+
text-decoration: none;
255+
}}
256+
.timestamp:hover {{
257+
text-decoration: underline;
258+
}}
259+
.error-marker {{
260+
scroll-margin-bottom: 15vh;
261+
color: #e5534b;
262+
}}
263+
.warning-marker {{
264+
color: #c69026;
265+
}}
266+
.path-marker {{
267+
color: #26c6a8;
268+
}}
269+
.ansi-black-fg {{ color: rgb(0, 0, 0); }}
270+
.ansi-red-fg {{ color: rgb(187, 0, 0); }}
271+
.ansi-green-fg {{ color: rgb(0, 187, 0); }}
272+
.ansi-yellow-fg {{ color: rgb(187, 187, 0); }}
273+
.ansi-blue-fg {{ color: rgb(0, 0, 187); }}
274+
.ansi-magenta-fg {{ color: rgb(187, 0, 187); }}
275+
.ansi-cyan-fg {{ color: rgb(0, 187, 187); }}
276+
.ansi-white-fg {{ color: rgb(255, 255, 255); }}
277+
.ansi-bright-black-fg {{ color: rgb(85, 85, 85); }}
278+
.ansi-bright-red-fg {{ color: rgb(255, 85, 85); }}
279+
.ansi-bright-green-fg {{ color: rgb(0, 255, 0); }}
280+
.ansi-bright-yellow-fg {{ color: rgb(255, 255, 85); }}
281+
.ansi-bright-blue-fg {{ color: rgb(85, 85, 255); }}
282+
.ansi-bright-magenta-fg {{ color: rgb(255, 85, 255); }}
283+
.ansi-bright-cyan-fg {{ color: rgb(85, 255, 255); }}
284+
.ansi-bright-white-fg {{ color: rgb(255, 255, 255); }}
285+
286+
.bold {{ font-weight: bold; }}
287+
.faint {{ opacity: 0.7; }}
288+
.italic {{ font-style: italic; }}
289+
.underline {{ text-decoration: underline; }}
269290
</style>
270291
<script type="module" nonce="{nonce}">
271292
import {{ AnsiUp }} from '{ANSI_UP_URL}'
272293
273-
var logs = {logs};
274-
var tree_roots = {tree_roots};
275-
var ansi_up = new AnsiUp();
294+
const logs = {logs};
295+
const tree_roots = {tree_roots};
296+
const ansi_up = new AnsiUp();
297+
ansi_up.use_classes = true;
276298
277299
// 1. Tranform the ANSI escape codes to HTML
278300
var html = ansi_up.ansi_to_html(logs);
@@ -324,9 +346,8 @@ async fn process_logs(
324346
}});
325347
326348
// 6. Add the html to the DOM
327-
var cdiv = document.getElementById("console");
328-
cdiv.innerHTML = html;
329-
349+
document.body.innerHTML = html;
350+
330351
// 7. If no anchor is given, scroll to the last error
331352
if (location.hash === "" && errorCounter >= 0) {{
332353
const hasSmallViewport = window.innerWidth <= 750;
@@ -338,7 +359,7 @@ async fn process_logs(
338359
}}
339360
</script>
340361
</head>
341-
<body id="console">
362+
<body>
342363
</body>
343364
</html>"###,
344365
);
@@ -358,7 +379,7 @@ async fn process_logs(
358379
}
359380

360381
pub fn ansi_up_min_js() -> anyhow::Result<Response<Body>, hyper::Error> {
361-
const ANSI_UP_MIN_JS: &str = include_str!("gha_logs/ansi_up@6.0.6.min.js");
382+
const ANSI_UP_MIN_JS: &str = include_str!("gha_logs/ansi_up@0.0.1-custom.js");
362383

363384
Ok(Response::builder()
364385
.status(StatusCode::OK)

0 commit comments

Comments
 (0)