Skip to content

Commit

Permalink
new: Support for reference tag [#153] (#154)
Browse files Browse the repository at this point in the history
* Support for @reference.

* tab

* Moved logic before React.
  • Loading branch information
rash805115 authored Sep 2, 2024
1 parent 19c8bff commit 6cea7f9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
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

0 comments on commit 6cea7f9

Please sign in to comment.