Skip to content

Commit 44e6b07

Browse files
committed
feat: add typescript playground links
1 parent ce5ec88 commit 44e6b07

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

server/utils/readme.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ interface PlaygroundProvider {
1313
id: string // Provider identifier
1414
name: string
1515
domains: string[] // Associated domains
16+
path?: string
1617
icon?: string // Provider icon name
1718
}
1819

@@ -74,6 +75,13 @@ const PLAYGROUND_PROVIDERS: PlaygroundProvider[] = [
7475
domains: ['vite.new'],
7576
icon: 'vite',
7677
},
78+
{
79+
id: 'typescript-playground',
80+
name: 'Typescript Playground',
81+
domains: ['typescriptlang.org'],
82+
path: '/play',
83+
icon: 'typescript',
84+
},
7785
]
7886

7987
/**
@@ -86,7 +94,10 @@ function matchPlaygroundProvider(url: string): PlaygroundProvider | null {
8694

8795
for (const provider of PLAYGROUND_PROVIDERS) {
8896
for (const domain of provider.domains) {
89-
if (hostname === domain || hostname.endsWith(`.${domain}`)) {
97+
if (
98+
(hostname === domain || hostname.endsWith(`.${domain}`)) &&
99+
(!provider.path || parsed.pathname.startsWith(provider.path))
100+
) {
90101
return provider
91102
}
92103
}
@@ -406,10 +417,6 @@ ${html}
406417
const text = this.parser.parseInline(tokens)
407418
const titleAttr = title ? ` title="${title}"` : ''
408419

409-
const isExternal = resolvedHref.startsWith('http://') || resolvedHref.startsWith('https://')
410-
const relAttr = isExternal ? ' rel="nofollow noreferrer noopener"' : ''
411-
const targetAttr = isExternal ? ' target="_blank"' : ''
412-
413420
// Check if this is a playground link
414421
const provider = matchPlaygroundProvider(resolvedHref)
415422
if (provider && !seenUrls.has(resolvedHref)) {
@@ -428,7 +435,7 @@ ${html}
428435

429436
const hrefValue = resolvedHref.startsWith('#') ? resolvedHref.toLowerCase() : resolvedHref
430437

431-
return `<a href="${hrefValue}"${titleAttr}${relAttr}${targetAttr}>${text}</a>`
438+
return `<a href="${hrefValue}"${titleAttr}>${text}</a>`
432439
}
433440

434441
// GitHub-style callouts: > [!NOTE], > [!TIP], etc.

0 commit comments

Comments
 (0)