Skip to content

Commit a75f0e8

Browse files
committed
Merge branch 'main' of github.com:elastic/docs-builder into add-migration-guide
2 parents 01bf01e + 42cc222 commit a75f0e8

File tree

6 files changed

+28
-11
lines changed

6 files changed

+28
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Through the `serve` command you can continuously and partially compile your docu
6363

6464
```bash
6565
docker run -v "./.git:/app/.git" -v "./docs:/app/docs" -v "./.artifacts:/app/.artifacts" \
66-
--expose 8080 ghcr.io/elastic/docs-builder:edge serve
66+
-p 8080:8080 ghcr.io/elastic/docs-builder:edge serve
6767
```
6868

6969
Each page is compiled on demand as you browse http://localhost:8080 and is never cached so changes to files and
@@ -148,4 +148,4 @@ The resulting binary `./.artifacts/publish/docs-builder` will run on machines wi
148148
To test performance it's best to build the binary and run outside of docker:
149149

150150
For refence here's the `markitpy-doc` docset (50k markdown files) currently takes `14s` vs `several minutes` compared to
151-
existing surveyed tools
151+
existing surveyed tools

src/Elastic.Markdown/BuildContext.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
4242
ReadFileSystem = readFileSystem;
4343
WriteFileSystem = writeFileSystem;
4444

45-
var docsFolder = FindDocsFolderFromRoot();
46-
47-
SourcePath = !string.IsNullOrWhiteSpace(source) ? ReadFileSystem.DirectoryInfo.New(source) : docsFolder;
45+
var rootFolder = !string.IsNullOrWhiteSpace(source)
46+
? ReadFileSystem.DirectoryInfo.New(source)
47+
: ReadFileSystem.DirectoryInfo.New(Path.Combine(Paths.Root.FullName, "docs"));
48+
SourcePath = FindDocsFolderFromRoot(rootFolder);
4849

4950
OutputPath = !string.IsNullOrWhiteSpace(output)
5051
? WriteFileSystem.DirectoryInfo.New(output)
@@ -59,12 +60,14 @@ public BuildContext(IFileSystem readFileSystem, IFileSystem writeFileSystem, str
5960
Git = GitConfiguration.Create(ReadFileSystem);
6061
}
6162

62-
private IDirectoryInfo FindDocsFolderFromRoot()
63+
private IDirectoryInfo FindDocsFolderFromRoot(IDirectoryInfo rootPath)
6364
{
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;
65+
if (rootPath.Exists &&
66+
ReadFileSystem.File.Exists(Path.Combine(rootPath.FullName, "docset.yml")))
67+
return rootPath;
68+
69+
var docsFolder = rootPath.EnumerateFiles("docset.yml", SearchOption.AllDirectories).FirstOrDefault();
70+
return docsFolder?.Directory ?? throw new Exception($"Can not locate docset.yml file in '{rootPath}'");
6871
}
6972

7073
}

src/Elastic.Markdown/IO/ConfigurationFile.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
4949
yaml.Load(textReader);
5050

5151
if (yaml.Documents.Count == 0)
52+
{
5253
context.EmitWarning(sourceFile, "empty configuration");
54+
return;
55+
}
5356

5457
// Examine the stream
5558
var mapping = (YamlMappingNode)yaml.Documents[0].RootNode;

src/Elastic.Markdown/Myst/Directives/AdmonitionBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public string Title
3434
public override void FinalizeAndValidate(ParserContext context)
3535
{
3636
CrossReferenceName = Properties.GetValueOrDefault("name");
37-
DropdownOpen = PropBool("open");
37+
DropdownOpen = TryPropBool("open");
3838
if (DropdownOpen.HasValue)
3939
Classes = "dropdown";
4040
}

src/Elastic.Markdown/Myst/Directives/DirectiveBlock.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ protected bool PropBool(params string[] keys)
9393
return bool.TryParse(value, out var result) && result;
9494
}
9595

96+
protected bool? TryPropBool(params string[] keys)
97+
{
98+
var value = Prop(keys);
99+
if (string.IsNullOrEmpty(value))
100+
return keys.Any(k => Properties.ContainsKey(k)) ? true : null;
101+
102+
return bool.TryParse(value, out var result) ? result : null;
103+
}
104+
105+
96106
protected string? Prop(params string[] keys)
97107
{
98108
foreach (var key in keys)

tests/Elastic.Markdown.Tests/OutputDirectoryTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public async Task CreatesDefaultOutputDirectory()
1818
var logger = new TestLoggerFactory(output);
1919
var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
2020
{
21+
{ "docs/source/docset.yml", new MockFileData("") },
2122
{ "docs/source/index.md", new MockFileData("test") }
2223
}, new MockFileSystemOptions
2324
{

0 commit comments

Comments
 (0)