Skip to content

Commit 00b2f74

Browse files
committed
improve automatically locating the documentation set in a repository
1 parent 5a22795 commit 00b2f74

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Elastic.Markdown/BuildContext.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,29 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
4242
ReadFileSystem = readFileSystem;
4343
WriteFileSystem = writeFileSystem;
4444

45-
SourcePath = !string.IsNullOrWhiteSpace(source)
46-
? ReadFileSystem.DirectoryInfo.New(source)
47-
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs/source"));
45+
var docsFolder = FindDocsFolderFromRoot();
46+
47+
SourcePath = !string.IsNullOrWhiteSpace(source) ? ReadFileSystem.DirectoryInfo.New(source) : docsFolder;
48+
4849
OutputPath = !string.IsNullOrWhiteSpace(output)
4950
? WriteFileSystem.DirectoryInfo.New(output)
5051
: WriteFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, ".artifacts/docs/html"));
5152

5253
ConfigurationPath =
53-
SourcePath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault()
54-
?? ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));
54+
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));
5555

5656
if (ConfigurationPath.FullName != SourcePath.FullName)
5757
SourcePath = ConfigurationPath.Directory!;
5858

5959
Git = GitConfiguration.Create(ReadFileSystem);
60+
}
6061

61-
62+
private IDirectoryInfo FindDocsFolderFromRoot()
63+
{
64+
var defaultDocsFolder = ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
65+
var root = ReadFileSystem.DirectoryInfo.New(Paths.Root.FullName);
66+
var docsFolder = root.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
67+
return docsFolder?.Directory ?? defaultDocsFolder;
6268
}
6369

6470
}

0 commit comments

Comments
 (0)