Skip to content

Commit bf864d9

Browse files
committed
Allow _docset.yml and _toc.yml as configuration filenames
1 parent 30e0d03 commit bf864d9

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

src/Elastic.Markdown/BuildContext.cs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,41 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
4949
var rootFolder = !string.IsNullOrWhiteSpace(source)
5050
? ReadFileSystem.DirectoryInfo.New(source)
5151
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName));
52-
SourcePath = FindDocsFolderFromRoot(rootFolder);
52+
53+
(SourcePath, ConfigurationPath) = FindDocsFolderFromRoot(rootFolder);
5354

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

58-
ConfigurationPath =
59-
ReadFileSystem.FileInfo.New(Path.Combine(SourcePath.FullName, "docset.yml"));
60-
6159
if (ConfigurationPath.FullName != SourcePath.FullName)
6260
SourcePath = ConfigurationPath.Directory!;
6361

6462
Git = GitCheckoutInformation.Create(ReadFileSystem);
6563
}
6664

67-
private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
65+
private (IDirectoryInfo, IFileInfo) FindDocsFolderFromRoot(IDirectoryInfo rootPath)
6866
{
67+
var configurationPath = ReadFileSystem.FileInfo.New(Path.Combine(rootPath.FullName, "docset.yml"));
6968
if (rootPath.Exists &&
7069
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
71-
return rootPath;
70+
return (rootPath, configurationPath);
71+
72+
configurationPath = ReadFileSystem.FileInfo.New(Path.Combine(rootPath.FullName, "_docset.yml"));
73+
if (rootPath.Exists &&
74+
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "_docset.yml")))
75+
return (rootPath, configurationPath);
76+
77+
configurationPath = rootPath
78+
.EnumerateFiles("docset.yml", SearchOption.AllDirectories)
79+
.OrderByDescending(f => f.Name switch { "docset.yml" => 2, "_docset.yml" => 1, _ => 0 })
80+
.FirstOrDefault()
81+
?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
82+
83+
var docsFolder = configurationPath.Directory
84+
?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
7285

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

7789
}

src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,17 @@ private Dictionary<string, string> ReadDictionary(KeyValuePair<YamlNode, YamlNod
257257
var rootPath = _context.ReadFileSystem.DirectoryInfo.New(Path.Combine(_rootPath.FullName, tocPath));
258258
var path = Path.Combine(rootPath.FullName, "toc.yml");
259259
var source = _context.ReadFileSystem.FileInfo.New(path);
260+
261+
var errorMessage = $"Nested toc: '{source.Directory}' directory has no toc.yml or _toc.yml file";
262+
263+
if (!source.Exists)
264+
{
265+
path = Path.Combine(rootPath.FullName, "_toc.yml");
266+
source = _context.ReadFileSystem.FileInfo.New(path);
267+
}
268+
260269
if (!source.Exists)
261-
EmitError($"Nested toc: '{source.FullName}' does not exist", entry.Key);
270+
EmitError(errorMessage, entry.Key);
262271
else
263272
found = true;
264273

src/Elastic.Markdown/Myst/CodeBlocks/EnhancedCodeBlockParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ public override bool Close(BlockProcessor processor, Block block)
8888
var line = lines.Lines[index];
8989
var span = line.Slice.AsSpan();
9090

91+
var startIndex = Math.Max(span.IndexOf("//"), span.IndexOf('#'));
92+
if (startIndex <= 0)
93+
continue;
94+
9195
if (span.ReplaceSubstitutions(context.FrontMatter?.Properties, out var replacement))
9296
{
9397
var s = new StringSlice(replacement);

0 commit comments

Comments
 (0)