dotnet / docfx

Static site generator for .NET API documentation.
https://dotnet.github.io/docfx/
MIT License
4.01k stars 853 forks source link

Change namespaces order in API reference documentation #7649

Open yevgeni-zolotko opened 2 years ago

yevgeni-zolotko commented 2 years ago

Hello,

Is it possible to change namespaces order in API reference docs generated by docfx from a single assembly from alphabetical sort to custom?

For example, I want my generated HTML navigation tree to go from

+ MyNamespaceA
+ MyNamespaceB
+ MyNamespaceC

to

+ MyNamespaceC
+ MyNamespaceA
+ MyNamespaceB

I.e. I want to specifically configure the MyNamespaceCto be at the top of the list.

ghost commented 2 years ago

You could write a custom post-processor to modify the generated HTML documents. See https://dotnet.github.io/docfx/tutorial/howto_add_a_customized_post_processor.html

Inside the processors Process method you could then iterate over all generated HTML files and reorder the <li> elements in the navigation.


public Manifest Process(Manifest manifest, string outputFolder)
{
  var htmlFilePaths = manifest.Files
    .Where(f => f.OutputFiles.ContainsKey(".html"))
    .Select(f => f.OutputFiles[".html"])
    .Select(f => Path.Combine(outputFolder, f.RelativePath));
  // TODO Patch table of contents in each HTML file
  return manifest;
}