mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat: link basic types to MDN/TS documentation (#9913)
* feat: link basic types to MDN/TS documentation * refactor: requested changes
This commit is contained in:
9
apps/website/src/components/DocumentationLink.tsx
Normal file
9
apps/website/src/components/DocumentationLink.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { PropsWithChildren } from 'react';
|
||||
|
||||
export function DocumentationLink({ children, href }: PropsWithChildren<{ readonly href: string }>) {
|
||||
return (
|
||||
<a className="text-blurple" href={href} rel="external noreferrer noopener" target="_blank">
|
||||
{children}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import type { ApiModel, Excerpt } from '@discordjs/api-extractor-model';
|
||||
import { ExcerptTokenKind } from '@discordjs/api-extractor-model';
|
||||
import { BuiltinDocumentationLinks } from '~/util/builtinDocumentationLinks';
|
||||
import { DISCORD_API_TYPES_DOCS_URL } from '~/util/constants';
|
||||
import { DocumentationLink } from './DocumentationLink';
|
||||
import { ItemLink } from './ItemLink';
|
||||
import { resolveItemURI } from './documentation/util';
|
||||
|
||||
@@ -25,6 +27,15 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
|
||||
// TODO: Real fix in api-extractor needed
|
||||
const text = token.text.replaceAll('\n', '').replaceAll(/\s{2}$/g, '');
|
||||
if (token.kind === ExcerptTokenKind.Reference) {
|
||||
if (text in BuiltinDocumentationLinks) {
|
||||
const href = BuiltinDocumentationLinks[text as keyof typeof BuiltinDocumentationLinks];
|
||||
return (
|
||||
<DocumentationLink key={`${text}-${idx}`} href={href}>
|
||||
{text}
|
||||
</DocumentationLink>
|
||||
);
|
||||
}
|
||||
|
||||
const source = token.canonicalReference?.source;
|
||||
const symbol = token.canonicalReference?.symbol;
|
||||
if (source && 'packageName' in source && source.packageName === 'discord-api-types' && symbol) {
|
||||
@@ -38,9 +49,9 @@ export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
|
||||
else href += `/${meaning}/${text}`;
|
||||
|
||||
return (
|
||||
<a className="text-blurple" href={href} key={idx} rel="external noreferrer noopener" target="_blank">
|
||||
<DocumentationLink key={`${text}-${idx}`} href={href}>
|
||||
{text}
|
||||
</a>
|
||||
</DocumentationLink>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user