Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure live reload picks up changes to docset and newly created files again #90

Merged
merged 4 commits into from
Dec 3, 2024
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
5 changes: 5 additions & 0 deletions src/Elastic.Markdown/IO/MarkdownFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ private void ReadDocumentInstructions(MarkdownDocument document)
Title = YamlFrontMatter.Title;
NavigationTitle = YamlFrontMatter.NavigationTitle;
}
else
{
Title = RelativePath;
NavigationTitle = RelativePath;
}

var contents = document
.Where(block => block is HeadingBlock { Level: 2 })
Expand Down
8 changes: 5 additions & 3 deletions src/Elastic.Markdown/Myst/Directives/VersionBlock.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 Elastic.Markdown.Helpers;
using static System.StringSplitOptions;

namespace Elastic.Markdown.Myst.Directives;

Expand All @@ -17,7 +18,7 @@ public class VersionBlock(DirectiveBlockParser parser, string directive, Diction

public override void FinalizeAndValidate(ParserContext context)
{
var tokens = Arguments?.Split(" ", 2, StringSplitOptions.RemoveEmptyEntries) ?? [];
var tokens = Arguments?.Split(" ", 2, RemoveEmptyEntries) ?? [];
if (tokens.Length < 1)
{
EmitError(context, $"{directive} needs exactly 2 arguments: <version> <title>");
Expand All @@ -26,8 +27,9 @@ public override void FinalizeAndValidate(ParserContext context)

if (!SemVersion.TryParse(tokens[0], out var version))
{
EmitError(context, $"{tokens[0]} is not a valid version");
return;
var numbers = tokens[0].Split('.', RemoveEmptyEntries);
if (numbers.Length != 2 || !SemVersion.TryParse($"{numbers[0]}.{numbers[1]}.0", out version))
EmitError(context, $"'{tokens[0]}' is not a valid version");
}

Version = version;
Expand Down
2 changes: 2 additions & 0 deletions src/docs-builder/Http/ReloadGeneratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ private void OnChanged(object sender, FileSystemEventArgs e)

if (e.FullPath.EndsWith("docset.yml"))
Reload();
if (e.FullPath.EndsWith(".md"))
Reload();

Logger.LogInformation($"Changed: {e.FullPath}");
}
Expand Down
32 changes: 32 additions & 0 deletions tests/Elastic.Markdown.Tests/Directives/VersionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,35 @@ public class VersionDeprectatedTests(ITestOutputHelper output) : VersionTests(ou
[Fact]
public void SetsTitle() => Block!.Title.Should().Be("Deprecated (1.0.1-beta1): more information");
}

public abstract class VersionValidationTests(ITestOutputHelper output, string version) : DirectiveTest<VersionBlock>(output,
$$"""
```{versionchanged} {{version}} more information
Version brief summary
```
A regular paragraph.
"""
);

public class SimpleVersion(ITestOutputHelper output) : VersionValidationTests(output, "7.17")
{
[Fact]
public void SetsVersion() => Block!.Version.Should().Be(new SemVersion(7, 17, 0));

[Fact]
public void HasNoError() => Collector.Diagnostics.Should().BeEmpty();
}

public class MajorVersionOnly(ITestOutputHelper output) : VersionValidationTests(output, "8")
{
[Fact]
public void HasError() => Collector.Diagnostics.Should().HaveCount(1)
.And.Contain(d => d.Message.Contains("'8' is not a valid version"));
}

public class BranchVersion(ITestOutputHelper output) : VersionValidationTests(output, "8.x")
{
[Fact]
public void HasError() => Collector.Diagnostics.Should().HaveCount(1)
.And.Contain(d => d.Message.Contains("'8.x' is not a valid version"));
}
Loading