Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions plugins/theme/helpers/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,38 @@ export default (ctx) => ({

typedListItem({ label, name, type, comment }) {
const namePart = label ? ` ${label}:` : name ? ` \`${name}\`` : "";

const typePart = type
? ` ${typeof type === "string" ? type : ctx.partials.someType(type)}`
: "";

const descPart = comment
? ` ${ctx.helpers.getCommentParts(comment.summary ?? comment.content)}`
: "";

return `*${namePart}${typePart}${descPart}`;
},

typedList(entries) {
return entries.map(ctx.helpers.typedListItem).join("\n");
},

signatureTitle(name, params) {
const paramsStr = params
.map((param, index) => {
if (param.flags?.isOptional) {
return index === 0 ? `[${param.name}]` : `[, ${param.name}]`;
}
return index === 0 ? param.name : `, ${param.name}`;
})
.join("");
return `\`${name}(${paramsStr})\``;
},

stabilityBlockquote(comment) {
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated removal

if (!comment) return null;

const deprecated = comment.blockTags?.find((t) => t.tag === "@deprecated");
const isExperimental =
comment.modifierTags?.has("@experimental") ||
comment.modifierTags?.has("@beta");
const legacy = comment.blockTags?.find((t) => t.tag === "@legacy");

if (deprecated) {
const message = deprecated.content?.length
? ctx.helpers.getCommentParts(deprecated.content).trim()
Expand All @@ -48,11 +55,9 @@ export default (ctx) => ({
? `> Stability: 0 - Deprecated: ${message}`
: `> Stability: 0 - Deprecated`;
}

if (isExperimental) {
return `> Stability: 1 - Experimental`;
}

if (legacy) {
const message = legacy.content?.length
? ctx.helpers.getCommentParts(legacy.content).trim()
Expand All @@ -61,7 +66,6 @@ export default (ctx) => ({
? `> Stability: 3 - Legacy: ${message}`
: `> Stability: 3 - Legacy`;
}

return null;
},
});
});
3 changes: 1 addition & 2 deletions plugins/theme/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ export class DocKitTheme extends MarkdownTheme {

export class DocKitThemeContext extends MarkdownThemeContext {
helpers = helpers(this);

partials = partials(this);

templates = {
...this.templates,
};
}

/** @param {import('typedoc').Application} app */
export function load(app) {
app.renderer.defineTheme("doc-kit", DocKitTheme);
}
100 changes: 80 additions & 20 deletions plugins/theme/partials/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export default (ctx) => ({
? model.comment
: model.comment || model.parent?.comment;

const stability = ctx.helpers.stabilityBlockquote(comment);

return [
stability,
stability && "",
model.typeParameters?.length &&
ctx.partials.typeParametersList(model.typeParameters, {
headingLevel: options.headingLevel,
Expand All @@ -66,31 +62,95 @@ export default (ctx) => ({
},

memberTitle(model) {
const params = model.signatures?.[0]?.parameters ?? [];
if (model.kind === ReflectionKind.Constructor) {
const className = model.parent?.name ?? model.name;
return ctx.helpers.signatureTitle(`new ${className}`, params);
}
const prefix = getMemberPrefix(model);
const params = model.signatures?.[0]?.parameters;
if (!params.length) return `${prefix}\`${model.name}\``;
return `${prefix}${ctx.helpers.signatureTitle(model.name, params)}`;
},

if (!params) {
return `${prefix}\`${model.name}\``;
memberContainer: (model, options) => {
const md = [];
if (!ctx.router.hasOwnDocument(model)) {
md.push(
"#".repeat(options.headingLevel) + " " +
ctx.partials.memberTitle(model)
);
}
md.push(ctx.partials.member(model, {
headingLevel: options.headingLevel + 1,
nested: options.nested,
}));
return md.filter(Boolean).join("\n\n");
},

const paramsString = params
.map((param, index) => {
const paramName = param.name;
if (param.flags?.isOptional) {
// For optional params, wrap comma + name in brackets (except for first param)
return index === 0 ? `[${paramName}]` : `[, ${paramName}]`;
} else {
// For required params, add comma separator (except for first param)
return index === 0 ? paramName : `, ${paramName}`;
}
constructor: (model, options) => {
return model.signatures?.map(signature => {
const params = signature.parameters ?? [];
return params.length ? ctx.helpers.typedList(params) : "";
}).filter(Boolean).join("\n\n") ?? "";
},

members: (model, options) => {
const items = model.filter(
(item) => !ctx.router.hasOwnDocument(item)
);
return items
.map(item =>
ctx.partials.memberContainer(item, {
headingLevel: options.headingLevel,
groupTitle: options.groupTitle,
})
)
.filter(Boolean)
.join("\n\n");
},

groups: (model, options) => {
return (model.groups ?? [])
.flatMap(group => {
const isPropertiesGroup = group.children?.every(
child => child.kind === ReflectionKind.Property
);
if (isPropertiesGroup) return [];
const children = group.children?.filter(
child => child.isDeclaration()
) ?? [];
if (!children.length) return [];
return [
ctx.partials.members(children, {
headingLevel: options.headingLevel,
groupTitle: group.title,
})
];
})
.join("");
.filter(Boolean)
.join("\n\n");
},

body: (model, options) => {
if (model.groups?.length) {
return ctx.partials.groups(model, {
headingLevel: options.headingLevel,
kind: model.kind,
});
}
return "";
},

return `${prefix}\`${model.name}(${paramsString})\``;
declarationTitle: (model) => {
return ctx.helpers.typedListItem({
name: model.name,
type: model.type,
comment: model.comment,
});
},

Comment on lines +75 to +151
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated

parametersList: ctx.helpers.typedList,
typedParametersList: ctx.helpers.typedList,
typeDeclarationList: ctx.helpers.typedList,
propertiesTable: ctx.helpers.typedList,
});
});