Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support for reference tag [#153] #154

Merged
merged 3 commits into from
Sep 2, 2024
Merged
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
3 changes: 3 additions & 0 deletions packages/plugin/src/components/Comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export function Comment({ comment, root, hideTags = [] }: CommentProps) {
return null;
}

// Hide custom tags.
hideTags.push('@reference');

const blockTags =
comment.blockTags?.filter((tag) => {
if (hideTags.includes(tag.tag)) {
Expand Down
37 changes: 36 additions & 1 deletion packages/plugin/src/plugin/data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs';
import path from 'path';
import * as TypeDoc from 'typedoc';
import { JSONOutput, ReflectionKind } from 'typedoc';
import { type InlineTagDisplayPart, type JSONOutput, ReflectionKind } from 'typedoc'
import ts from 'typescript';
import { normalizeUrl } from '@docusaurus/utils';
import type {
Expand Down Expand Up @@ -110,7 +110,42 @@ export function createReflectionMap(
): TSDDeclarationReflectionMap {
const map: TSDDeclarationReflectionMap = {};

// eslint-disable-next-line complexity
items.forEach((item) => {
// Add @reference categories to reflection.
const referenceCategories: Record<string, { title: string; children: number[] }> = {};
for (const tag of item.comment?.blockTags ?? []) {
if (tag.tag === '@reference' && tag.content.length >= 2 && tag.content[0].kind === 'text') {
const categoryName = tag.content[0].text.trim();
const ref = (tag.content as InlineTagDisplayPart[]).find((t) => t.tag === '@link');

if (ref && typeof ref.target === 'number') {
if (!(categoryName in referenceCategories)) {
referenceCategories[categoryName] = { title: categoryName, children: [] };
}

if (!referenceCategories[categoryName].children.includes(ref.target)) {
referenceCategories[categoryName].children.push(ref.target);
}
}
}
}

// Update categories with reference categories.
if (!item.categories) {
// eslint-disable-next-line no-param-reassign
item.categories = [];
}
for (const category of Object.values(referenceCategories)) {
if (category.children.length > 0) {
const index = item.categories.findIndex((c) => c.title === category.title);
if (index === -1) {
item.categories.push(category);
}
}
}

// Add item.
map[item.id] = item;
});

Expand Down
Loading