Skip to content

Commit f13ec33

Browse files
Fix OSS GitHub metric load and responsiveness (#304)
1 parent 4929d7e commit f13ec33

File tree

76 files changed

+4972
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+4972
-409
lines changed

categories/News/index.html

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ <h2 class="collection-header">News
360360

361361
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
362362
<script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
363-
<script src="/js/utils.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>
363+
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script>
364364
<script>
365365
var pjax = new Pjax({
366366
selectors: [
@@ -387,11 +387,72 @@ <h2 class="collection-header">News
387387
.add(NexT.motion.middleWares.postList)
388388
.bootstrap();
389389
}
390-
const hasTOC = document.querySelector('.post-toc');
391-
document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
392-
document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
393390
NexT.utils.updateSidebarPosition();
394391
});
392+
393+
// Create a persistent cache object for OSS page repos
394+
if (!window.githubDataCache) {
395+
window.githubDataCache = {};
396+
}
397+
398+
// A hook for fetching and loading data for OSS page
399+
// Function to update project information from GitHub API
400+
function updateProjectsFromGitHub() {
401+
// Check if we're on the Open Source page
402+
if (document.title !== "Open Source") {
403+
return;
404+
}
405+
406+
const projects = document.querySelectorAll('.project');
407+
408+
projects.forEach(project => {
409+
const githubUrl = project.getAttribute('data-repo');
410+
if (!githubUrl) return;
411+
412+
// Construct the GitHub API URL
413+
const apiUrl = githubUrl.replace('https://github.com/', 'https://api.github.com/repos/');
414+
415+
// Use project name or the full URL as a cache key
416+
const cacheKey = githubUrl;
417+
418+
if (window.githubDataCache[cacheKey]) {
419+
// Use cached data if available
420+
updateProjectDOM(project, window.githubDataCache[cacheKey]);
421+
} else {
422+
// Fetch from API if not in cache
423+
fetch(apiUrl)
424+
.then(response => response.json())
425+
.then(data => {
426+
// Store in cache
427+
window.githubDataCache[cacheKey] = data;
428+
// Update DOM
429+
updateProjectDOM(project, data);
430+
})
431+
.catch(error => console.error('Error fetching GitHub data:', error));
432+
}
433+
});
434+
}
435+
436+
// Helper function to update the DOM for a project
437+
function updateProjectDOM(project, data) {
438+
// Use project name to generate IDs
439+
const idPrefix = data.name.toLowerCase().replace(/ /g, '-');
440+
441+
const languageElement = document.getElementById(`${idPrefix}-language`);
442+
const starsElement = document.getElementById(`${idPrefix}-stars`);
443+
const forksElement = document.getElementById(`${idPrefix}-forks`);
444+
445+
// Only update if elements exist
446+
if (languageElement) languageElement.textContent = data.language || 'N/A';
447+
if (starsElement) starsElement.textContent = data.stargazers_count || 0;
448+
if (forksElement) forksElement.textContent = data.forks_count || 0;
449+
}
450+
451+
// Hook into pjax:success event
452+
document.addEventListener('pjax:success', updateProjectsFromGitHub);
453+
454+
// Also run on initial page load to handle direct navigation
455+
updateProjectsFromGitHub();
395456
</script>
396457

397458

categories/News/page/10/index.html

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ <h2 class="collection-header">News
363363

364364
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
365365
<script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
366-
<script src="/js/utils.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>
366+
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script>
367367
<script>
368368
var pjax = new Pjax({
369369
selectors: [
@@ -390,11 +390,72 @@ <h2 class="collection-header">News
390390
.add(NexT.motion.middleWares.postList)
391391
.bootstrap();
392392
}
393-
const hasTOC = document.querySelector('.post-toc');
394-
document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
395-
document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
396393
NexT.utils.updateSidebarPosition();
397394
});
395+
396+
// Create a persistent cache object for OSS page repos
397+
if (!window.githubDataCache) {
398+
window.githubDataCache = {};
399+
}
400+
401+
// A hook for fetching and loading data for OSS page
402+
// Function to update project information from GitHub API
403+
function updateProjectsFromGitHub() {
404+
// Check if we're on the Open Source page
405+
if (document.title !== "Open Source") {
406+
return;
407+
}
408+
409+
const projects = document.querySelectorAll('.project');
410+
411+
projects.forEach(project => {
412+
const githubUrl = project.getAttribute('data-repo');
413+
if (!githubUrl) return;
414+
415+
// Construct the GitHub API URL
416+
const apiUrl = githubUrl.replace('https://github.com/', 'https://api.github.com/repos/');
417+
418+
// Use project name or the full URL as a cache key
419+
const cacheKey = githubUrl;
420+
421+
if (window.githubDataCache[cacheKey]) {
422+
// Use cached data if available
423+
updateProjectDOM(project, window.githubDataCache[cacheKey]);
424+
} else {
425+
// Fetch from API if not in cache
426+
fetch(apiUrl)
427+
.then(response => response.json())
428+
.then(data => {
429+
// Store in cache
430+
window.githubDataCache[cacheKey] = data;
431+
// Update DOM
432+
updateProjectDOM(project, data);
433+
})
434+
.catch(error => console.error('Error fetching GitHub data:', error));
435+
}
436+
});
437+
}
438+
439+
// Helper function to update the DOM for a project
440+
function updateProjectDOM(project, data) {
441+
// Use project name to generate IDs
442+
const idPrefix = data.name.toLowerCase().replace(/ /g, '-');
443+
444+
const languageElement = document.getElementById(`${idPrefix}-language`);
445+
const starsElement = document.getElementById(`${idPrefix}-stars`);
446+
const forksElement = document.getElementById(`${idPrefix}-forks`);
447+
448+
// Only update if elements exist
449+
if (languageElement) languageElement.textContent = data.language || 'N/A';
450+
if (starsElement) starsElement.textContent = data.stargazers_count || 0;
451+
if (forksElement) forksElement.textContent = data.forks_count || 0;
452+
}
453+
454+
// Hook into pjax:success event
455+
document.addEventListener('pjax:success', updateProjectsFromGitHub);
456+
457+
// Also run on initial page load to handle direct navigation
458+
updateProjectsFromGitHub();
398459
</script>
399460

400461

categories/News/page/2/index.html

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ <h2 class="collection-header">News
360360

361361
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
362362
<script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
363-
<script src="/js/utils.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>
363+
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script>
364364
<script>
365365
var pjax = new Pjax({
366366
selectors: [
@@ -387,11 +387,72 @@ <h2 class="collection-header">News
387387
.add(NexT.motion.middleWares.postList)
388388
.bootstrap();
389389
}
390-
const hasTOC = document.querySelector('.post-toc');
391-
document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
392-
document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
393390
NexT.utils.updateSidebarPosition();
394391
});
392+
393+
// Create a persistent cache object for OSS page repos
394+
if (!window.githubDataCache) {
395+
window.githubDataCache = {};
396+
}
397+
398+
// A hook for fetching and loading data for OSS page
399+
// Function to update project information from GitHub API
400+
function updateProjectsFromGitHub() {
401+
// Check if we're on the Open Source page
402+
if (document.title !== "Open Source") {
403+
return;
404+
}
405+
406+
const projects = document.querySelectorAll('.project');
407+
408+
projects.forEach(project => {
409+
const githubUrl = project.getAttribute('data-repo');
410+
if (!githubUrl) return;
411+
412+
// Construct the GitHub API URL
413+
const apiUrl = githubUrl.replace('https://github.com/', 'https://api.github.com/repos/');
414+
415+
// Use project name or the full URL as a cache key
416+
const cacheKey = githubUrl;
417+
418+
if (window.githubDataCache[cacheKey]) {
419+
// Use cached data if available
420+
updateProjectDOM(project, window.githubDataCache[cacheKey]);
421+
} else {
422+
// Fetch from API if not in cache
423+
fetch(apiUrl)
424+
.then(response => response.json())
425+
.then(data => {
426+
// Store in cache
427+
window.githubDataCache[cacheKey] = data;
428+
// Update DOM
429+
updateProjectDOM(project, data);
430+
})
431+
.catch(error => console.error('Error fetching GitHub data:', error));
432+
}
433+
});
434+
}
435+
436+
// Helper function to update the DOM for a project
437+
function updateProjectDOM(project, data) {
438+
// Use project name to generate IDs
439+
const idPrefix = data.name.toLowerCase().replace(/ /g, '-');
440+
441+
const languageElement = document.getElementById(`${idPrefix}-language`);
442+
const starsElement = document.getElementById(`${idPrefix}-stars`);
443+
const forksElement = document.getElementById(`${idPrefix}-forks`);
444+
445+
// Only update if elements exist
446+
if (languageElement) languageElement.textContent = data.language || 'N/A';
447+
if (starsElement) starsElement.textContent = data.stargazers_count || 0;
448+
if (forksElement) forksElement.textContent = data.forks_count || 0;
449+
}
450+
451+
// Hook into pjax:success event
452+
document.addEventListener('pjax:success', updateProjectsFromGitHub);
453+
454+
// Also run on initial page load to handle direct navigation
455+
updateProjectsFromGitHub();
395456
</script>
396457

397458

categories/News/page/3/index.html

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ <h2 class="collection-header">News
357357

358358
<script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
359359
<script src="https://cdn.jsdelivr.net/npm/@next-theme/pjax@0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
360-
<script src="/js/utils.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script>
360+
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script>
361361
<script>
362362
var pjax = new Pjax({
363363
selectors: [
@@ -384,11 +384,72 @@ <h2 class="collection-header">News
384384
.add(NexT.motion.middleWares.postList)
385385
.bootstrap();
386386
}
387-
const hasTOC = document.querySelector('.post-toc');
388-
document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
389-
document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
390387
NexT.utils.updateSidebarPosition();
391388
});
389+
390+
// Create a persistent cache object for OSS page repos
391+
if (!window.githubDataCache) {
392+
window.githubDataCache = {};
393+
}
394+
395+
// A hook for fetching and loading data for OSS page
396+
// Function to update project information from GitHub API
397+
function updateProjectsFromGitHub() {
398+
// Check if we're on the Open Source page
399+
if (document.title !== "Open Source") {
400+
return;
401+
}
402+
403+
const projects = document.querySelectorAll('.project');
404+
405+
projects.forEach(project => {
406+
const githubUrl = project.getAttribute('data-repo');
407+
if (!githubUrl) return;
408+
409+
// Construct the GitHub API URL
410+
const apiUrl = githubUrl.replace('https://github.com/', 'https://api.github.com/repos/');
411+
412+
// Use project name or the full URL as a cache key
413+
const cacheKey = githubUrl;
414+
415+
if (window.githubDataCache[cacheKey]) {
416+
// Use cached data if available
417+
updateProjectDOM(project, window.githubDataCache[cacheKey]);
418+
} else {
419+
// Fetch from API if not in cache
420+
fetch(apiUrl)
421+
.then(response => response.json())
422+
.then(data => {
423+
// Store in cache
424+
window.githubDataCache[cacheKey] = data;
425+
// Update DOM
426+
updateProjectDOM(project, data);
427+
})
428+
.catch(error => console.error('Error fetching GitHub data:', error));
429+
}
430+
});
431+
}
432+
433+
// Helper function to update the DOM for a project
434+
function updateProjectDOM(project, data) {
435+
// Use project name to generate IDs
436+
const idPrefix = data.name.toLowerCase().replace(/ /g, '-');
437+
438+
const languageElement = document.getElementById(`${idPrefix}-language`);
439+
const starsElement = document.getElementById(`${idPrefix}-stars`);
440+
const forksElement = document.getElementById(`${idPrefix}-forks`);
441+
442+
// Only update if elements exist
443+
if (languageElement) languageElement.textContent = data.language || 'N/A';
444+
if (starsElement) starsElement.textContent = data.stargazers_count || 0;
445+
if (forksElement) forksElement.textContent = data.forks_count || 0;
446+
}
447+
448+
// Hook into pjax:success event
449+
document.addEventListener('pjax:success', updateProjectsFromGitHub);
450+
451+
// Also run on initial page load to handle direct navigation
452+
updateProjectsFromGitHub();
392453
</script>
393454

394455

0 commit comments

Comments
 (0)