Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/BuildContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public BuildContext(DiagnosticsCollector collector, IFileSystem readFileSystem,

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

if (ConfigurationPath.FullName != DocumentationSourceDirectory.FullName)
DocumentationSourceDirectory = ConfigurationPath.Directory!;
Expand Down
2 changes: 1 addition & 1 deletion src/Elastic.Markdown/DocumentationGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private async Task ExtractEmbeddedStaticResources(Cancel ctx)
if (resourceStream == null)
continue;

var path = a.Replace("Elastic.Markdown.", "").Replace("_static.", "_static/");
var path = a.Replace("Elastic.Markdown.", "").Replace("_static.", $"_static{Path.DirectorySeparatorChar}");

var outputFile = OutputFile(path);
await _documentationFileExporter.CopyEmbeddedResource(outputFile, resourceStream, ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public IReadOnlyCollection<ITocItem> CreateTableOfContentItems(
HashSet<string> files
)
{
var detectionRulesFolder = $"{Path.Combine(parentPath, detectionRules)}".TrimStart('/');
var detectionRulesFolder = Path.Combine(parentPath, detectionRules).TrimStart(Path.DirectorySeparatorChar);
var fs = Build.ReadFileSystem;
var sourceDirectory = Build.DocumentationSourceDirectory;
var path = fs.DirectoryInfo.New(fs.Path.GetFullPath(fs.Path.Combine(sourceDirectory.FullName, detectionRulesFolder)));
Expand Down
25 changes: 14 additions & 11 deletions src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information

using System.IO.Abstractions;
using System.Runtime.InteropServices;
using DotNet.Globbing;
using Elastic.Markdown.Diagnostics;
using Elastic.Markdown.Extensions;
Expand Down Expand Up @@ -114,7 +115,7 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon
throw;
}

Globs = [.. ImplicitFolders.Select(f => Glob.Parse($"{f}/*.md"))];
Globs = [.. ImplicitFolders.Select(f => Glob.Parse($"{f}{Path.DirectorySeparatorChar}*.md"))];
}

private IReadOnlyCollection<IDocsBuilderExtension> InstantiateExtensions()
Expand Down Expand Up @@ -189,13 +190,13 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
break;
case "folder":
folder = ReadFolder(reader, entry, parentPath, out folderFound);
parentPath += $"/{folder}";
parentPath += $"{Path.DirectorySeparatorChar}{folder}";
break;
case "detection_rules":
if (Extensions.IsDetectionRulesEnabled)
{
detectionRules = ReadDetectionRules(reader, entry, parentPath, out detectionRulesFound);
parentPath += $"/{folder}";
parentPath += $"{Path.DirectorySeparatorChar}{folder}";
}
break;
case "children":
Expand All @@ -209,7 +210,7 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
foreach (var f in toc.Files)
_ = Files.Add(f);

return [new FolderReference($"{parentPath}".TrimStart('/'), folderFound, inNav, toc.TableOfContents)];
return [new FolderReference($"{parentPath}".TrimStart(Path.DirectorySeparatorChar), folderFound, inNav, toc.TableOfContents)];
}

if (file is not null)
Expand All @@ -230,15 +231,15 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
children = extension.CreateTableOfContentItems(parentPath, detectionRules, Files);
}
}
return [new FileReference($"{parentPath}/{file}".TrimStart('/'), fileFound, hiddenFile, children ?? [])];
return [new FileReference($"{parentPath}{Path.DirectorySeparatorChar}{file}".TrimStart(Path.DirectorySeparatorChar), fileFound, hiddenFile, children ?? [])];
}

if (folder is not null)
{
if (children is null)
_ = ImplicitFolders.Add(parentPath.TrimStart('/'));
_ = ImplicitFolders.Add(parentPath.TrimStart(Path.DirectorySeparatorChar));

return [new FolderReference($"{parentPath}".TrimStart('/'), folderFound, inNav, children ?? [])];
return [new FolderReference($"{parentPath}".TrimStart(Path.DirectorySeparatorChar), folderFound, inNav, children ?? [])];
}

return null;
Expand All @@ -250,7 +251,7 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
var folder = reader.ReadString(entry);
if (folder is not null)
{
var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart('/'), folder);
var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart(Path.DirectorySeparatorChar), folder);
if (!_context.ReadFileSystem.DirectoryInfo.New(path).Exists)
reader.EmitError($"Directory '{path}' does not exist", entry.Key);
else
Expand All @@ -266,7 +267,7 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
var folder = reader.ReadString(entry);
if (folder is not null)
{
var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart('/'), folder);
var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart(Path.DirectorySeparatorChar), folder);
if (!_context.ReadFileSystem.DirectoryInfo.New(path).Exists)
reader.EmitError($"Directory '{path}' does not exist", entry.Key);
else
Expand All @@ -282,13 +283,15 @@ private List<ITocItem> ReadChildren(YamlStreamReader reader, KeyValuePair<YamlNo
var file = reader.ReadString(entry);
if (file is null)
return null;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
file = file.Replace('/', Path.DirectorySeparatorChar);

var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart('/'), file);
var path = Path.Combine(_rootPath.FullName, parentPath.TrimStart(Path.DirectorySeparatorChar), file);
if (!_context.ReadFileSystem.FileInfo.New(path).Exists)
reader.EmitError($"File '{path}' does not exist", entry.Key);
else
found = true;
_ = Files.Add((parentPath + "/" + file).TrimStart('/'));
_ = Files.Add((parentPath + Path.DirectorySeparatorChar + file).TrimStart(Path.DirectorySeparatorChar));

return file;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Elastic.Markdown/IO/DocumentationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Collections.Frozen;
using System.IO.Abstractions;
using System.Runtime.InteropServices;
using Elastic.Markdown.CrossLinks;
using Elastic.Markdown.Diagnostics;
using Elastic.Markdown.Extensions;
Expand Down Expand Up @@ -175,6 +176,9 @@ private void ValidateRedirectsExists()

void ValidateExists(string from, string to, IReadOnlyDictionary<string, string?>? valueAnchors)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
to = to.Replace('/', Path.DirectorySeparatorChar);

if (!FlatMappedFiles.TryGetValue(to, out var file))
{
Build.EmitError(Configuration.SourceFile, $"Redirect {from} points to {to} which does not exist");
Expand Down Expand Up @@ -262,7 +266,7 @@ private DocumentationFile CreateMarkDownFile(IFileInfo file, BuildContext contex
return new MarkdownFile(file, SourceDirectory, MarkdownParser, context, this);

// we ignore files in folders that start with an underscore
if (relativePath.IndexOf("/_", StringComparison.Ordinal) > 0 || relativePath.StartsWith('_'))
if (relativePath.IndexOf($"{Path.DirectorySeparatorChar}_", StringComparison.Ordinal) > 0 || relativePath.StartsWith('_'))
return new ExcludedFile(file, SourceDirectory);

context.EmitError(Configuration.SourceFile, $"Not linked in toc: {relativePath}");
Expand Down
8 changes: 6 additions & 2 deletions src/docs-builder/Http/DocumentationWebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.IO.Abstractions;
using System.Net;
using System.Runtime.InteropServices;
using Documentation.Builder.Diagnostics.LiveMode;
using Elastic.Documentation.Tooling;
using Elastic.Markdown;
Expand Down Expand Up @@ -149,10 +150,13 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
{
var generator = holder.Generator;

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
slug = slug.Replace('/', Path.DirectorySeparatorChar);

var s = Path.GetExtension(slug) == string.Empty ? Path.Combine(slug, "index.md") : slug;
if (!generator.DocumentationSet.FlatMappedFiles.TryGetValue(s, out var documentationFile))
{
s = Path.GetExtension(slug) == string.Empty ? slug + ".md" : s.Replace("/index.md", ".md");
s = Path.GetExtension(slug) == string.Empty ? slug + ".md" : s.Replace($"{Path.DirectorySeparatorChar}index.md", ".md");
if (!generator.DocumentationSet.FlatMappedFiles.TryGetValue(s, out documentationFile))
{
foreach (var extension in generator.Context.Configuration.EnabledExtensions)
Expand Down Expand Up @@ -230,7 +234,7 @@ public IDirectoryContents GetDirectoryContents(string subpath)

public IFileInfo GetFileInfo(string subpath)
{
var path = subpath.Replace("/_static", "");
var path = subpath.Replace($"{Path.DirectorySeparatorChar}_static", "");
var fileInfo = FirstYielding(path, static (a, p) => p.GetFileInfo(a));
if (fileInfo is null || !fileInfo.Exists)
fileInfo = _embeddedProvider.GetFileInfo(subpath);
Expand Down