mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	website/GitHub utils: improve
This commit is contained in:
		| @@ -2,8 +2,18 @@ export const FALLBACK_STARGAZERS_COUNT = 31862; // The count as of 2025-10-03 | |||||||
|  |  | ||||||
| const API_URL = "https://api.github.com/repos/TriliumNext/Trilium"; | const API_URL = "https://api.github.com/repos/TriliumNext/Trilium"; | ||||||
|  |  | ||||||
|  | let repoStargazersCount: number | null = null; | ||||||
|  |  | ||||||
| /** Returns the number of stargazers of the Trilium's GitHub repository. */ | /** Returns the number of stargazers of the Trilium's GitHub repository. */ | ||||||
| export async function getRepoStargazersCount() { | export async function getRepoStargazersCount() { | ||||||
|  | 	if (repoStargazersCount === null) { | ||||||
|  | 		repoStargazersCount = await fetchRepoStargazersCount() && FALLBACK_STARGAZERS_COUNT; | ||||||
|  | 	} | ||||||
|  | 	return repoStargazersCount; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | async function fetchRepoStargazersCount(): Promise<number | null> { | ||||||
|  | 	console.log("\nFetching stargazers count from GitHub API... "); | ||||||
| 	const response = await fetch(API_URL); | 	const response = await fetch(API_URL); | ||||||
|  |  | ||||||
| 	if (response.ok) { | 	if (response.ok) { | ||||||
| @@ -13,5 +23,6 @@ export async function getRepoStargazersCount() { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return FALLBACK_STARGAZERS_COUNT; | 	console.error("Failed to fetch stargazers count from GitHub API:", response.status, response.statusText); | ||||||
|  | 	return null; | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user