Skip to content

Commit 158a806

Browse files
Copilotteemingc
andauthored
fix: make documentation page titles distinguishable by section (#1607)
* Initial plan * Update page titles to be more distinguishable across docs sections Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com> * Use get_topic_title helper instead of duplicating logic Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com> * Move topics logic to shared utils directory Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com> * doing what copilot dont * copilot messed this up --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: teemingc <54401897+teemingc@users.noreply.github.com> Co-authored-by: Tee Ming Chew <chew.tee.ming@nindatech.com>
1 parent 3e3d434 commit 158a806

File tree

7 files changed

+35
-19
lines changed

7 files changed

+35
-19
lines changed

apps/svelte.dev/src/lib/server/llms.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { minimatch } from 'minimatch';
22
import { dev } from '$app/environment';
33
import { index } from './content';
4+
import type { Topic } from '$lib/topics';
45

56
interface GenerateLlmContentOptions {
67
ignore?: string[];
@@ -16,11 +17,6 @@ interface MinimizeOptions {
1617
remove_prettier_ignore: boolean;
1718
}
1819

19-
interface Topic {
20-
slug: string;
21-
title: string;
22-
}
23-
2420
const defaults: MinimizeOptions = {
2521
remove_legacy: false,
2622
remove_note_blocks: false,
@@ -63,12 +59,6 @@ export function generate_llm_content(options: GenerateLlmContentOptions): string
6359
return content;
6460
}
6561

66-
export const topics: Topic[] = [
67-
{ slug: 'svelte', title: 'Svelte' },
68-
{ slug: 'kit', title: 'SvelteKit' },
69-
{ slug: 'cli', title: 'the Svelte CLI' }
70-
];
71-
7262
export function get_documentation_title(topic: Topic): string {
7363
return `This is the developer documentation for ${topic.title}.`;
7464
}

apps/svelte.dev/src/lib/topics.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export interface Topic {
2+
slug: string;
3+
title: string;
4+
}
5+
6+
export const topics = [
7+
{ slug: 'svelte', title: 'Svelte' },
8+
{ slug: 'kit', title: 'SvelteKit' },
9+
{ slug: 'cli', title: 'Svelte CLI' },
10+
{ slug: 'mcp', title: 'Svelte MCP' }
11+
] as const satisfies Topic[];
12+
13+
const DEFAULT_TITLE = 'Svelte';
14+
15+
export function get_topic_title(slug: string | undefined): string {
16+
if (!slug) return DEFAULT_TITLE;
17+
const topic = topics.find((t) => t.slug === slug);
18+
return topic?.title ?? DEFAULT_TITLE;
19+
}

apps/svelte.dev/src/routes/docs/[topic]/[...path]/+page.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { goto } from '$app/navigation';
1010
import { escape_html } from '$lib/utils/escape';
1111
import { page } from '$app/state';
12+
import { get_topic_title } from '$lib/topics';
1213
1314
let { data } = $props();
1415
@@ -22,6 +23,8 @@
2223
return `https://github.com/sveltejs/${name}/edit/main/documentation/${link}`;
2324
});
2425
26+
const topic_title = $derived(get_topic_title(page.params.topic));
27+
2528
onMount(() => {
2629
// hash was lowercase in v4 docs and varying case in v5 docs
2730
const hash = location.hash.slice(1);
@@ -58,15 +61,15 @@
5861
</script>
5962

6063
<svelte:head>
61-
<title>{data.document.metadata.title} • Docs • Svelte</title>
64+
<title>{data.document.metadata.title} • {topic_title} Docs</title>
6265

63-
<meta name="twitter:title" content="{data.document.metadata.title}Docs • Svelte" />
66+
<meta name="twitter:title" content="{data.document.metadata.title}{topic_title} Docs" />
6467
<meta
6568
name="twitter:description"
66-
content="{data.document.metadata.title}Svelte documentation"
69+
content="{data.document.metadata.title}{topic_title} documentation"
6770
/>
6871
<meta name="twitter:card" content="summary_large_image" />
69-
<meta name="description" content="{data.document.metadata.title}Svelte documentation" />
72+
<meta name="description" content="{data.document.metadata.title}{topic_title} documentation" />
7073
<meta
7174
name="twitter:image"
7275
content="https://svelte.dev/docs/{page.params.topic}/{page.params.path}/card.png"

apps/svelte.dev/src/routes/docs/[topic]/[...path]/llms.txt/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { error } from '@sveltejs/kit';
22
import { docs } from '$lib/server/content.js';
3-
import { generate_llm_content, get_documentation_title, topics } from '$lib/server/llms';
3+
import { generate_llm_content, get_documentation_title } from '$lib/server/llms';
4+
import { topics } from '$lib/topics';
45

56
export const prerender = true;
67

apps/svelte.dev/src/routes/llms-full.txt/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { generate_llm_content, topics } from '$lib/server/llms';
1+
import { generate_llm_content } from '$lib/server/llms';
2+
import { topics } from '$lib/topics';
23

34
export const prerender = true;
45

apps/svelte.dev/src/routes/llms-medium.txt/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { generate_llm_content, topics } from '$lib/server/llms';
1+
import { generate_llm_content } from '$lib/server/llms';
2+
import { topics } from '$lib/topics';
23

34
export function GET() {
45
const main_content = generate_llm_content({

apps/svelte.dev/src/routes/llms.txt/+server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { get_documentation_title, topics } from '$lib/server/llms';
1+
import { get_documentation_title } from '$lib/server/llms';
2+
import { topics } from '$lib/topics';
23
import template from './template.md?raw';
34

45
const DOMAIN = `https://svelte.dev`;

0 commit comments

Comments
 (0)