Skip to content

Commit

Permalink
fix(website): link dapi-types to proper website (#9388)
Browse files Browse the repository at this point in the history
  • Loading branch information
suneettipirneni committed Apr 14, 2023
1 parent 8314317 commit cac3c07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion apps/website/src/components/ExcerptText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ApiModel, Excerpt } from '@microsoft/api-extractor-model';
import { ExcerptTokenKind } from '@microsoft/api-extractor-model';
import { ItemLink } from './ItemLink';
import { resolveItemURI } from './documentation/util';
import { DISCORD_API_TYPES_DOCS_URL } from '~/util/constants';

export interface ExcerptTextProps {
/**
Expand All @@ -20,8 +21,24 @@ export interface ExcerptTextProps {
export function ExcerptText({ model, excerpt }: ExcerptTextProps) {
return (
<>
{excerpt.spannedTokens.map((token) => {
{excerpt.spannedTokens.map((token, idx) => {
if (token.kind === ExcerptTokenKind.Reference) {
const source = token.canonicalReference?.source;

if (source && 'packageName' in source && source.packageName === 'discord-api-types') {
const meaning = token.canonicalReference.symbol?.meaning;
const href =
meaning === 'type'
? `${DISCORD_API_TYPES_DOCS_URL}#${token.text}`
: `${DISCORD_API_TYPES_DOCS_URL}/${meaning}/${token.text}`;

return (
<a className="text-blurple" href={href} key={idx} rel="external noreferrer noopener" target="_blank">
{token.text}
</a>
);
}

const item = model.resolveDeclarationReference(token.canonicalReference!, model).resolvedApiItem;

if (!item) {
Expand Down
3 changes: 3 additions & 0 deletions apps/website/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ client.on('interactionCreate', async (interaction) => {
});
await client.login(TOKEN);`;

export const DISCORD_API_TYPES_VERSION = 'v10';
export const DISCORD_API_TYPES_DOCS_URL = `https://discord-api-types.dev/api/discord-api-types-${DISCORD_API_TYPES_VERSION}`;

1 comment on commit cac3c07

@vercel
Copy link

@vercel vercel bot commented on cac3c07 Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.