Skip to content

Commit 7b28e6f

Browse files
zulip encode topic links
1 parent d39f1c9 commit 7b28e6f

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

site/zulip_script.html

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
<script>
2+
function zulipEncodeTopic(topic) {
3+
return Array.from(topic).map(ch => {
4+
const code = ch.charCodeAt(0);
5+
if (
6+
(code >= 48 && code <= 57) || // 0-9
7+
(code >= 65 && code <= 90) || // A-Z
8+
(code >= 97 && code <= 122) // a-z
9+
) {
10+
return ch;
11+
} else {
12+
return "." + code.toString(16).toUpperCase().padStart(2, "0");
13+
}
14+
}).join("");
15+
}
16+
217
document.addEventListener('DOMContentLoaded', (event) => {
318
const zulipOrg = "clojurians.zulipchat.com";
4-
const zulipChannel = "clojurecivitas";
5-
const title =
6-
document.querySelector('#title-block-header h1.title')?.textContent.trim();
19+
const zulipChannel = "528764-clojurecivitas";
20+
const title = document.querySelector('#title-block-header h1.title')?.textContent.trim();
721

822
if (title) {
9-
const encodedTitle = encodeURIComponent(title);
10-
const zulipURL = `https://${zulipOrg}/#narrow/stream/${zulipChannel}/topic/${encodedTitle}`;
23+
const encodedTitle = zulipEncodeTopic(title);
24+
const zulipURL = `https://${zulipOrg}/#narrow/channel/${zulipChannel}/topic/${encodedTitle}`;
1125
const linkHTML = `<p><a href="${zulipURL}">Discuss ${title} on Zulip</a></p>`;
1226
document.getElementById('quarto-content').insertAdjacentHTML('beforeend', linkHTML);
1327
}

0 commit comments

Comments
 (0)