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

DocFxTocGenerator: Fixed override for folders to be used over index or readme #78

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,54 @@ public async Task Run_Issue_27_Run2()
string toc = _fileService.ReadAllText(_fileService.GetFullPath("toc.yml"));
toc.Should().Be(expected);
}

[Fact]
public async Task Run_Issue_77()
{
// arrange
_fileService.Files.Clear();
_fileService.AddFile(string.Empty, "README.md", string.Empty.AddHeading("Issue 77 override problem", 1).AddParagraphs(1));
_fileService.AddFile(string.Empty, ".override",
@"override-folder;The Folder Override");
var folder = _fileService.AddFolder("override-folder");
_fileService.AddFile(folder, "README.md", string.Empty.AddHeading("Title of the README", 1).AddParagraphs(1));
_fileService.AddFile(folder, "content.md", string.Empty.AddHeading("Some content", 1).AddParagraphs(1));

ContentInventoryAction content = new(_fileService.Root, useOrder: false, useIgnore: false, useOverride: true, camelCasing: false, _fileService, _logger);
await content.RunAsync();

EnsureIndexAction index = new(content.RootFolder!, Index.IndexGenerationStrategy.Never, camelCasing: false, _fileService, _logger);
await index.RunAsync();

GenerateTocAction action = new(
_fileService.Root,
content.RootFolder!,
folderReferenceStrategy: TocFolderReferenceStrategy.IndexReadme,
orderStrategy: TocOrderStrategy.All,
maxDepth: 0,
_fileService,
_logger);

int originalCount = _fileService.Files.Count();

string expected =
@"# This is an automatically generated file
- name: Issue 77 override problem
href: README.md
- name: The Folder Override
href: override-folder/README.md
items:
- name: Some content
href: override-folder/content.md
".NormalizeContent();

// act
ReturnCode ret = await action.RunAsync();

// assert
ret.Should().Be(ReturnCode.Normal);
_fileService.Files.Should().HaveCount(originalCount + 1);
string toc = _fileService.ReadAllText(_fileService.GetFullPath("toc.yml"));
toc.Should().Be(expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ public void FillDemoSet()

folder = AddFolder("deep-tree");
folder = AddFolder("deep-tree/level1");
AddFile(folder, ".override",
@"level2;The Second Level");
folder = AddFolder("deep-tree/level1/level2");
AddFile(folder, "index.md", string.Empty
.AddHeading("Index of LEVEL 2", 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public async Task GetTocItems_GetTocFolderReferenceIndex()
toc.Href.Should().BeNull();

toc.Items.Count.Should().Be(1);
toc.Items[0].Name.Should().Be("Index of LEVEL 2");
toc.Items[0].Name.Should().Be("The Second Level");
toc.Items[0].Href.Should().Be("deep-tree/level1/level2/index.md");
}

Expand Down Expand Up @@ -429,7 +429,7 @@ public async Task SerializeTocItem_Hierarchy()
items:
- name: Level1
items:
- name: Level2
- name: The Second Level
items:
- name: Index of LEVEL 2
href: deep-tree/level1/level2/index.md
Expand Down Expand Up @@ -548,7 +548,7 @@ public async Task SerializeTocItem_Hierarchy_CamelCase()
items:
- name: level1
items:
- name: level2
- name: The Second Level
items:
- name: index of LEVEL 2
href: deep-tree/level1/level2/index.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public Task<ReturnCode> RunAsync()
if (parent.OverrideList.TryGetValue(folder.Name, out string? name))
{
folder.DisplayName = name;
folder.IsDisplayNameOverride = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public FileData CreateFileData(FolderData folder, string file)
{
// override the display name
filedata.DisplayName = name;
filedata.IsDisplayNameOverride = true;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public record FolderFileBase
/// </summary>
public string DisplayName { get; set; } = string.Empty;

/// <summary>
/// Gets or sets a value indicating whether the display name is coming from the .override.
/// This should always be the preference then.
/// </summary>
public bool IsDisplayNameOverride { get; set; }

/// <summary>
/// Gets or sets the sequence value of this item.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
// </copyright>
using System.CodeDom.Compiler;
using System.Xml.Linq;
using DocFxTocGenerator.FileService;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -62,6 +63,13 @@ public TocItem GetTocItemsForFolder(FolderData folder, int depth)
Base = folder,
};

// we took one of the defaults, but if the parent has an override for this folder
// the override must take preference. (fixing issue #77)
if (folder.IsDisplayNameOverride)
{
tocItem.Name = folder.DisplayName;
}

// first add all sub folders
foreach (var subfolder in folder.Folders)
{
Expand Down