Files
classroomio/apps/website/src/routes/+layout.ts
T

84 lines
2.6 KiB
TypeScript
Raw Normal View History

2024-08-25 21:35:59 +01:00
import type { MetaTagsProps } from 'svelte-meta-tags';
2024-02-02 08:18:26 +01:00
export const prerender = true;
2025-12-12 09:35:59 +01:00
export async function load({ url }) {
const stars = await getStars();
2024-02-02 08:18:26 +01:00
return {
2024-08-25 21:35:59 +01:00
baseMetaTags: getBaseMetaTags(url),
2025-12-12 09:35:59 +01:00
url: url.pathname,
stars
2024-02-02 08:18:26 +01:00
};
}
2024-08-25 21:35:59 +01:00
2025-12-12 09:35:59 +01:00
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');
let stars = 0;
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.log('error fetching stars', error);
}
2025-12-12 09:35:59 +01:00
starsCache.set(CACHE_KEY, { stars, lastUpdated: now });
return stars;
}
2024-08-25 21:35:59 +01:00
function getBaseMetaTags(url: URL) {
const metatags = Object.freeze({
2024-10-07 01:36:07 +01:00
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
2024-08-25 21:35:59 +01:00
description:
2024-10-07 01:36:07 +01:00
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
2024-08-25 21:35:59 +01:00
canonical: new URL(url.pathname, url.origin).href,
openGraph: {
type: 'website',
url: new URL(url.pathname, url.origin).href,
locale: 'en_IE',
2024-10-07 01:36:07 +01:00
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
2024-08-25 21:35:59 +01:00
description:
2024-10-07 01:36:07 +01:00
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
2024-08-25 21:35:59 +01:00
siteName: 'ClassroomIO',
images: [
{
2024-09-05 15:51:05 +01:00
url: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
2024-08-25 21:35:59 +01:00
alt: 'ClassroomIO OG Image',
width: 1920,
height: 1080,
2024-09-05 15:51:05 +01:00
secureUrl: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
2024-08-25 21:35:59 +01:00
type: 'image/jpeg'
}
]
},
twitter: {
handle: '@classroomio',
site: '@classroomio',
cardType: 'summary_large_image' as const,
2024-10-07 01:36:07 +01:00
title: 'ClassroomIO | The Open Source Learning Management System for Companies',
2024-08-25 21:35:59 +01:00
description:
2024-10-07 01:36:07 +01:00
'A flexible, user-friendly platform for creating, managing, and delivering courses for companies and training organisations',
2024-09-05 15:51:05 +01:00
image: 'https://brand.cdn.clsrio.com/og/classroomio-og.png',
2024-08-25 21:35:59 +01:00
imageAlt: 'ClassroomIO OG Image'
}
}) satisfies MetaTagsProps;
return metatags;
}