-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmk5.html
More file actions
549 lines (496 loc) · 23.6 KB
/
mk5.html
File metadata and controls
549 lines (496 loc) · 23.6 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GitHub Topic Search - MK5</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Google Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600&family=Poppins:wght@600;700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<style>
:root {
/* Light Mode Palette */
--primary-bg: #f8f9fa; /* Bootstrap Light */
--secondary-bg: #ffffff; /* White */
--text-color: #212529; /* Bootstrap Dark */
--muted-text-color: #6c757d; /* Bootstrap Muted */
--accent-color: #0d6efd; /* Bootstrap Primary Blue */
--accent-hover-color: #0b5ed7; /* Darker Blue */
--card-shadow: rgba(0, 0, 0, 0.05);
--card-hover-shadow: rgba(0, 0, 0, 0.1);
--border-color: #dee2e6; /* Bootstrap Border Color */
/* Typography */
--heading-font: 'Poppins', sans-serif;
--body-font: 'Inter', sans-serif;
--base-font-size: 16px;
--line-height: 1.7; /* Increased line height */
}
/* Dark Mode Palette */
@media (prefers-color-scheme: dark) {
:root {
--primary-bg: #212529; /* Bootstrap Dark */
--secondary-bg: #343a40; /* Bootstrap Gray Dark */
--text-color: #f8f9fa; /* Bootstrap Light */
--muted-text-color: #adb5bd;
--border-color: #495057;
/* Accent color remains the same for contrast */
--card-shadow: rgba(0, 0, 0, 0.15);
--card-hover-shadow: rgba(0, 0, 0, 0.25);
}
}
body {
font-family: var(--body-font);
background-color: var(--primary-bg);
color: var(--text-color);
font-size: var(--base-font-size);
line-height: var(--line-height);
transition: background-color 0.3s ease, color 0.3s ease;
padding-top: 3rem; /* Add space at the top */
padding-bottom: 3rem; /* Add space at the bottom */
}
/* --------------------------------- Layout & Spacing --------------------------------- */
.search-container {
max-width: 700px; /* Limit width for centered effect */
margin-left: auto;
margin-right: auto;
}
/* --------------------------------- Typography --------------------------------- */
h1.display-4 { /* Using Bootstrap display class */
font-family: var(--heading-font);
font-weight: 700; /* Bold Poppins */
color: var(--text-color);
margin-bottom: 2.5rem; /* More space below heading */
letter-spacing: -1px;
}
.repo-title {
font-family: var(--heading-font);
font-weight: 600; /* Semi-bold Poppins */
font-size: 1.15em; /* ~18.4px */
color: var(--accent-color); /* Blue for titles */
text-decoration: none;
transition: color 0.2s ease;
}
.repo-title:hover {
color: var(--accent-hover-color); /* Darker Blue hover */
}
.repo-description {
font-size: 0.95em; /* ~15px */
color: var(--muted-text-color);
margin-bottom: 1rem;
font-weight: 400; /* Regular Inter */
}
.repo-stats,
.repo-language,
.repo-last-updated,
.repo-owner,
.repo-topics small { /* Target the "Topics:" text */
font-size: 0.85em; /* ~13.6px */
color: var(--muted-text-color);
margin-top: 3px;
margin-bottom: 3px; /* Consistent small margins */
}
.repo-owner a {
color: var(--muted-text-color);
text-decoration: none;
font-weight: 600; /* Semi-bold Inter */
transition: color 0.2s ease;
}
.repo-owner a:hover {
color: var(--accent-color); /* Blue hover */
}
/* --------------------------------- Search Bar & Button --------------------------------- */
.input-group.input-group-lg .form-control,
.input-group.input-group-lg .btn {
border-radius: 50rem; /* .rounded-pill equivalent */
}
.input-group.input-group-lg .form-control {
padding-left: 1.5rem; /* More padding inside input */
border-right: 0; /* Hide border between input and button */
}
.input-group.input-group-lg .btn {
padding-left: 1.5rem;
padding-right: 1.5rem;
z-index: 2; /* Ensure button overlaps input border */
}
.form-control {
background-color: var(--secondary-bg);
color: var(--text-color);
border: 1px solid var(--border-color);
transition: background-color 0.3s ease, color 0.3s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-control::placeholder {
color: var(--muted-text-color);
opacity: 0.7;
}
.form-control:focus {
background-color: var(--secondary-bg);
color: var(--text-color);
border-color: var(--accent-color);
box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25); /* Blue focus ring */
z-index: 3; /* Ensure focus ring is on top */
}
.btn-primary {
background-color: var(--accent-color);
border-color: var(--accent-color);
color: #ffffff;
font-weight: 600; /* Semi-bold Inter */
transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}
.btn-primary:hover {
background-color: var(--accent-hover-color);
border-color: var(--accent-hover-color);
color: #ffffff;
transform: scale(1.03); /* Slight scale effect */
}
/* --------------------------------- Cards --------------------------------- */
.repo-card {
border: 1px solid var(--border-color);
border-radius: 0.5rem; /* Bootstrap's default card radius */
box-shadow: 0 1px 3px var(--card-shadow); /* Very subtle shadow */
transition: transform 0.2s ease, box-shadow 0.2s ease;
background-color: var(--secondary-bg);
}
.card-body {
padding: 1.25rem; /* Default Bootstrap card padding */
}
.repo-card:hover {
transform: translateY(-3px);
box-shadow: 0 4px 10px var(--card-hover-shadow); /* Slightly stronger hover shadow */
}
/* --------------------------------- Badges (Topics) --------------------------------- */
.badge {
font-size: 0.7em; /* Smaller badges */
font-weight: 600; /* Semi-bold Inter */
padding: 0.3em 0.6em;
border-radius: 50rem; /* Pill shape */
text-decoration: none;
transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
border: 1px solid transparent; /* Base border */
cursor: pointer;
}
/* Collected topics above search */
#collected-topics-container {
display: flex; /* Enable Flexbox */
flex-wrap: wrap; /* Allow badges to wrap to the next line */
justify-content: center; /* Center the lines of badges */
}
#collected-topics-container .badge {
background-color: var(--secondary-bg);
border-color: var(--border-color);
color: var(--muted-text-color);
font-size: 2.1em; /* Make collected topics significantly larger */
}
#collected-topics-container .badge:hover {
background-color: var(--accent-color);
border-color: var(--accent-color);
color: #ffffff;
}
/* Topics within cards */
.topic-link-badge {
background-color: var(--secondary-bg);
border-color: var(--accent-color); /* Blue border */
color: var(--accent-color); /* Blue text */
}
.topic-link-badge:hover {
background-color: var(--accent-color); /* Blue background */
border-color: var(--accent-color);
color: #ffffff; /* White text */
}
/* --------------------------------- Loading & Pagination --------------------------------- */
#loading-message {
display: none;
text-align: center;
font-size: 1rem; /* Standard text size */
margin-top: 2rem;
color: var(--muted-text-color);
}
/* Optional: Add spinner */
#loading-message::before {
content: '';
display: inline-block;
width: 1rem;
height: 1rem;
margin-right: 0.5rem;
border: 2px solid currentColor;
border-right-color: transparent;
border-radius: 50%;
animation: spinner-border .75s linear infinite;
vertical-align: text-bottom;
}
@keyframes spinner-border {
to { transform: rotate(360deg); }
}
.pagination .page-link {
background-color: var(--secondary-bg);
border: 1px solid var(--border-color);
color: var(--accent-color);
margin: 0 3px;
border-radius: 0.25rem; /* Standard radius */
transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.pagination .page-link:hover {
background-color: var(--primary-bg);
border-color: var(--accent-color);
color: var(--accent-color);
}
.pagination .page-item.active .page-link {
background-color: var(--accent-color);
border-color: var(--accent-color);
color: white;
}
.pagination .page-item.disabled .page-link {
background-color: var(--secondary-bg);
border-color: var(--border-color);
color: var(--muted-text-color);
opacity: 0.65;
}
/* --------------------------------- Mobile Responsiveness --------------------------------- */
@media (max-width: 768px) {
h1.display-4 {
font-size: 2.5rem; /* Adjust heading for smaller screens */
margin-bottom: 2rem;
}
.search-container {
max-width: 100%; /* Full width on smaller screens */
}
.input-group.input-group-lg .form-control,
.input-group.input-group-lg .btn {
font-size: 1rem; /* Adjust font size for smaller screens */
}
}
</style>
</head>
<body>
<div class="container">
<div class="search-container"> <!-- Centering container -->
<h1 class="display-4 text-center">Explore GitHub Topics</h1> <!-- Using display class -->
<!-- Container for Collected Topics -->
<div id="collected-topics-container" class="mb-4 text-center">
<!-- Collected topic badges will be inserted here -->
</div>
<!-- Search Input and Button -->
<!-- Using input-group-lg and rounded-pill -->
<div class="input-group input-group-lg mb-5 shadow-sm">
<input type="text" id="topics-input" class="form-control rounded-pill" placeholder="Search topics..." aria-label="GitHub Topics">
<button class="btn btn-primary rounded-pill" type="button" id="search-button">Search</button>
</div>
</div> <!-- /search-container -->
<!-- Loading Message -->
<div id="loading-message">Loading...</div>
<!-- Results Section -->
<div id="results-container" class="row row-cols-1 row-cols-md-2 row-cols-lg-3 g-4 mt-4" aria-live="polite">
<!-- Dynamic Results will be inserted here -->
</div>
<!-- Pagination Controls -->
<nav id="pagination-controls" aria-label="Search results navigation" class="mt-5 d-none">
</nav>
</div> <!-- /container -->
<!-- Bootstrap JS Bundle (includes Popper) -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
<!-- Custom JS (Identical to mk4.html) -->
<script>
// State for pagination
let currentPage = 1;
const perPage = 15; // Number of results per page
/* --------------------------------- Step 1: Handling Input --------------------------------- */
function getSearchQuery() {
const input = document.getElementById('topics-input').value;
return input.split(',')
.map(topic => topic.trim())
.filter(Boolean);
}
/* --------------------------------- Step 2: Fetching GitHub Repos --------------------------------- */
async function fetchGitHubRepos(query, page = 1) {
const url = `https://api.github.com/search/repositories?q=${query}+in:topics&per_page=${perPage}&page=${page}`;
document.getElementById('loading-message').style.display = 'block';
document.getElementById('results-container').innerHTML = '';
document.getElementById('pagination-controls').classList.add('d-none');
document.getElementById('collected-topics-container').innerHTML = '';
try {
const response = await fetch(url);
if (response.status === 403) {
throw new Error('GitHub API rate limit exceeded. Please wait and try again.');
}
if (!response.ok) throw new Error(`Failed to fetch data from GitHub (Status: ${response.status})`);
const data = await response.json();
return data;
} catch (error) {
handleError(error);
return null;
}
}
/* --------------------------------- Step 3: Handling Errors --------------------------------- */
function handleError(error) {
console.error("Search Error:", error);
const container = document.getElementById('results-container');
container.innerHTML = `<div class="alert alert-danger" role="alert">Error: ${error.message}</div>`;
document.getElementById('loading-message').style.display = 'none';
document.getElementById('pagination-controls').classList.add('d-none');
document.getElementById('collected-topics-container').innerHTML = '';
}
/* --------------------------------- Step 4: Displaying Results --------------------------------- */
function displayResults(data) {
const container = document.getElementById('results-container');
const repos = data.items || [];
container.innerHTML = '';
if (repos.length === 0) {
container.innerHTML = '<p class="text-center text-muted mt-4">No repositories found matching your topics.</p>'; // Added margin
document.getElementById('pagination-controls').classList.add('d-none');
return;
}
repos.forEach(repo => {
const repoCard = createRepoCard(repo);
container.appendChild(repoCard);
});
collectAndDisplayUniqueTopics(repos);
}
/* --- Helper Functions for Displaying Topics --- */
function collectAndDisplayUniqueTopics(repos) {
const allTopics = repos.flatMap(repo => repo.topics || []);
const uniqueTopics = [...new Set(allTopics)].sort();
displayCollectedTopics(uniqueTopics);
}
function displayCollectedTopics(topics) {
const container = document.getElementById('collected-topics-container');
container.innerHTML = ''; // Clear previous
if (topics.length > 0) {
// No explicit "Related Topics:" text, just show the badges
topics.forEach(topic => {
const badgeLink = document.createElement('a');
badgeLink.href = '#';
badgeLink.classList.add('badge', 'me-1', 'mb-1');
badgeLink.dataset.topic = topic;
badgeLink.textContent = topic;
container.appendChild(badgeLink);
});
}
}
/* --------------------------------- Step 4.5: Handling Pagination Display --------------------------------- */
function displayPagination(totalCount, query) {
const paginationContainer = document.getElementById('pagination-controls');
paginationContainer.innerHTML = '';
const maxResults = 1000;
const displayableTotalCount = Math.min(totalCount, maxResults);
const totalPages = Math.ceil(displayableTotalCount / perPage);
if (totalPages <= 1) {
paginationContainer.classList.add('d-none');
return;
}
paginationContainer.classList.remove('d-none');
const paginationList = document.createElement('ul');
paginationList.classList.add('pagination', 'justify-content-center');
const prevLi = document.createElement('li');
prevLi.classList.add('page-item');
if (currentPage === 1) { prevLi.classList.add('disabled'); }
prevLi.innerHTML = `<button class="page-link" ${currentPage === 1 ? 'tabindex="-1" aria-disabled="true"' : ''} data-page="${currentPage - 1}" data-query="${query}">Previous</button>`;
paginationList.appendChild(prevLi);
const currentLi = document.createElement('li');
currentLi.classList.add('page-item', 'disabled');
currentLi.innerHTML = `<span class="page-link">Page ${currentPage} of ${totalPages} ${totalCount > maxResults ? '(of ~1k)' : ''}</span>`;
paginationList.appendChild(currentLi);
const nextLi = document.createElement('li');
nextLi.classList.add('page-item');
if (currentPage >= totalPages) { nextLi.classList.add('disabled'); }
nextLi.innerHTML = `<button class="page-link" ${currentPage >= totalPages ? 'tabindex="-1" aria-disabled="true"' : ''} data-page="${currentPage + 1}" data-query="${query}">Next</button>`;
paginationList.appendChild(nextLi);
paginationContainer.appendChild(paginationList);
paginationContainer.querySelectorAll('.page-link[data-page]').forEach(button => {
button.addEventListener('click', handlePaginationClick);
});
}
/* --------------------------------- Step 5: Creating Repo Cards --------------------------------- */
function createRepoCard(repo) {
const card = document.createElement('div');
card.classList.add('col');
card.innerHTML = `
<div class="card h-100 repo-card">
<div class="card-body d-flex flex-column">
<h5 class="card-title mb-2">
<a href="${repo.html_url}" target="_blank" rel="noopener noreferrer" class="repo-title">${repo.name}</a>
</h5>
<p class="repo-description card-text flex-grow-1">${repo.description || 'No description available'}</p>
<div class="mt-auto pt-2">
<p class="repo-stats card-text mb-1"><small>Stars: ${repo.stargazers_count} | Forks: ${repo.forks_count}</small></p>
<p class="repo-language card-text mb-1"><small>Language: ${repo.language || 'N/A'}</small></p>
<p class="repo-last-updated card-text mb-1"><small>Updated: ${new Date(repo.updated_at).toLocaleDateString()}</small></p>
<p class="repo-owner card-text mb-2">
<small>Owner: <a href="${repo.owner.html_url}" target="_blank" rel="noopener noreferrer">${repo.owner.login}</a></small>
</p>
<div class="repo-topics mt-2">
${repo.topics && repo.topics.length > 0
? '<small class="d-block mb-1 text-muted">Topics:</small> ' + repo.topics.map(topic => `<a href="#" class="badge me-1 mb-1 topic-link-badge" data-topic="${topic}">${topic}</a>`).join(' ')
: '<small class="text-muted">Topics: None listed</small>'
}
</div>
</div>
</div>
</div>`;
return card;
}
/* --------------------------------- Step 5.5: Handling Pagination Clicks --------------------------------- */
async function handlePaginationClick(event) {
event.preventDefault();
const button = event.target;
const targetPage = parseInt(button.getAttribute('data-page'), 10);
const query = button.getAttribute('data-query');
if (!isNaN(targetPage) && targetPage > 0 && query) {
currentPage = targetPage;
const data = await fetchGitHubRepos(query, currentPage);
if (data) {
displayResults(data);
displayPagination(data.total_count, query);
// Scroll to top of container for consistency
document.querySelector('.container').scrollIntoView({ behavior: 'smooth', block: 'start' });
}
document.getElementById('loading-message').style.display = 'none';
} else {
console.warn("Pagination click ignored: Invalid target page or query.");
}
}
/* --- Helper function to trigger search --- */
async function performSearch(topicsArray = null) {
const topics = topicsArray || getSearchQuery();
if (topics.length === 0) {
handleError(new Error('Please enter at least one valid topic.'));
return;
}
const query = topics.map(topic => `topic:${topic}`).join(' ');
currentPage = 1;
const data = await fetchGitHubRepos(query, currentPage);
if (data) {
displayResults(data);
displayPagination(data.total_count, query);
}
document.getElementById('loading-message').style.display = 'none';
}
/* --------------------------------- Step 6: Triggering the Search --------------------------------- */
function handleTopicClick(event) {
const topicBadge = event.target.closest('[data-topic]');
if (topicBadge) {
event.preventDefault();
const topic = topicBadge.dataset.topic;
if (topic) {
document.getElementById('topics-input').value = topic;
performSearch([topic]);
}
}
}
/* --- Add event listeners --- */
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('search-button').addEventListener('click', () => performSearch());
document.getElementById('topics-input').addEventListener('keypress', event => {
if (event.key === 'Enter') {
event.preventDefault();
performSearch();
}
});
document.getElementById('results-container').addEventListener('click', handleTopicClick);
document.getElementById('collected-topics-container').addEventListener('click', handleTopicClick);
});
</script>
</body>
</html>