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

[Feature Request] Support custom API page categories #9998

Open
glopesdev opened this issue Jun 10, 2024 · 1 comment
Open

[Feature Request] Support custom API page categories #9998

glopesdev opened this issue Jun 10, 2024 · 1 comment
Labels
dotnet Generate .NET API reference docs

Comments

@glopesdev
Copy link

glopesdev commented Jun 10, 2024

Is your feature request related to a problem? Please describe.

The API page output format is a great way to help organize large project reference documentation by grouping types into categories, e.g. Classes and Enums. However, in some domains it would be great to have support for additional custom groups, e.g. Attributes or TypeConverters.

Describe the solution you'd like

It would be great if there was a way to specify new custom categories, and provide filters for types to be included in them, e.g. similar to hasAttribute in filter.yml.

For example, in the YAML below we would be able to specify that all classes with the AttributeUsageAttribute would be grouped under a new custom API page type group called Attributes.

apiPages:
- groups:
  - name: Attributes 
    hasAttribute:
      uid: System.AttributeUsageAttribute

Describe alternatives you've considered

I have looked into the DocFX template system for ways to customize the left-hand side TOC and couldn't find anything that could be used to achieve this.

It is unclear from the current docs and template code how the grouping in the API page templates is even achieved in the current DocFX template system, but it could be another way to do it, as long as there are ways to specify the relevant conditionals.

Additional context

It looks like the current feature for API page output format might be implemented here:

Types(t => t.TypeKind is TypeKind.Class, "Classes");
Types(t => t.TypeKind is TypeKind.Struct, "Structs");
Types(t => t.TypeKind is TypeKind.Interface, "Interfaces");
Types(t => t.TypeKind is TypeKind.Enum, "Enums");
Types(t => t.TypeKind is TypeKind.Delegate, "Delegates");

Apparently the t in this lambda is an instance of INamedTypeSymbol from the Roslyn analyzers. If this is the case, it should be possible to add additional predicates to test custom attributes using the ISymbol.GetAttributes method, e.g. something like:

Types(t => t.GetAttributes().Any(a => a.AttributeClass.Name == "System.AttributeUsageTarget"), "Attributes");
@filzrev
Copy link
Contributor

filzrev commented Jun 12, 2024

I have looked into the DocFX template system for ways to customize the left-hand side TOC and couldn't find anything that could be used to achieve this.

TOC categories are inserted by following lines.

InsertCategory(TocNodeType.Class, "Classes");
InsertCategory(TocNodeType.Struct, "Structs");
InsertCategory(TocNodeType.Interface, "Interfaces");
InsertCategory(TocNodeType.Enum, "Enums");
InsertCategory(TocNodeType.Delegate, "Delegates");
InsertCategory(TocNodeType.Constructor, "Constructors");
InsertCategory(TocNodeType.Field, "Fields");
InsertCategory(TocNodeType.Property, "Properties");
InsertCategory(TocNodeType.Method, "Methods");
InsertCategory(TocNodeType.Event, "Events");
InsertCategory(TocNodeType.Operator, "Operators");

TocNode contains symbols data so it can implement Custom Category feature by using this information.
Though it'll requires some code refactoring.


It looks like the current feature for API page output format might be implemented here:

Suggested code seems to be used for Namespace API pages. (e.g. https://dotnet.github.io/docfx/api/Docfx.html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dotnet Generate .NET API reference docs
Projects
None yet
Development

No branches or pull requests

3 participants