Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
432 changes: 431 additions & 1 deletion package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@eslint/js": "^10.0.1",
"@fontsource-variable/geist": "^5.3.0",
"@fontsource-variable/geist-mono": "^5.3.0",
"@fontsource/geist-mono": "^5.3.0",
"@internationalized/date": "^3.12.4",
"@lucide/svelte": "^1.66.0",
"@sveltejs/adapter-node": "^5.5.4",
Expand Down Expand Up @@ -55,8 +56,13 @@
"vitest": "^5.1.0"
},
"dependencies": {
"@resvg/resvg-js": "^2.6.2",
"drizzle-orm": "^0.45.4",
"postgres": "^4.1.0",
"satori": "^0.63.2",
"zod": "^4.6.7"
},
"overrides": {
"fflate": "^0.7.5"
}
}
29 changes: 22 additions & 7 deletions src/lib/components/common/PageMeta.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<script lang="ts">
import { APP_NAME } from '$lib/config';
import { page } from '$app/state';
import { APP_NAME, OG_SIZE, paths } from '$lib/config';

// One head block for every page, so titles and descriptions never drift
let { title, description }: { title: string; description?: string } = $props();
// One head block for every page, so titles, descriptions and share cards never drift
let { title, description }: { title?: string; description: string } = $props();

const fullTitle = $derived(title ? `${title} · ${APP_NAME}` : APP_NAME);
const canonical = $derived(new URL(page.url.pathname, page.url).href);
const image = $derived(new URL(paths.ogImage(page.url.pathname), page.url).href);
</script>

<svelte:head>
<title>{title} · {APP_NAME}</title>
{#if description}
<meta name="description" content={description} />
{/if}
<title>{fullTitle}</title>
<meta name="description" content={description} />
<link rel="canonical" href={canonical} />
<meta property="og:site_name" content={APP_NAME} />
<meta property="og:type" content="website" />
<meta property="og:title" content={title ?? APP_NAME} />
<meta property="og:description" content={description} />
<meta property="og:url" content={canonical} />
<meta property="og:image" content={image} />
<meta property="og:image:type" content="image/png" />
<meta property="og:image:width" content={String(OG_SIZE.width)} />
<meta property="og:image:height" content={String(OG_SIZE.height)} />
<meta property="og:image:alt" content={fullTitle} />
<meta name="twitter:card" content="summary_large_image" />
</svelte:head>
19 changes: 0 additions & 19 deletions src/lib/components/home/HomeMeta.svelte

This file was deleted.

7 changes: 6 additions & 1 deletion src/lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ export const APP_NAME = 'github-dashboards';
export const APP_DESCRIPTION = 'A fast GitHub status board for users and repos';
export const GITHUB_WEB = 'https://github.com';

// Social share card size, the 1.91:1 every platform crops to
export const OG_SIZE = { width: 1200, height: 630 } as const;

// A login's avatar straight from GitHub, no id needed, redirects to the sized image.
// Larger sizes stay crisp when the avatar is drawn big, e.g. inside a bubble
export const githubAvatar = (login: string, size = 48) => `${GITHUB_WEB}/${login}.png?size=${size}`;
Expand Down Expand Up @@ -32,5 +35,7 @@ export const paths = {
`/${user}/${repo}/ops/${section}`,
repoInfo: (user: string, repo: string) => `/${user}/${repo}/info`,
repoInfoSection: (user: string, repo: string, section: string) =>
`/${user}/${repo}/info/${section}`
`/${user}/${repo}/info/${section}`,
// Share card for a page path, home gets the baked default
ogImage: (path: string) => (path === '/' ? '/og.png' : `/_og${path}.png`)
};
2 changes: 1 addition & 1 deletion src/lib/server/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function purgeExpired(): void {
let storageReachable = true;
export const isStorageHealthy = () => storageReachable;

function isFresh(fetchedAt: Date, ttl: number): boolean {
export function isFresh(fetchedAt: Date, ttl: number): boolean {
return Date.now() - fetchedAt.getTime() < ttl * 1000;
}

Expand Down
8 changes: 7 additions & 1 deletion src/lib/server/github/repo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { graphql } from '$lib/server/github/client';
import { REPO_FIELDS, mapRepo, type RawRepo } from '$lib/server/github/user';
import { cached } from '$lib/server/cache';
import { cached, isFresh, readCached } from '$lib/server/cache';
import { AppError } from '$lib/utils/errors';
import type { Repo } from '$lib/types';

Expand Down Expand Up @@ -46,6 +46,12 @@ export async function getRepo(owner: string, name: string): Promise<Repo | null>
return repo;
}

// Fresh cached header data only, never fetching, so a repo gone private drops out with its TTL
export async function peekRepo(owner: string, name: string): Promise<Repo | null> {
const stored = await readCached<{ repo: Repo | null }>(repoKey(owner, name));
return stored && isFresh(stored.fetchedAt, stored.ttl) ? stored.value.repo : null;
}

// Resolve a repo without exposing private repos to other or anonymous viewers
export async function requireRepo(
owner: string,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/server/github/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@ export async function getUserOverview(login: string): Promise<UserOverview> {
return toOverview(stored.value);
}

// The cached profile only, never syncing, null until someone has loaded the overview
export async function peekUserProfile(login: string): Promise<UserProfile | null> {
const stored = await readCached<OverviewState>(overviewKey(login));
return stored ? mapProfile(stored.value.owner, stored.value.owned.nodes.map(mapRepo)) : null;
}

// blocking sync of every owned repo, for callers that need live counts
export async function refreshUserOverview(login: string): Promise<UserOverview> {
// joining a shallow sync already in flight would skip the rewalk
Expand Down
61 changes: 61 additions & 0 deletions src/lib/server/og/card.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { describe, it, expect } from 'vitest';
import { cleanText, defaultCard, pageCard, type OgNode } from './card';

// Every node in a card tree, depth first, so tests check what actually renders
function nodes(node: OgNode | string): (OgNode | string)[] {
if (typeof node === 'string') return [node];
return [node, ...((node.props.children ?? []) as (OgNode | string)[]).flatMap(nodes)];
}

const texts = (card: OgNode) => nodes(card).filter((node) => typeof node === 'string');
const dots = (card: OgNode) =>
nodes(card).filter((node) => typeof node !== 'string' && node.type === 'circle').length;

describe('cleanText', () => {
it('drops emoji, flags, keycaps and joined sequences', () => {
expect(cleanText('🚀 Fast ✨ flag 🇬🇧 key 1️⃣ family 👨‍👩‍👧 done')).toBe('Fast flag key family done');
});

it('keeps accented latin and punctuation, drops scripts the font lacks', () => {
expect(cleanText('Café Ünïcödé, a/b (c) 你好 日本')).toBe('Café Ünïcödé, a/b (c)');
});

it('returns empty for missing or undrawable text so callers can fall back', () => {
expect(cleanText(null)).toBe('');
expect(cleanText('日本語のみ 🎉')).toBe('');
});
});

describe('cards', () => {
it('draws the full robot from the site logo', () => {
expect(dots(defaultCard())).toBe(441);
});

it('shows the repo identity, page trail and stats', () => {
const text = texts(
pageCard({
trail: ['Info', 'Stats'],
owner: 'octocat',
name: 'hello-world',
description: 'My first repo',
avatar: null,
stats: [{ label: 'Stars', value: '1.2K' }]
})
);
expect(text).toEqual(
expect.arrayContaining(['octocat /', 'hello-world', 'My first repo', 'Info / Stats', '1.2K'])
);
});

it('leaves out the stat row and avatar when nothing is cached', () => {
const card = pageCard({
trail: ['Overview'],
name: 'octocat',
description: 'Profile summary',
avatar: null,
stats: []
});
expect(JSON.stringify(card)).not.toContain('"img"');
expect(texts(card)).not.toContain('Stars');
});
});
Loading
Loading