flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/docs/src/route-data.ts

78 lines2,909 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Docs in the shape of docs.continue.dev1import { defineRouteMiddleware } from '@astrojs/starlight/route-data';
2
3import { tabFor } from './tabs';
4
Social cards for every page: og.g1t.sh5type Entry = { type: string; label?: string; href?: string; isCurrent?: boolean; entries?: Entry[] };
6
7/** The social cards' service; see services/og. */
8const OG = 'https://og.g1t.sh';
Merge branch 'worktree-agent-ab2e39e11a6493412'9
10/** The slug of a group's first page on this site, such as `reference/api`. */
11function firstSlug(entries: Entry[]): string | undefined {
12 for (const entry of entries) {
13 if (entry.type === 'group') {
14 const slug = firstSlug(entry.entries ?? []);
15 if (slug !== undefined) return slug;
16 } else if (entry.href?.startsWith('/') && !entry.href.startsWith('//')) {
17 return entry.href.replace(/^\/|\/$/g, '');
18 }
19 }
20 return undefined;
21}
22
Social cards for every page: og.g1t.sh23/** The label of the sidebar group holding the current page, the innermost if they nest. */
24function sectionOf(entries: Entry[], group?: string): string | undefined {
25 for (const entry of entries) {
26 if (entry.type === 'group') {
27 const found = sectionOf(entry.entries ?? [], entry.label);
28 if (found !== undefined) return found;
29 } else if (entry.isCurrent) {
30 return group;
31 }
32 }
33 return undefined;
34}
35
Merge branch 'worktree-agent-ab2e39e11a6493412'36/**
37 * Each page's sidebar holds only its tab's groups: those whose pages
38 * belong to the same tab. Groups are told apart by their pages, not their
39 * labels, since a guide group and an API group can share a name.
Social cards for every page: og.g1t.sh40 *
41 * Each page also gets its own social card: its title, its section and its
42 * description, drawn by the og service.
Merge branch 'worktree-agent-ab2e39e11a6493412'43 */
Docs in the shape of docs.continue.dev44export const onRequest = defineRouteMiddleware((context) => {
45 const route = context.locals.starlightRoute;
Social cards for every page: og.g1t.sh46 const section = sectionOf(route.sidebar as Entry[]);
Docs in the shape of docs.continue.dev47 const tab = tabFor(route.id);
Merge branch 'worktree-agent-ab2e39e11a6493412'48 route.sidebar = route.sidebar.filter((entry) => {
49 if (entry.type !== 'group') return false;
50 const slug = firstSlug(entry.entries as Entry[]);
51 return slug !== undefined && tabFor(slug) === tab;
52 });
Social cards for every page: og.g1t.sh53
54 const { title, description } = route.entry.data;
55 const card = new URL('/docs', OG);
56 card.searchParams.set('title', title);
57 if (section) card.searchParams.set('section', section);
58 if (description) card.searchParams.set('description', description);
59 const image = card.toString();
60 const alt = `${title} · g1t docs`;
61 const meta = (key: 'property' | 'name', name: string, content: string) => ({
62 tag: 'meta' as const,
63 attrs: { [key]: name, content },
64 });
65 // Starlight already writes og:title, og:description, og:url and
66 // twitter:card; these finish the card.
67 route.head.push(
68 meta('property', 'og:image', image),
69 meta('property', 'og:image:type', 'image/png'),
70 meta('property', 'og:image:width', '1200'),
71 meta('property', 'og:image:height', '630'),
72 meta('property', 'og:image:alt', alt),
73 meta('name', 'twitter:title', title),
74 meta('name', 'twitter:image', image),
75 meta('name', 'twitter:image:alt', alt),
76 );
77 if (description) route.head.push(meta('name', 'twitter:description', description));
Docs in the shape of docs.continue.dev78});

This file's history is long; its oldest lines are credited to the oldest commit read.