我是这样做的:
"overwrite": [
{
"files": [
"apidoc/**.md",
"namespaces/**.md"
],
"exclude": [
"obj/**",
"_site/**"
]
}
],
在namespaces文件夹中为每个要添加文档的命名空间创建一个Markdown文件。最好将这些文件与命名空间同名。
文件应该具有一个YAML头,其UID与命名空间的名称匹配。 summary:*content行告诉docfx用此文件的内容覆盖 命名空间的摘要。
页面的其余部分是标准Markdown,将成为命名空间的摘要。 例如:
---
uid:My.Groovy.Namespace
摘要:*content
---
My.Groovy.Namespace命名空间包含一堆类和接口。
我可能对这个问题非常晚,但我面临了类似的问题,我找到的解决方案涉及修改docfx源代码并添加帮助类,就像Sandcastle
的解决方案一样。
免责声明:
我不声称我展示的解决方案在程序上是稳定的、安全的或者甚至是正确的。我不声称这个解决方案将在任何情况下或任何用途中都有效。我只验证,对于我来说,它完美地工作了,尽管我认识到它只是一个快速的解决方法。
docfx-2.59.2\src\Microsoft.DocAsCode.Metadata.ManagedReference\ExtractMetadataWorker.cs
。
GetMetadataFromProjectLevelCache
的方法,该方法在某个时刻从树形式中提取引用项目中的元数据。private Tuple<MetadataItem, bool> GetMetadataFromProjectLevelCache(IBuildController controller, IInputParameters key){
// [...]
projectMetadata = controller.ExtractMetadata(key); // THIS line
// [...]
}
private Tuple<MetadataItem, bool> GetMetadataFromProjectLevelCache(IBuildController controller, IInputParameters key){
// [...]
projectMetadata = controller.ExtractMetadata(key);
ExtractNamespaceDocumentation(projectMetadata); // THIS line
// [...]
}
private void ExtractNamespaceDocumentation(MetadataItem node)
{
// Terminal nodes are not of our interest in any case
// Even if it's a namespace, it does not contain documentation
if (node.Items is not { Count: > 0 }) return;
// If it is namespace
if (node.Type == MemberType.Namespace)
{
// Get (if any), the child that is class and is named "_NamespaceDoc"
var doc = node.Items.FirstOrDefault(x =>
x.Type == MemberType.Class && x.Name.Split('.').Last() == "_NamespaceDoc");
// If we didn't found such class, the namespace does not contain documentation.
// Leave and don't go further.
if (doc is null) return;
// Else, assign the class' Summary and remarks to the Namespace and remove the class from the tree.
node.Summary = doc.Summary;
node.Remarks = doc.Remarks;
node.Items.Remove(doc);
// job finished for this namespace, we do not want to go further down the tree.
return;
}
// For non-namespace intermediate nodes (IE assembly nodes), visit the children.
foreach (var child in node.Items) ExtractNamespaceDocumentation(child);
}
docfx-2.59.2\src\docfx\bin\Debug\net472
的新创建的 docfx.exe
,成功检测到所有名为 _NamespaceDoc
的类,并使用它们的 <summary>
标签填充它们所在的命名空间。
.cs
文件来包含所有_NamespaceDoc
类,这样当我想要发布项目时就更容易禁用整个文件。这个文件看起来像这样:namespace RootNamespace
{
/// <summary>
/// Documentation for the Root Namespace
/// </summary>
public static class _NamespaceDoc { }
}
namespace RootNamespace.SubFolder
{
/// <summary>
/// Documentation for the Root Namespace's `SubFolder` Sub-Namespace.
/// </summary>
public static class _NamespaceDoc { }
}
// [...]
docfx
的开发人员和贡献者更可靠地实现此功能。
关于这种方法的更多信息,我已经在docfx的github仓库上开始了讨论。