Skip to content

Commit

Permalink
improve automatically locating the documentation set in a repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Mpdreamz committed Dec 9, 2024
1 parent 5a22795 commit 00b2f74
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,29 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
ReadFileSystem = readFileSystem;
WriteFileSystem = writeFileSystem;

SourcePath = !string.IsNullOrWhiteSpace(source)
? ReadFileSystem.DirectoryInfo.New(source)
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs/source"));
var docsFolder = FindDocsFolderFromRoot();

SourcePath = !string.IsNullOrWhiteSpace(source) ? ReadFileSystem.DirectoryInfo.New(source) : docsFolder;

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

ConfigurationPath =
SourcePath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault()
?? ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));

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

Git = GitConfiguration.Create(ReadFileSystem);
}


private IDirectoryInfo FindDocsFolderFromRoot()
{
var defaultDocsFolder = ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
var root = ReadFileSystem.DirectoryInfo.New(Paths.Root.FullName);
var docsFolder = root.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
return docsFolder?.Directory ?? defaultDocsFolder;
}

}

0 comments on commit 00b2f74

Please sign in to comment.