mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
refactor(website): consolidate badge logic (#9417)
Co-authored-by: Noel <buechler.noel@outlook.com>
This commit is contained in:
@@ -38,7 +38,7 @@ export function Header({
|
||||
{name}
|
||||
</span>
|
||||
{sourceURL ? (
|
||||
<a className="text-blurple" href={sourceURL}>
|
||||
<a className="text-blurple" href={sourceURL} rel="external noopener noreferrer" target="_blank">
|
||||
<VscFileCode />
|
||||
</a>
|
||||
) : null}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import type { ApiDeclaredItem, ApiItemContainerMixin, ApiTypeParameterListMixin } from '@microsoft/api-extractor-model';
|
||||
import type { ReactNode } from 'react';
|
||||
// import { Outline } from '../Outline';
|
||||
import { SyntaxHighlighter } from '../SyntaxHighlighter';
|
||||
import { Documentation } from './Documentation';
|
||||
import { MethodsSection } from './section/MethodsSection';
|
||||
import { PropertiesSection } from './section/PropertiesSection';
|
||||
import { SummarySection } from './section/SummarySection';
|
||||
import { TypeParameterSection } from './section/TypeParametersSection';
|
||||
import { hasProperties, hasMethods /* , serializeMembers */ } from './util';
|
||||
|
||||
export function MemberContainerDocumentation({
|
||||
item,
|
||||
subheading,
|
||||
}: {
|
||||
item: ApiDeclaredItem & ApiItemContainerMixin & ApiTypeParameterListMixin;
|
||||
subheading?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<Documentation>
|
||||
{subheading}
|
||||
{/* @ts-expect-error async component */}
|
||||
<SyntaxHighlighter code={item.excerpt.text} />
|
||||
<SummarySection item={item} />
|
||||
{item.typeParameters.length ? <TypeParameterSection item={item} /> : null}
|
||||
{hasProperties(item) ? <PropertiesSection item={item} /> : null}
|
||||
{hasMethods(item) ? <MethodsSection item={item} /> : null}
|
||||
|
||||
{/* <Outline members={serializeMembers(item)} /> */}
|
||||
</Documentation>
|
||||
);
|
||||
}
|
||||
@@ -2,23 +2,15 @@ import type { ApiConstructor } from '@microsoft/api-extractor-model';
|
||||
import { VscSymbolMethod } from '@react-icons/all-files/vsc/VscSymbolMethod';
|
||||
import { ParameterTable } from '../../ParameterTable';
|
||||
import { TSDoc } from '../tsdoc/TSDoc';
|
||||
import { parametersString } from '../util';
|
||||
import { DocumentationSection } from './DocumentationSection';
|
||||
|
||||
function getShorthandName(ctor: ApiConstructor) {
|
||||
return `constructor(${ctor.parameters.reduce((prev, cur, index) => {
|
||||
if (index === 0) {
|
||||
return `${prev}${cur.isOptional ? `${cur.name}?` : cur.name}`;
|
||||
}
|
||||
|
||||
return `${prev}, ${cur.isOptional ? `${cur.name}?` : cur.name}`;
|
||||
}, '')})`;
|
||||
}
|
||||
import { CodeHeading } from '~/components/CodeHeading';
|
||||
|
||||
export function ConstructorSection({ item }: { item: ApiConstructor }) {
|
||||
return (
|
||||
<DocumentationSection icon={<VscSymbolMethod size={20} />} padded title="Constructor">
|
||||
<div className="flex flex-col gap-2">
|
||||
<h4 className="break-all font-mono text-lg font-bold">{getShorthandName(item)}</h4>
|
||||
<CodeHeading>{`constructor(${parametersString(item)})`}</CodeHeading>
|
||||
{item.tsdocComment ? <TSDoc item={item} tsdoc={item.tsdocComment} /> : null}
|
||||
<ParameterTable item={item} />
|
||||
</div>
|
||||
|
||||
@@ -6,10 +6,13 @@ import type {
|
||||
ApiMethodSignature,
|
||||
ApiProperty,
|
||||
ApiPropertySignature,
|
||||
ApiDocumentedItem,
|
||||
ApiParameterListMixin,
|
||||
} from '@microsoft/api-extractor-model';
|
||||
import type { TableOfContentsSerialized } from '../TableOfContentItems';
|
||||
import { METHOD_SEPARATOR, OVERLOAD_SEPARATOR } from '~/util/constants';
|
||||
import { resolveMembers } from '~/util/members';
|
||||
import { resolveParameters } from '~/util/model';
|
||||
|
||||
export function hasProperties(item: ApiItemContainerMixin) {
|
||||
return resolveMembers(item, memberPredicate).some(
|
||||
@@ -56,3 +59,13 @@ export function serializeMembers(clazz: ApiItemContainerMixin): TableOfContentsS
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function parametersString(item: ApiDocumentedItem & ApiParameterListMixin) {
|
||||
return resolveParameters(item).reduce((prev, cur, index) => {
|
||||
if (index === 0) {
|
||||
return `${prev}${cur.isOptional ? `${cur.name}?` : cur.name}`;
|
||||
}
|
||||
|
||||
return `${prev}, ${cur.isOptional ? `${cur.name}?` : cur.name}`;
|
||||
}, '');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user