diff --git a/src/Elastic.Markdown/BuildContext.cs b/src/Elastic.Markdown/BuildContext.cs index 40911dfdf..7b1086295 100644 --- a/src/Elastic.Markdown/BuildContext.cs +++ b/src/Elastic.Markdown/BuildContext.cs @@ -49,29 +49,42 @@ 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) { - if (rootPath.Exists && - ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml"))) - return rootPath; - - var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault(); - return docsFolder?.Directory ?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'"); + string[] files = ["docset.yml", "_docset.yml"]; + string[] knownFolders = [rootPath.FullName, Path.Combine(rootPath.FullName, "docs")]; + var mostLikelyTargets = + from file in files + from folder in knownFolders + select Path.Combine(folder, file); + + var knownConfigPath = mostLikelyTargets.FirstOrDefault(ReadFileSystem.File.Exists); + var configurationPath = knownConfigPath is null ? null : ReadFileSystem.FileInfo.New(knownConfigPath); + if (configurationPath is not null) + return (configurationPath.Directory!, configurationPath); + + configurationPath = rootPath + .EnumerateFiles("*docset.yml", SearchOption.AllDirectories) + .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}'"); + + return (docsFolder, configurationPath); } } diff --git a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs index 437ac461d..778117ca4 100644 --- a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs +++ b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs @@ -257,8 +257,17 @@ private Dictionary ReadDictionary(KeyValuePair () - fileSystem.AddFile(Path.Combine(root.FullName, "docset.yml"), MockFileData(yaml.ToString())); + let name = if Random().Next(0, 10) % 2 = 0 then "_docset.yml" else "docset.yml" + fileSystem.AddFile(Path.Combine(root.FullName, name), MockFileData(yaml.ToString())); static member Generator (files: TestFile seq) : Task =