Skip to content

Commit

Permalink
Merge pull request #47 from Ellerbach/fix-index-generation
Browse files Browse the repository at this point in the history
Fixing index not generated on root
  • Loading branch information
Ellerbach authored Dec 8, 2023
2 parents c861e11 + 1008680 commit 12becfd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/DocFxTocGenerator/DocFxTocGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath=""/>
<None Include="README.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
Expand Down
31 changes: 17 additions & 14 deletions src/DocFxTocGenerator/TocGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,18 @@ private static string WalkDirectoryTree(DirectoryInfo folder, TocItem yamlNode)
_message.Verbose($"Items ordered in {folder.FullName}");
}

if (!string.IsNullOrWhiteSpace(yamlNode.Filename))
// if indicated, add a folder index - but not for the root folder.
if (_options.AutoIndex)
{
// if indicated, add a folder index - but not for the root folder.
if (_options.AutoIndex)
string indexFile = AddIndex(folder, yamlNode, GetOverrides(folder.Parent));
if (!string.IsNullOrEmpty(indexFile))
{
string indexFile = AddIndex(folder, yamlNode, GetOverrides(folder.Parent));
if (!string.IsNullOrEmpty(indexFile))
{
yamlNode.Href = GetRelativePath(indexFile, _options.DocFolder);
}
yamlNode.Href = GetRelativePath(indexFile, _options.DocFolder);
}
else
}
else
{
if (!string.IsNullOrWhiteSpace(yamlNode.Filename))
{
if (yamlNode.Items != null && yamlNode.Items.Any())
{
Expand Down Expand Up @@ -538,7 +538,9 @@ private static bool WriteIndex(string outputFile, TocItem yamlNode)
// read lines if existing file.
List<string> lines = new List<string>();

lines.Add($"# {yamlNode.Title}");
// We are taking the node name as title, if it's the root one, then the name of the parent folder
var title = string.IsNullOrWhiteSpace(yamlNode.Title) ? ToTitleCase(Directory.GetParent(outputFile).Name) : yamlNode.Title;
lines.Add($"# {title}");
lines.Add(string.Empty);
foreach (TocItem item in yamlNode.Items)
{
Expand Down Expand Up @@ -575,11 +577,12 @@ private static void Serialize(IndentedTextWriter writer, TocItem tocItem, bool i
if (!string.IsNullOrEmpty(tocItem.Title))
{
writer.WriteLine($"- name: {tocItem.Title}");
}

if (!string.IsNullOrEmpty(tocItem.Href))
{
writer.WriteLine($" href: {tocItem.Href}");
// href can't be singleton, you always have to have a name before
if (!string.IsNullOrEmpty(tocItem.Href))
{
writer.WriteLine($" href: {tocItem.Href}");
}
}

if (tocItem.Items != null)
Expand Down

0 comments on commit 12becfd

Please sign in to comment.