@@ -59,26 +59,7 @@ export class ExperimentalYamlDocumenter extends YamlDocumenter {
5959 name : apiItem . displayName ,
6060 uid : this . _getUid ( apiItem )
6161 } ;
62- // Filtering out the api-items as we build the tocItems array.
63- if ( apiItem instanceof ApiDocumentedItem ) {
64- const docInlineTag : DocInlineTag | undefined =
65- ( this . _config && this . _config . filterByInlineTag )
66- ? this . _findInlineTagByName ( this . _config . filterByInlineTag , apiItem . tsdocComment )
67- : undefined ;
68-
69- const tagContent : string | undefined =
70- docInlineTag && docInlineTag . tagContent && docInlineTag . tagContent . trim ( ) ;
71-
72- if ( tagContent && this . _tocPointerMap [ tagContent ] ) {
73- // null assertion used because when pointer map was created we checked for presence of empty `items` array
74- this . _tocPointerMap [ tagContent ] . items ! . push ( tocItem ) ;
75- } else {
76- if ( this . _catchAllPointer && this . _catchAllPointer . items ) {
77- this . _catchAllPointer . items . push ( tocItem ) ;
78- }
79- }
80- }
81-
62+ this . _filterItem ( apiItem , tocItem ) ;
8263 }
8364 }
8465
@@ -102,13 +83,15 @@ export class ExperimentalYamlDocumenter extends YamlDocumenter {
10283
10384 // Parses the tocConfig object to build a pointers map of nodes where we want to sort out the API items
10485 private _generateTocPointersMap ( tocConfig : IYamlTocFile | IYamlTocItem ) : void {
86+ const { catchAllCategory } = this . _config ;
87+
10588 if ( tocConfig . items ) {
10689 for ( const tocItem of tocConfig . items ) {
107- if ( tocItem . items && tocItem . items . length > 0 ) {
90+ if ( tocItem . items && tocItem . items . length > 0 && this . _shouldNotIncludeInPointersMap ( tocItem ) ) {
10891 this . _generateTocPointersMap ( tocItem ) ;
10992 } else {
11093 // check for presence of the `catchAllCategory` config option
111- if ( this . _config && this . _config . catchAllCategory && tocItem . name === this . _config . catchAllCategory ) {
94+ if ( catchAllCategory && tocItem . name === catchAllCategory ) {
11295 this . _catchAllPointer = tocItem ;
11396 } else {
11497 this . _tocPointerMap [ tocItem . name ] = tocItem ;
@@ -118,11 +101,57 @@ export class ExperimentalYamlDocumenter extends YamlDocumenter {
118101 }
119102 }
120103
104+ /**
105+ * Filtering out the api-item by inlineTags or category name presence in the item name.
106+ */
107+ private _filterItem ( apiItem : ApiItem , tocItem : IYamlTocItem ) : void {
108+ const { categoryInlineTag, categorizeByName } = this . _config ;
109+ const { name : itemName } = tocItem ;
110+ let filtered : boolean = false ;
111+
112+ // First we attempt to filter by inline tag if provided.
113+ if ( apiItem instanceof ApiDocumentedItem ) {
114+ const docInlineTag : DocInlineTag | undefined =
115+ categoryInlineTag
116+ ? this . _findInlineTagByName ( categoryInlineTag , apiItem . tsdocComment )
117+ : undefined ;
118+
119+ const tagContent : string | undefined =
120+ docInlineTag && docInlineTag . tagContent && docInlineTag . tagContent . trim ( ) ;
121+
122+ if ( tagContent && this . _tocPointerMap [ tagContent ] ) {
123+ // null assertion used because when pointer map was created we checked for presence of empty `items` array
124+ this . _tocPointerMap [ tagContent ] . items ! . push ( tocItem ) ;
125+ filtered = true ;
126+ }
127+ }
128+
129+ // If not filtered by inline tag and `categorizeByName` config is enabled attempt to filter it by category name.
130+ if ( ! filtered && categorizeByName ) {
131+ const pointers : string [ ] = Object . keys ( this . _tocPointerMap ) ;
132+ for ( let i : number = 0 , length : number = pointers . length ; i < length ; i ++ ) {
133+ if ( itemName . indexOf ( pointers [ i ] ) !== - 1 ) {
134+ // null assertion used because when pointer map was created we checked for presence of empty `items` array
135+ this . _tocPointerMap [ pointers [ i ] ] . items ! . push ( tocItem ) ;
136+ filtered = true ;
137+ break ;
138+ }
139+ }
140+ }
141+
142+ // If item still not filtered and a `catchAllCategory` config provided push it to it.
143+ if ( ! filtered && this . _catchAllPointer && this . _catchAllPointer . items ) {
144+ this . _catchAllPointer . items . push ( tocItem ) ;
145+ }
146+ }
147+
121148 // This is a direct copy of a @docCategory inline tag finder in office-ui-fabric-react,
122149 // but is generic enough to be used for any inline tag
123150 private _findInlineTagByName ( tagName : string , docComment : DocComment | undefined ) : DocInlineTag | undefined {
151+ const tagNameToCheck : string = `@${ tagName } ` ;
152+
124153 if ( docComment instanceof DocInlineTag ) {
125- if ( docComment . tagName === tagName ) {
154+ if ( docComment . tagName === tagNameToCheck ) {
126155 return docComment ;
127156 }
128157 }
@@ -136,4 +165,12 @@ export class ExperimentalYamlDocumenter extends YamlDocumenter {
136165 }
137166 return undefined ;
138167 }
168+
169+ private _shouldNotIncludeInPointersMap ( item : IYamlTocItem ) : boolean {
170+ const { nonEmptyCategoryNodeNames } = this . _config ;
171+ if ( nonEmptyCategoryNodeNames && nonEmptyCategoryNodeNames . length ) {
172+ return nonEmptyCategoryNodeNames . indexOf ( item . name ) === - 1 ;
173+ }
174+ return true ;
175+ }
139176}
0 commit comments