Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
28 changes: 20 additions & 8 deletions src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,41 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
var rootFolder = !string.IsNullOrWhiteSpace(source)
? ReadFileSystem.DirectoryInfo.New(source)
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName));
SourcePath = FindDocsFolderFromRoot(rootFolder);

(SourcePath, ConfigurationPath) = FindDocsFolderFromRoot(rootFolder);

OutputPath = !string.IsNullOrWhiteSpace(output)
? WriteFileSystem.DirectoryInfo.New(output)
: WriteFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, ".artifacts/docs/html"));

ConfigurationPath =
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));

if (ConfigurationPath.FullName != SourcePath.FullName)
SourcePath = ConfigurationPath.Directory!;

Git = GitCheckoutInformation.Create(ReadFileSystem);
}

private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
private (IDirectoryInfo, IFileInfo) FindDocsFolderFromRoot(IDirectoryInfo rootPath)
{
var configurationPath = ReadFileSystem.FileInfo.New(Path.Combine(rootPath.FullName, "docset.yml"));
if (rootPath.Exists &&
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
return rootPath;
return (rootPath, configurationPath);

configurationPath = ReadFileSystem.FileInfo.New(Path.Combine(rootPath.FullName, "_docset.yml"));
if (rootPath.Exists &&
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "_docset.yml")))
return (rootPath, configurationPath);

configurationPath = rootPath
.EnumerateFiles("docset.yml", SearchOption.AllDirectories)
.OrderByDescending(f => f.Name switch { "docset.yml" => 2, "_docset.yml" => 1, _ => 0 })
.FirstOrDefault()
?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");

var docsFolder = configurationPath.Directory
?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");

var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
return docsFolder?.Directory ?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
return (docsFolder, configurationPath);
}

}
11 changes: 10 additions & 1 deletion src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,17 @@ private Dictionary<string, string> ReadDictionary(KeyValuePair<YamlNode, YamlNod
var rootPath = _context.ReadFileSystem.DirectoryInfo.New(Path.Combine(_rootPath.FullName, tocPath));
var path = Path.Combine(rootPath.FullName, "toc.yml");
var source = _context.ReadFileSystem.FileInfo.New(path);

var errorMessage = $"Nested toc: '{source.Directory}' directory has no toc.yml or _toc.yml file";

if (!source.Exists)
{
path = Path.Combine(rootPath.FullName, "_toc.yml");
source = _context.ReadFileSystem.FileInfo.New(path);
}

if (!source.Exists)
EmitError($"Nested toc: '{source.FullName}' does not exist", entry.Key);
EmitError(errorMessage, entry.Key);
else
found = true;

Expand Down