Skip to content

Commit e15a874

Browse files
authored
Merge 6fb45cc into f092a90
2 parents f092a90 + 6fb45cc commit e15a874

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/Docfx.Build/ApiPage/ApiPageProcessor.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ public FileModel Load(FileAndType file, ImmutableDictionary<string, object> meta
4141
var yml = EnvironmentContext.FileAbstractLayer.ReadAllText(file.File);
4242
var json = JsonSerializer.Serialize(deserializer.Deserialize<object>(yml));
4343
var data = JsonSerializer.Deserialize<ApiPage>(json, ApiPage.JsonSerializerOptions);
44-
var content = new Dictionary<string, object>(metadata.OrderBy(item => item.Key))
44+
var content = new Dictionary<string, object>(metadata.OrderBy(item => item.Key));
45+
46+
if (data.metadata is not null)
4547
{
46-
["title"] = data.title,
47-
["content"] = ApiPageHtmlTemplate.Render(data, Markup).ToString(),
48-
["yamlmime"] = "ApiPage",
49-
["_disableNextArticle"] = true,
50-
};
48+
foreach (var (key, value) in data.metadata.OrderBy(item => item.Key))
49+
content[key] = value.Value;
50+
}
51+
52+
content["title"] = data.title;
53+
content["content"] = ApiPageHtmlTemplate.Render(data, Markup).ToString();
54+
content["yamlmime"] = "ApiPage";
55+
content["_disableNextArticle"] = true;
5156

5257
var localPathFromRoot = PathUtility.MakeRelativePath(EnvironmentContext.BaseDirectory, EnvironmentContext.FileAbstractLayer.GetPhysicalPath(file.File));
5358

src/Docfx.Dotnet/Docfx.Dotnet.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
</ItemGroup>
3030

3131
<ItemGroup>
32+
<PackageReference Include="HtmlAgilityPack" />
3233
<PackageReference Include="ICSharpCode.Decompiler" />
3334
<PackageReference Include="IgnoresAccessChecksToGenerator" PrivateAssets="All" />
3435
<PackageReference Include="OneOf" />

src/Docfx.Dotnet/DotnetApiCatalog.ApiPage.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Docfx.Common.Git;
1111
using Docfx.DataContracts.ManagedReference;
1212
using Docfx.Plugins;
13+
using HtmlAgilityPack;
1314
using Microsoft.CodeAnalysis;
1415
using Microsoft.CodeAnalysis.Shared.Extensions;
1516
using OneOf;
@@ -96,9 +97,14 @@ _ when SymbolHelper.IsMember(method) => "Method",
9697
throw new NotSupportedException($"Unknown symbol type kind {symbols[0].symbol}");
9798
}
9899

100+
var metadata = new Dictionary<string, OneOf<string, string[]>>();
101+
if (!string.IsNullOrEmpty(comment?.Summary))
102+
metadata["description"] = HtmlInnerText(comment.Summary);
103+
99104
output(config.OutputFolder, id, new ApiPage
100105
{
101106
title = title,
107+
metadata = metadata.Count > 0 ? metadata : null,
102108
languageId = "csharp",
103109
body = body.ToArray(),
104110
});
@@ -760,6 +766,13 @@ Span Link(string text, string? url)
760766
});
761767
}
762768
}
769+
770+
static string HtmlInnerText(string html)
771+
{
772+
var doc = new HtmlDocument();
773+
doc.LoadHtml(html);
774+
return doc.DocumentNode.InnerText;
775+
}
763776
}
764777

765778
#endif

templates/common/ManagedReference.common.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ exports.transform = function (model) {
3636
}
3737
}
3838

39+
if (model.summary && !model.description) {
40+
model.description = model.summary.replace(/<.*?>/gi, '').replace(/(\r\n|\n|\r)/gm, ' ');
41+
}
42+
3943
return model;
4044
}
4145

0 commit comments

Comments
 (0)