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
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<PackageVersion Include="Slugify.Core" Version="4.0.1" />
<PackageVersion Include="SoftCircuits.IniFileParser" Version="2.7.0" />
<PackageVersion Include="System.IO.Abstractions" Version="21.0.29" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="9.0.4" />
<PackageVersion Include="Utf8StreamReader" Version="1.3.2" />
<PackageVersion Include="Vecc.YamlDotNet.Analyzers.StaticGenerator" Version="16.1.3" PrivateAssets="All" />
<PackageVersion Include="Westwind.AspNetCore.LiveReload" Version="0.5.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Markdown.IO.State;
using Elastic.Documentation.Serialization;
using YamlDotNet.Serialization;

namespace Documentation.Assembler.Configuration;
namespace Elastic.Documentation.Configuration.Assembler;

public record AssemblyConfiguration
{
Expand Down Expand Up @@ -78,53 +78,3 @@ private static TRepository RepositoryDefaults<TRepository>(TRepository r, string
[YamlMember(Alias = "named_git_references")]
public Dictionary<string, string> NamedGitReferences { get; set; } = [];
}

public record PublishEnvironment
{
[YamlIgnore]
public string Name { get; set; } = string.Empty;

[YamlMember(Alias = "uri")]
public string Uri { get; set; } = string.Empty;

[YamlMember(Alias = "path_prefix")]
public string? PathPrefix { get; set; } = string.Empty;

[YamlMember(Alias = "allow_indexing")]
public bool AllowIndexing { get; set; }

[YamlMember(Alias = "content_source")]
public ContentSource ContentSource { get; set; }

[YamlMember(Alias = "google_tag_manager")]
public GoogleTagManager GoogleTagManager { get; set; } = new();
}

public record GoogleTagManager
{
[YamlMember(Alias = "enabled")]
public bool Enabled { get; set; }

private string _id = string.Empty;

[YamlMember(Alias = "id")]
public string Id
{
get => _id;
set
{
if (Enabled && string.IsNullOrEmpty(value))
throw new ArgumentException("Id is required when Enabled is true.");
_id = value;
}
}

[YamlMember(Alias = "auth")]
public string? Auth { get; set; }

[YamlMember(Alias = "preview")]
public string? Preview { get; set; }

[YamlMember(Alias = "cookies_win")]
public string? CookiesWin { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text.Json.Serialization;
using NetEscapades.EnumGenerators;

namespace Elastic.Markdown.IO.State;
namespace Elastic.Documentation.Configuration.Assembler;

[EnumExtensions]
public enum ContentSource
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using YamlDotNet.Serialization;

namespace Elastic.Documentation.Configuration.Assembler;

public record GoogleTagManager
{
[YamlMember(Alias = "enabled")]
public bool Enabled { get; set; }

private string _id = string.Empty;

[YamlMember(Alias = "id")]
public string Id
{
get => _id;
set
{
if (Enabled && string.IsNullOrEmpty(value))
throw new ArgumentException("Id is required when Enabled is true.");
_id = value;
}
}

[YamlMember(Alias = "auth")]
public string? Auth { get; set; }

[YamlMember(Alias = "preview")]
public string? Preview { get; set; }

[YamlMember(Alias = "cookies_win")]
public string? CookiesWin { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Diagnostics.CodeAnalysis;
using System.Web;

namespace Elastic.Documentation.Configuration.Assembler;

public record GoogleTagManagerConfiguration
{
public bool Enabled { get; init; }
[MemberNotNullWhen(returnValue: true, nameof(Enabled))]
public string? Id { get; init; }
public string? Auth { get; init; }
public string? Preview { get; init; }
public string? CookiesWin { get; init; }

public string QueryString()
{
var queryString = HttpUtility.ParseQueryString(string.Empty);
if (Auth is not null)
queryString.Add("gtm_auth", Auth);

if (Preview is not null)
queryString.Add("gtm_preview", Preview);

if (CookiesWin is not null)
queryString.Add("gtm_cookies_win", CookiesWin);

return queryString.Count > 0 ? $"&{queryString}" : string.Empty;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using YamlDotNet.Serialization;

namespace Elastic.Documentation.Configuration.Assembler;

public record PublishEnvironment
{
[YamlIgnore]
public string Name { get; set; } = string.Empty;

[YamlMember(Alias = "uri")]
public string Uri { get; set; } = string.Empty;

[YamlMember(Alias = "path_prefix")]
public string? PathPrefix { get; set; } = string.Empty;

[YamlMember(Alias = "allow_indexing")]
public bool AllowIndexing { get; set; }

[YamlMember(Alias = "content_source")]
public ContentSource ContentSource { get; set; }

[YamlMember(Alias = "google_tag_manager")]
public GoogleTagManager GoogleTagManager { get; set; } = new();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using Elastic.Markdown.IO.State;
using YamlDotNet.Serialization;

namespace Documentation.Assembler.Configuration;
namespace Elastic.Documentation.Configuration.Assembler;

public record NarrativeRepository : Repository
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Markdown.IO.Configuration;
namespace Elastic.Documentation.Configuration.Builder;

public class EnabledExtensions(IReadOnlyCollection<string> extensions)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Markdown.IO.Configuration;
namespace Elastic.Documentation.Configuration.Builder;

public class FeatureFlags(Dictionary<string, bool> featureFlags)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Markdown.IO.Configuration;
using Elastic.Documentation.Navigation;

namespace Elastic.Documentation.Configuration.TableOfContents;

public interface ITocItem
{
Expand Down
18 changes: 18 additions & 0 deletions Elastic.Documentation/ContentSourceMoniker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Documentation;

public static class ContentSourceMoniker
{
public static Uri Create(string repo, string? path) => new(CreateString(repo, path));

public static string CreateString(string repo, string? path)
{
path = path?.Replace("\\", "/").Trim('/');
if (string.IsNullOrWhiteSpace(path) || path == ".")
return $"{repo}://";
return $"{repo}://{path}/";
}
}
15 changes: 15 additions & 0 deletions Elastic.Documentation/Diagnostics/Diagnostic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Documentation.Diagnostics;

public readonly record struct Diagnostic
{
public Severity Severity { get; init; }
public int? Line { get; init; }
public int? Column { get; init; }
public int? Length { get; init; }
public string File { get; init; }
public string Message { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,7 @@
using System.Threading.Channels;
using Microsoft.Extensions.Hosting;

namespace Elastic.Markdown.Diagnostics;

public enum Severity
{
Error,
Warning,
Hint
}

public readonly record struct Diagnostic
{
public Severity Severity { get; init; }
public int? Line { get; init; }
public int? Column { get; init; }
public int? Length { get; init; }
public string File { get; init; }
public string Message { get; init; }
}
namespace Elastic.Documentation.Diagnostics;

public sealed class DiagnosticsChannel : IDisposable
{
Expand Down Expand Up @@ -69,8 +52,7 @@ public interface IDiagnosticsOutput
void Write(Diagnostic diagnostic);
}

public class DiagnosticsCollector(IReadOnlyCollection<IDiagnosticsOutput> outputs)
: IHostedService, IAsyncDisposable
public class DiagnosticsCollector(IReadOnlyCollection<IDiagnosticsOutput> outputs) : IHostedService, IAsyncDisposable
{
public DiagnosticsChannel Channel { get; } = new();

Expand Down
12 changes: 12 additions & 0 deletions Elastic.Documentation/Diagnostics/Severity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

namespace Elastic.Documentation.Diagnostics;

public enum Severity
{
Error = 0,
Warning = 1,
Hint = 2
}
19 changes: 19 additions & 0 deletions Elastic.Documentation/Elastic.Documentation.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Elastic.Documentation</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Logging"/>
<PackageReference Include="NetEscapades.EnumGenerators"/>
<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator"/>
<PackageReference Include="YamlDotNet"/>
<PackageReference Include="SoftCircuits.IniFileParser" />
<PackageReference Include="System.IO.Abstractions" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.Logging;
using SoftCircuits.IniFileParser;

namespace Elastic.Markdown.IO.Discovery;
namespace Elastic.Documentation;

public record GitCheckoutInformation
{
Expand Down Expand Up @@ -60,7 +60,7 @@ public static GitCheckoutInformation Create(IDirectoryInfo? source, IFileSystem
var gitRef = head;
var branch = head.Replace("refs/heads/", string.Empty);
//not detached HEAD
if (head.StartsWith("ref:"))
if (head.StartsWith("ref:", StringComparison.OrdinalIgnoreCase))
{
head = head.Replace("ref: ", string.Empty);
gitRef = Read(source, Path.Combine(".git", head)) ?? fakeRef;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information

using System.Runtime.InteropServices;
using System.Text.Json;
using System.Text.Json.Serialization;
using Elastic.Markdown.IO.Discovery;
using Elastic.Documentation.Serialization;

namespace Elastic.Markdown.IO.State;
namespace Elastic.Documentation;

public record LinkMetadata
{
Expand Down Expand Up @@ -70,28 +69,4 @@ public static LinkReference Deserialize(string json) =>

public static string Serialize(LinkReference reference) =>
JsonSerializer.Serialize(reference, SourceGenerationContext.Default.LinkReference);

public static LinkReference Create(DocumentationSet set)
{
var redirects = set.Configuration.Redirects;
var crossLinks = set.Build.Collector.CrossLinks.ToHashSet().ToArray();
var links = set.MarkdownFiles.Values
.Select(m => (m.LinkReferenceRelativePath, File: m))
.ToDictionary(k => RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? k.LinkReferenceRelativePath.Replace('\\', '/')
: k.LinkReferenceRelativePath, v =>
{
var anchors = v.File.Anchors.Count == 0 ? null : v.File.Anchors.ToArray();
return new LinkMetadata { Anchors = anchors, Hidden = v.File.Hidden };
});

return new LinkReference
{
Redirects = redirects,
UrlPathPrefix = set.Build.UrlPathPrefix,
Origin = set.Build.Git,
Links = links,
CrossLinks = crossLinks
};
}
}
Loading
Loading