Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotnet/docfx
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 64ee0daef8db5c9807d48ed08ccc6dec339ba1da
Choose a base ref
..
head repository: dotnet/docfx
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8703a511cdf469ef14c66ad7f34381266d651b8d
Choose a head ref
Showing with 29 additions and 31 deletions.
  1. +20 −20 src/Microsoft.DocAsCode.App/Helpers/DocumentBuilderWrapper.cs
  2. +9 −11 test/docfx.Tests/DocsetTest.cs
40 changes: 20 additions & 20 deletions src/Microsoft.DocAsCode.App/Helpers/DocumentBuilderWrapper.cs
Original file line number Diff line number Diff line change
@@ -254,6 +254,14 @@ private static ImmutableDictionary<string, object> GetGlobalMetadata(BuildJsonCo
{
var result = new Dictionary<string, object>();

if (config.GlobalMetadata != null)
{
foreach (var (key, value) in config.GlobalMetadata)
{
result[key] = value;
}
}

if (config.GlobalMetadataFilePaths != null)
{
foreach (var path in config.GlobalMetadataFilePaths)
@@ -265,21 +273,25 @@ private static ImmutableDictionary<string, object> GetGlobalMetadata(BuildJsonCo
}
}

if (config.GlobalMetadata != null)
{
foreach (var (key, value) in config.GlobalMetadata)
{
result[key] = value;
}
}

return result.ToImmutableDictionary();
}

private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfig config)
{
var result = new Dictionary<string, List<FileMetadataItem>>();

if (config.FileMetadata != null)
{
foreach (var (key, value) in config.FileMetadata)
{
var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
}
}
}

if (config.FileMetadataFilePaths != null)
{
foreach (var path in config.FileMetadataFilePaths)
@@ -295,18 +307,6 @@ private static FileMetadata GetFileMetadata(string baseDirectory, BuildJsonConfi
}
}

if (config.FileMetadata != null)
{
foreach (var (key, value) in config.FileMetadata)
{
var list = result.TryGetValue(key, out var items) ? items : result[key] = new();
foreach (var pair in value.Items)
{
list.Add(new FileMetadataItem(pair.Glob, key, pair.Value));
}
}
}

return new FileMetadata(baseDirectory, result.ToDictionary(p => p.Key, p => p.Value.ToImmutableArray()));
}

20 changes: 9 additions & 11 deletions test/docfx.Tests/DocsetTest.cs
Original file line number Diff line number Diff line change
@@ -91,33 +91,32 @@ public static async Task Build_With_Global_Metadata_Files()
"exportRawModel": true,
"globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"],
"globalMetadata": {
"meta1": "1",
"meta3": "3"
"meta1": "docfx.json",
"meta3": "docfx.json"
}
}
}
""",
["projectMetadata1.json"] =
"""
{
"meta1": "0",
"meta3": "1"
"meta1": "projectMetadata1.json",
"meta2": "projectMetadata2.json"
}
""",
["projectMetadata2.json"] =
"""
{
"meta2": "2",
"meta3": "2"
"meta2": "projectMetadata2.json"
}
""",
["index.md"] = ""
});

var metadata = JsonDocument.Parse(outputs["index.raw.json"]()).RootElement;
Assert.Equal("1", metadata.GetProperty("meta1").GetString());
Assert.Equal("2", metadata.GetProperty("meta2").GetString());
Assert.Equal("3", metadata.GetProperty("meta3").GetString());
Assert.Equal("projectMetadata1.json", metadata.GetProperty("meta1").GetString());
Assert.Equal("projectMetadata2.json", metadata.GetProperty("meta2").GetString());
Assert.Equal("docfx.json", metadata.GetProperty("meta3").GetString());
}

[Fact]
@@ -145,7 +144,6 @@ public static async Task Build_With_File_Metadata_Files()
"""
{
"meta1": {
"a.md": "fileMetadata1.json",
"b.md": "fileMetadata1.json"
}
}
@@ -165,7 +163,7 @@ public static async Task Build_With_File_Metadata_Files()

var a = JsonDocument.Parse(outputs["a.raw.json"]()).RootElement;
var b = JsonDocument.Parse(outputs["b.raw.json"]()).RootElement;
Assert.Equal("docfx.json", a.GetProperty("meta1").GetString());
Assert.Equal("fileMetadata1.json", a.GetProperty("meta1").GetString());
Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString());
}
}