chore: move stars fetch to server
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
/node_modules/
|
|
||||||
node_modules
|
|
||||||
/src/node_modules/@sapper/
|
|
||||||
yarn-error.log
|
|
||||||
.svelte-kit/
|
|
||||||
.env
|
|
||||||
/dist/
|
|
||||||
/cert/
|
|
||||||
package-lock.json
|
|
||||||
.pnpm-store/*
|
|
||||||
|
|
||||||
# Local Netlify folder
|
|
||||||
.netlify
|
|
||||||
|
|
||||||
# Sentry Auth Token
|
|
||||||
.env.sentry-build-plugin
|
|
||||||
|
|
||||||
/_supascripts/
|
|
||||||
data.sql
|
|
||||||
changes.sql
|
|
||||||
|
|
||||||
.svelte-kit
|
|
||||||
@@ -9,7 +9,8 @@
|
|||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { fly } from 'svelte/transition';
|
import { fly } from 'svelte/transition';
|
||||||
|
|
||||||
let stars = 0;
|
export let stars: number;
|
||||||
|
|
||||||
let showDrawer = false;
|
let showDrawer = false;
|
||||||
let showSolutions = false;
|
let showSolutions = false;
|
||||||
let activeLink = '';
|
let activeLink = '';
|
||||||
@@ -53,20 +54,6 @@
|
|||||||
$: activeLink = page.url.pathname;
|
$: activeLink = page.url.pathname;
|
||||||
$: activeHash = page.url.hash;
|
$: activeHash = page.url.hash;
|
||||||
$: isSolutionsActive = solutions.some((s) => activeHash.includes(s.key));
|
$: isSolutionsActive = solutions.some((s) => activeHash.includes(s.key));
|
||||||
|
|
||||||
async function setStars() {
|
|
||||||
try {
|
|
||||||
const response = await fetch('https://api.github.com/repos/classroomio/classroomio');
|
|
||||||
const data = await response.json();
|
|
||||||
stars = data?.stargazers_count || 0;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching GitHub stars:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
setStars();
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
<MetaTags {...metaTags} />
|
<MetaTags {...metaTags} />
|
||||||
|
|
||||||
<div class="overflow-hidden bg-white">
|
<div class="overflow-hidden bg-white">
|
||||||
<Navigation />
|
<Navigation stars={data.stars} />
|
||||||
|
|
||||||
<PageTransition url={data.url}>
|
<PageTransition url={data.url}>
|
||||||
{#if page.status === 404}
|
{#if page.status === 404}
|
||||||
|
|||||||
@@ -2,13 +2,40 @@ import type { MetaTagsProps } from 'svelte-meta-tags';
|
|||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
|
|
||||||
export function load({ url }) {
|
export async function load({ url }) {
|
||||||
|
const stars = await getStars();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
baseMetaTags: getBaseMetaTags(url),
|
baseMetaTags: getBaseMetaTags(url),
|
||||||
url: url.pathname
|
url: url.pathname,
|
||||||
|
stars
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const starsCache = new Map<string, { stars: number; lastUpdated: number }>();
|
||||||
|
const CACHE_TIME = 1000 * 60 * 60 * 48; // 48 hours
|
||||||
|
const CACHE_KEY = 'github-stars';
|
||||||
|
|
||||||
|
async function getStars() {
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
|
const cacheData = starsCache.get(CACHE_KEY);
|
||||||
|
if (cacheData && now - cacheData.lastUpdated < CACHE_TIME) {
|
||||||
|
console.log('Returning cached stars');
|
||||||
|
return cacheData.stars;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Fetching stars from GitHub');
|
||||||
|
|
||||||
|
const response = await fetch('https://api.github.com/repos/classroomio/classroomio');
|
||||||
|
const data = await response.json();
|
||||||
|
const stars = data?.stargazers_count || 0;
|
||||||
|
|
||||||
|
starsCache.set(CACHE_KEY, { stars, lastUpdated: now });
|
||||||
|
|
||||||
|
return stars;
|
||||||
|
}
|
||||||
|
|
||||||
function getBaseMetaTags(url: URL) {
|
function getBaseMetaTags(url: URL) {
|
||||||
const metatags = Object.freeze({
|
const metatags = Object.freeze({
|
||||||
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
|
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
|
||||||
|
|||||||
Reference in New Issue
Block a user