-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
579 lines (482 loc) · 16.2 KB
/
script.js
File metadata and controls
579 lines (482 loc) · 16.2 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
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
const GITHUB_USERNAME = "byGOG";
const MAX_REPOS = 6;
const REPO_API_BASE = `https://api.github.com/repos/${GITHUB_USERNAME}`;
const CACHE_KEY = "bygog_gh_cache_v2";
const CACHE_TTL = 3600 * 1000; // 1 saat
function getCache() {
try {
const raw = localStorage.getItem(CACHE_KEY);
if (!raw) return null;
const { data, ts } = JSON.parse(raw);
if (Date.now() - ts > CACHE_TTL) return null;
return data;
} catch { return null; }
}
function setCache(data) {
try {
localStorage.setItem(CACHE_KEY, JSON.stringify({ data, ts: Date.now() }));
} catch {}
}
const PROJECT_OVERRIDES = {
"StashZero": {
displayName: "StashZero",
description: "Modern ve hızlı uygulama kütüphanesi. Tauri, React 19 ve Rust kullanılarak geliştirilmiştir.",
topics: ["Tauri", "React", "Rust", "Desktop"],
language: "Rust",
},
"Bibata-Cursor-Installer": {
displayName: "Bibata Cursor Installer",
description: "Windows için Bibata Modern Ice imleç temasının tek tıkla otomatik kurulumunu sağlayan araç.",
topics: ["PowerShell", "Windows", "UI", "Theme"],
language: "PowerShell",
},
"bygog.github.io": {
displayName: "Kişisel Site Kaynağı",
description: "Bu GitHub Pages deposu kişisel portföyümün tasarımını, animasyonlarını ve bileşenlerini barındırır.",
homepage: "https://bygog.github.io",
topics: ["GitHub Pages", "Portföy", "HTML", "CSS"],
language: "CSS",
},
"byGOG-Lab": {
displayName: "byGOG Lab",
description: "Windows ve yazılım araçları için güvenilir bağlantıları tek sayfada sunan PWA; arama ve çevrimdışı destekli.",
homepage: "https://bygog.github.io/byGOG-Lab/",
topics: ["PWA", "Windows", "Bağlantı Koleksiyonu"],
},
"ZTE-H3601P": {
displayName: "ZTE H3601P Otomasyonu",
description: "ZTE H3601P modemini belirli aralıklarla yeniden başlatıp IP değişimini kontrol eden Python uygulaması.",
topics: ["Python", "Ağ", "Otomasyon"],
language: "Python",
},
"GOGon": {
displayName: "GOGon Yükleyici",
description: "PySide6 arayüzüyle yazılım kategorilerini listeler, tek tıklamayla indirme ve kurulum akışı sunar.",
topics: ["PySide6", "Masaüstü Uygulaması", "Yükleyici"],
},
};
function createFallbackProject(name, url, language) {
const override = PROJECT_OVERRIDES[name] || {};
return {
name,
displayName: override.displayName || name,
url,
description: truncateText(override.description || "Proje detayları yakında güncellenecek."),
language: override.language || language || null,
stars: null,
forks: null,
updatedAt: null,
homepage: override.homepage || null,
topics: override.topics ? [...override.topics] : [],
isFallback: true,
};
}
const FALLBACK_PROJECTS = [
createFallbackProject("StashZero", "https://github.com/byGOG/StashZero", "Rust"),
createFallbackProject("Bibata-Cursor-Installer", "https://github.com/byGOG/Bibata-Cursor-Installer", "PowerShell"),
createFallbackProject("byGOG-Lab", "https://github.com/byGOG/byGOG-Lab", "JavaScript"),
createFallbackProject("ZTE-H3601P", "https://github.com/byGOG/ZTE-H3601P", "Python"),
createFallbackProject("GOGon", "https://github.com/byGOG/GOGon", "Python"),
createFallbackProject("bygog.github.io", "https://github.com/byGOG/bygog.github.io", "CSS"),
];
const relativeTimeFormatter =
typeof Intl !== "undefined" && typeof Intl.RelativeTimeFormat === "function"
? new Intl.RelativeTimeFormat("tr", { numeric: "auto" })
: null;
function renderSkeletons(list, count) {
list.innerHTML = "";
for (let i = 0; i < count; i++) {
const item = document.createElement("li");
item.className = "github-item github-item--skeleton";
item.setAttribute("aria-hidden", "true");
item.innerHTML =
'<div class="skeleton-line skeleton-line--title"></div>' +
'<div class="skeleton-line"></div>' +
'<div class="skeleton-line skeleton-line--short"></div>' +
'<div class="skeleton-line skeleton-line--meta"></div>';
list.appendChild(item);
}
}
async function loadGitHubProjects() {
const list = document.querySelector("[data-github-projects]");
const status = document.querySelector("[data-github-status]");
if (!list || !status) {
return;
}
renderSkeletons(list, MAX_REPOS);
status.textContent = "GitHub projeleri yükleniyor...";
try {
// Önce önbelleğe bak (1 saatlik TTL)
const cachedRepos = getCache();
let repos;
if (cachedRepos) {
repos = cachedRepos;
} else {
// PROJECT_OVERRIDES'daki repoları tek tek çek — pinned repo benzeri davranış
const names = Object.keys(PROJECT_OVERRIDES);
const results = await Promise.all(
names.map((name) =>
fetch(`${REPO_API_BASE}/${name}`, {
headers: { Accept: "application/vnd.github.mercy-preview+json" },
})
.then((r) => (r.ok ? r.json() : null))
.catch(() => null)
)
);
repos = results.filter((r) => r && !r.fork && !r.private);
if (repos.length) setCache(repos);
}
if (!repos.length) {
status.textContent = "Öne çıkan projeler:";
renderProjects(FALLBACK_PROJECTS, list);
return;
}
const enriched = await Promise.all(repos.map(enrichRepository));
status.textContent = "GitHub'dan güncel projeler:";
renderProjects(enriched, list);
} catch (error) {
console.error(error);
status.textContent = "GitHub projeleri alınamadı. Öne çıkan çalışmalar:";
renderProjects(FALLBACK_PROJECTS, list);
}
}
async function enrichRepository(repo) {
const override = PROJECT_OVERRIDES[repo.name] || {};
let description = override.description || repo.description;
if (!description) {
description = await fetchReadmeSummary(repo);
}
if (!description) {
description = "Bu proje için açıklama henüz eklenmedi.";
}
const topics = uniqueTopics([
...(override.topics || []),
...(Array.isArray(repo.topics) ? repo.topics : []),
]);
const language = override.language || repo.language || null;
const stars = typeof repo.stargazers_count === "number" ? repo.stargazers_count : 0;
const forks = typeof repo.forks_count === "number" ? repo.forks_count : 0;
const updatedAt = repo.pushed_at || repo.updated_at || null;
return {
name: repo.name,
displayName: override.displayName || repo.name,
url: repo.html_url,
description: truncateText(description),
language,
stars,
forks,
updatedAt,
homepage: override.homepage || repo.homepage || null,
topics,
isFallback: false,
};
}
function uniqueTopics(topics) {
return Array.from(new Set(topics.filter(Boolean).map((topic) => topic.trim())));
}
async function fetchReadmeSummary(repo) {
const owner = repo.owner?.login || GITHUB_USERNAME;
const branch = repo.default_branch || "main";
const readmeUrl = `https://raw.githubusercontent.com/${owner}/${repo.name}/${branch}/README.md`;
try {
const response = await fetch(readmeUrl);
if (!response.ok) {
return null;
}
const markdown = await response.text();
return extractSummary(markdown);
} catch (error) {
console.warn("README özetine ulaşılamadı:", error);
return null;
}
}
function extractSummary(markdown) {
if (!markdown) {
return null;
}
const lines = markdown.split(/\r?\n/);
let inCodeBlock = false;
for (const rawLine of lines) {
const trimmed = rawLine.trim();
if (!trimmed) {
continue;
}
if (trimmed.startsWith("```")) {
inCodeBlock = !inCodeBlock;
continue;
}
if (inCodeBlock) {
continue;
}
if (trimmed.startsWith("<!--") && trimmed.endsWith("-->")) {
continue;
}
if (trimmed.startsWith(">")) {
continue;
}
if (trimmed.startsWith("`")) {
continue;
}
const sanitized = sanitizeLine(rawLine);
if (!sanitized) {
continue;
}
if (trimmed.startsWith("#") && sanitized.length < 30) {
continue;
}
if (sanitized.length < 25 && sanitized.split(" ").length <= 3) {
continue;
}
return truncateText(sanitized);
}
return null;
}
function sanitizeLine(line) {
let sanitized = line;
sanitized = sanitized.replace(/<!--[\s\S]*?-->/g, "");
sanitized = sanitized.replace(/!\[[^\]]*\]\([^\)]*\)/g, "");
sanitized = sanitized.replace(/\[([^\]]+)\]\([^\)]+\)/g, "$1");
sanitized = sanitized.replace(/`{1,3}([^`]+)`{1,3}/g, "$1");
sanitized = sanitized.replace(/<[^>]+>/g, " ");
sanitized = sanitized.replace(/^\s*[>*+-]\s+/g, "");
sanitized = sanitized.replace(/^\s*#{1,6}\s+/g, "");
sanitized = sanitized.replace(/\*\*([^*]+)\*\*/g, "$1");
sanitized = sanitized.replace(/__([^_]+)__/g, "$1");
sanitized = sanitized.replace(/\*([^*]+)\*/g, "$1");
sanitized = sanitized.replace(/_([^_]+)_/g, "$1");
sanitized = sanitized.replace(/\s+/g, " ");
return sanitized.trim();
}
function truncateText(text, maxLength = 220) {
if (!text) {
return "";
}
const trimmed = text.trim();
if (trimmed.length <= maxLength) {
return trimmed;
}
return `${trimmed.slice(0, maxLength - 1).trim()}…`;
}
function formatRelativeTime(dateString) {
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) {
return null;
}
if (!relativeTimeFormatter) {
return date.toLocaleDateString("tr-TR");
}
let duration = (date.getTime() - Date.now()) / 1000;
const divisions = [
{ amount: 60, unit: "second" },
{ amount: 60, unit: "minute" },
{ amount: 24, unit: "hour" },
{ amount: 7, unit: "day" },
{ amount: 4.34524, unit: "week" },
{ amount: 12, unit: "month" },
{ amount: Infinity, unit: "year" },
];
for (const division of divisions) {
if (Math.abs(duration) < division.amount) {
return relativeTimeFormatter.format(Math.round(duration), division.unit);
}
duration /= division.amount;
}
return null;
}
function formatAbsoluteDate(dateString) {
const date = new Date(dateString);
if (Number.isNaN(date.getTime())) {
return "";
}
try {
return new Intl.DateTimeFormat("tr-TR", {
dateStyle: "long",
timeStyle: "short",
}).format(date);
} catch (error) {
return date.toLocaleString();
}
}
function renderProjects(projects, list) {
list.innerHTML = "";
if (!projects.length) {
const emptyItem = document.createElement("li");
emptyItem.className = "github-item github-item--empty";
emptyItem.textContent = "Şu anda listelenecek proje bulunmuyor.";
list.appendChild(emptyItem);
return;
}
projects.forEach((project, index) => {
const item = buildProjectItem(project);
item.style.setProperty("--i", index);
list.appendChild(item);
});
}
function buildProjectItem(project) {
const item = document.createElement("li");
item.className = "github-item";
item.dataset.source = project.isFallback ? "fallback" : "github";
const titleRow = document.createElement("div");
titleRow.className = "github-item__title-row";
const title = document.createElement("a");
title.className = "github-item__title";
title.href = project.url;
title.target = "_blank";
title.rel = "noopener";
const displayName = project.displayName || project.name;
title.textContent = displayName;
title.setAttribute("aria-label", `${displayName} GitHub deposunu yeni sekmede aç`);
titleRow.appendChild(title);
if (project.homepage) {
const demoLink = document.createElement("a");
demoLink.className = "github-item__demo";
demoLink.href = project.homepage;
demoLink.target = "_blank";
demoLink.rel = "noopener";
demoLink.textContent = "Canlı demo";
titleRow.appendChild(demoLink);
}
item.appendChild(titleRow);
if (project.description) {
const description = document.createElement("p");
description.className = "github-item__description";
description.textContent = project.description;
item.appendChild(description);
}
if (project.topics && project.topics.length) {
const topicList = document.createElement("ul");
topicList.className = "github-topics";
project.topics.forEach((topic) => {
const topicItem = document.createElement("li");
topicItem.textContent = topic;
topicList.appendChild(topicItem);
});
item.appendChild(topicList);
}
const metaItems = [];
if (project.language) {
metaItems.push({
icon: "🛠️",
label: project.language,
srLabel: `Ana dil ${project.language}`,
});
}
if (typeof project.stars === "number") {
metaItems.push({
icon: "⭐",
label: project.stars.toString(),
srLabel: `${project.stars} GitHub yıldızı`,
});
}
if (typeof project.forks === "number") {
metaItems.push({
icon: "🍴",
label: project.forks.toString(),
srLabel: `${project.forks} çatal`,
});
}
if (project.updatedAt) {
const relative = formatRelativeTime(project.updatedAt);
const absolute = formatAbsoluteDate(project.updatedAt);
if (relative) {
metaItems.push({
icon: "🕒",
label: relative,
srLabel: `Son güncellenme tarihi ${absolute}`,
title: absolute,
});
}
}
if (metaItems.length) {
const metaList = document.createElement("ul");
metaList.className = "github-meta";
metaItems.forEach((meta) => {
metaList.appendChild(createMetaItem(meta));
});
item.appendChild(metaList);
}
return item;
}
function createMetaItem({ icon, label, srLabel, title }) {
const item = document.createElement("li");
item.className = "github-meta__item";
if (title) {
item.title = title;
}
if (icon) {
const iconSpan = document.createElement("span");
iconSpan.setAttribute("aria-hidden", "true");
iconSpan.textContent = icon;
item.appendChild(iconSpan);
}
const text = document.createElement("span");
text.textContent = label;
item.appendChild(text);
if (srLabel) {
const sr = document.createElement("span");
sr.className = "sr-only";
sr.textContent = srLabel;
item.appendChild(sr);
}
return item;
}
function applyLang(lang) {
document.querySelectorAll("[data-tr]").forEach(function (el) {
el.textContent = lang === "en" ? (el.dataset.en || el.dataset.tr) : el.dataset.tr;
});
document.querySelectorAll("[data-tr-placeholder]").forEach(function (el) {
el.placeholder = lang === "en"
? (el.dataset.enPlaceholder || el.dataset.trPlaceholder)
: el.dataset.trPlaceholder;
});
document.documentElement.setAttribute("lang", lang === "en" ? "en" : "tr");
var langText = document.querySelector(".lang-toggle__text");
if (langText) langText.textContent = lang === "en" ? "TR" : "EN";
}
function initLangToggle() {
var saved = localStorage.getItem("lang") || "tr";
applyLang(saved);
var btn = document.querySelector(".lang-toggle");
if (!btn) return;
btn.addEventListener("click", function () {
var current = localStorage.getItem("lang") || "tr";
var next = current === "tr" ? "en" : "tr";
localStorage.setItem("lang", next);
applyLang(next);
});
}
function initNavToggle() {
var nav = document.querySelector(".site-nav");
var toggle = document.querySelector(".nav-toggle");
if (!nav || !toggle) return;
toggle.addEventListener("click", function () {
var isOpen = nav.classList.toggle("site-nav--open");
toggle.setAttribute("aria-expanded", isOpen ? "true" : "false");
toggle.setAttribute("aria-label", isOpen ? "Menüyü kapat" : "Menüyü aç");
});
nav.querySelectorAll(".site-nav__link").forEach(function (link) {
link.addEventListener("click", function () {
nav.classList.remove("site-nav--open");
toggle.setAttribute("aria-expanded", "false");
toggle.setAttribute("aria-label", "Menüyü aç");
});
});
document.addEventListener("click", function (e) {
if (!nav.contains(e.target) && nav.classList.contains("site-nav--open")) {
nav.classList.remove("site-nav--open");
toggle.setAttribute("aria-expanded", "false");
toggle.setAttribute("aria-label", "Menüyü aç");
}
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", function () {
loadGitHubProjects();
initLangToggle();
initNavToggle();
});
} else {
loadGitHubProjects();
initLangToggle();
initNavToggle();
}