Skip to content

Commit 6c91314

Browse files
authored
Merge pull request #2095 from Urgau/gha-logs-ts-anchors
Add self-referential anchors to every timestamps in our GHA logs viewer
2 parents 6d0c521 + b7df749 commit 6c91314

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/gha_logs.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ async fn process_logs(
129129
let nonce = Uuid::new_v4().to_hyphenated().to_string();
130130

131131
let html = format!(
132-
r#"<!DOCTYPE html>
132+
r##"<!DOCTYPE html>
133133
<html>
134134
<head>
135135
<title>{log_uuid} - triagebot</title>
@@ -143,22 +143,41 @@ async fn process_logs(
143143
color: #CCCCCC;
144144
white-space: pre;
145145
}}
146+
.timestamp {{
147+
color: unset;
148+
text-decoration: none;
149+
}}
150+
.timestamp:hover {{
151+
text-decoration: underline;
152+
}}
146153
</style>
147154
<script type="module" nonce="{nonce}">
148155
import {{ AnsiUp }} from '{ANSI_UP_URL}'
149156
150157
var logs = {logs};
151158
var ansi_up = new AnsiUp();
152159
160+
// 1. Tranform the ANSI escape codes to HTML
153161
var html = ansi_up.ansi_to_html(logs);
154162
163+
// 2. Remove UTF-8 useless BOM
164+
if (html.charCodeAt(0) === 0xFEFF) {{
165+
html = html.substr(1);
166+
}}
167+
168+
// 3. Add a self-referencial anchor to all timestamps at the start of the lines
169+
const dateRegex = /^(\d{{4}}-\d{{2}}-\d{{2}}T\d{{2}}:\d{{2}}:\d{{2}}\.\d+Z)/gm;
170+
html = html.replace(dateRegex, (ts) =>
171+
`<a id="${{ts}}" href="#${{ts}}" class="timestamp">${{ts}}</a>`
172+
);
173+
155174
var cdiv = document.getElementById("console");
156175
cdiv.innerHTML = html;
157176
</script>
158177
</head>
159178
<body id="console">
160179
</body>
161-
</html>"#,
180+
</html>"##,
162181
);
163182

164183
tracing::info!("gha_logs: serving logs for {log_uuid}");

0 commit comments

Comments
 (0)