-
Notifications
You must be signed in to change notification settings - Fork 235
Expand file tree
/
Copy pathshared.js
More file actions
197 lines (175 loc) · 6.68 KB
/
Copy pathshared.js
File metadata and controls
197 lines (175 loc) · 6.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
function insertLogo() {
const path = window.location.pathname;
const isHomePage = path === '/' || path === '/index.html';
let logoHTML = `
<div class="logo-line">
<span class="edge-logo-symbol">+</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">~</span>
<span class="edge-logo-symbol">*</span>
</div>
<div class="logo-line">
<span class="vertical-logo-symbol">|</span>
<span class="logo-text"> commonware </span>
<span class="vertical-logo-symbol"> </span>
</div>
<div class="logo-line">
<span class="edge-logo-symbol">*</span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">~</span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">+</span>
<span class="horizontal-logo-symbol"> </span>
<span class="horizontal-logo-symbol">-</span>
<span class="horizontal-logo-symbol">*</span>
<span class="horizontal-logo-symbol">-</span>
<span class="edge-logo-symbol">+</span>
</div>
`;
if (!isHomePage) {
// Wrap the logo in an anchor tag linking back to the homepage
logoHTML = `
<a href="/index.html" class="logo-link">
${logoHTML}
</a>
`;
}
document.getElementById('logo-placeholder').innerHTML = logoHTML;
initializeLogoAnimations();
}
function initializeLogoAnimations() {
const horizontalSymbols = [" ", "*", "+", "-", "~"];
const verticalSymbols = [" ", "*", "+", "|"];
const edgeSymbols = [" ", "*", "+"];
function getRandomItem(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
function getRandomDuration(min) {
return Math.random() * (10000 - min) + min;
}
function updateSymbol(symbol, choices) {
symbol.innerText = getRandomItem(choices);
setTimeout(() => updateSymbol(symbol, choices), getRandomDuration(500));
}
document.querySelectorAll('.horizontal-logo-symbol').forEach(symbol => {
setTimeout(() => updateSymbol(symbol, horizontalSymbols), getRandomDuration(1500));
});
document.querySelectorAll('.vertical-logo-symbol').forEach(symbol => {
setTimeout(() => updateSymbol(symbol, verticalSymbols), getRandomDuration(1500));
});
document.querySelectorAll('.edge-logo-symbol').forEach(symbol => {
setTimeout(() => updateSymbol(symbol, edgeSymbols), getRandomDuration(1500));
});
}
function setExternalLinksToOpenInNewTab() {
for (const link of document.querySelectorAll('a')) {
const href = link.getAttribute('href');
if (href && href.startsWith('http')) {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
}
}
}
function insertFooter() {
// If the footer placeholder doesn't exist, skip footer insertion.
const footerPlaceholder = document.getElementById('footer-placeholder');
if (!footerPlaceholder) {
return;
}
// Insert the footer.
const currentYear = new Date().getFullYear();
const footerHTML = `
<div class="footer">
<div class="socials">
<a href="https://github.com/commonwarexyz/monorepo">GitHub</a>
<a href="/benchmarks.html">Benchmarks</a>
<a href="/mcp.html">MCP</a>
<a href="/hiring.html">Hiring</a>
<a href="https://x.com/commonwarexyz">X</a>
<a href="/podcast.html">Podcast</a>
</div>
© ${currentYear} Commonware, Inc. All rights reserved.
</div>
`;
footerPlaceholder.innerHTML = footerHTML;
}
// Trim leading and trailing blank lines from all <pre><code> blocks
function trimCode() {
const codeBlocks = document.querySelectorAll('pre code');
for (const block of codeBlocks) {
const lines = block.innerHTML.split('\n');
// Remove leading blank lines
while (lines.length > 0 && lines[0].trim() === '') {
lines.shift();
}
// Remove trailing blank lines
while (lines.length > 0 && lines[lines.length - 1].trim() === '') {
lines.pop();
}
block.innerHTML = lines.join('\n');
// Remove whitespace text nodes between <pre> and <code>
const pre = block.parentElement;
if (pre && pre.tagName === 'PRE') {
for (const child of [...pre.childNodes]) {
if (child.nodeType === Node.TEXT_NODE) {
pre.removeChild(child);
}
}
}
}
}
// Open figure images in a zoomable modal when clicked
function initializeImageZoom() {
const images = document.querySelectorAll('.image-container img');
if (images.length === 0) {
return;
}
// Build the modal overlay once and reuse it for every image.
const overlay = document.createElement('div');
overlay.className = 'image-modal';
const overlayImg = document.createElement('img');
overlayImg.alt = '';
overlay.appendChild(overlayImg);
document.body.appendChild(overlay);
function close() {
overlay.classList.remove('open');
document.body.style.overflow = '';
}
for (const img of images) {
img.style.cursor = 'zoom-in';
img.addEventListener('click', () => {
overlayImg.src = img.currentSrc || img.src;
overlayImg.alt = img.alt;
overlay.classList.add('open');
document.body.style.overflow = 'hidden';
});
}
overlay.addEventListener('click', close);
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && overlay.classList.contains('open')) {
close();
}
});
}
// Load the logo when the DOM content is loaded
document.addEventListener('DOMContentLoaded', () => {
insertLogo();
insertFooter();
setExternalLinksToOpenInNewTab();
trimCode();
initializeImageZoom();
});