Skip to content

Commit 1440a52

Browse files
authored
Use new versions.yml config to render applies_to tags (#1465)
* Add new versions config and use in `applies_to` tags * Don't hide tooltip on click
1 parent e19ef30 commit 1440a52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1139
-442
lines changed

docs/syntax/applies.md

Lines changed: 135 additions & 34 deletions
Large diffs are not rendered by default.

docs/syntax/stepper.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ npm install
2020
::::
2121

2222
::::{step} Build
23+
### Build
2324
Then build the project.
2425
```shell
2526
npm run build

docs/testing/req.md

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,5 @@
1-
---
2-
applies_to:
3-
stack: ga 9.1
4-
---
5-
61
# Requirements
72

8-
Current version: **9.0.0**
9-
10-
| `applies_to` | result |
11-
|--------------------------------------------|--------------------------------------|
12-
| `` {applies_to}`stack: preview` `` | {applies_to}`stack: preview` |
13-
| `` {applies_to}`stack: preview 8.18` `` | {applies_to}`stack: preview 8.18` |
14-
| `` {applies_to}`stack: preview 9.0` `` | {applies_to}`stack: preview 9.0` |
15-
| `` {applies_to}`stack: preview 9.1` `` | {applies_to}`stack: preview 9.1` |
16-
| `` {applies_to}`stack: ga` `` | {applies_to}`stack: ga` |
17-
| `` {applies_to}`stack: ga 8.18` `` | {applies_to}`stack: ga 8.18` |
18-
| `` {applies_to}`stack: ga 9.0` `` | {applies_to}`stack: ga 9.0` |
19-
| `` {applies_to}`stack: ga 9.1` `` | {applies_to}`stack: ga 9.1` |
20-
| `` {applies_to}`stack: beta` `` | {applies_to}`stack: beta` |
21-
| `` {applies_to}`stack: beta 8.18` `` | {applies_to}`stack: beta 8.18` |
22-
| `` {applies_to}`stack: beta 9.0` `` | {applies_to}`stack: beta 9.0` |
23-
| `` {applies_to}`stack: beta 9.1` `` | {applies_to}`stack: beta 9.1` |
24-
| `` {applies_to}`stack: deprecated` `` | {applies_to}`stack: deprecated` |
25-
| `` {applies_to}`stack: deprecated 8.18` `` | {applies_to}`stack: deprecated 8.18` |
26-
| `` {applies_to}`stack: deprecated 9.0` `` | {applies_to}`stack: deprecated 9.0` |
27-
| `` {applies_to}`stack: deprecated 9.1` `` | {applies_to}`stack: deprecated 9.1` |
28-
| `` {applies_to}`stack: removed` `` | {applies_to}`stack: removed` |
29-
| `` {applies_to}`stack: removed 8.18` `` | {applies_to}`stack: removed 8.18` |
30-
| `` {applies_to}`stack: removed 9.0` `` | {applies_to}`stack: removed 9.0` |
31-
| `` {applies_to}`stack: removed 9.1` `` | {applies_to}`stack: removed 9.1` |
32-
| `` {applies_to}`stack: ` `` | {applies_to}`stack: ` |
33-
34-
{applies_to}`stack: deprecated 9.1, removed 9.4`
35-
36-
373
To follow this tutorial you will need to install the following components:
384

395
- An installation of Elasticsearch, based on our hosted [Elastic Cloud](https://www.elastic.co/cloud) service (which includes a free trial period), or a self-hosted service that you run on your own computer. See the Install Elasticsearch section above for installation instructions.
@@ -44,3 +10,6 @@ The tutorial assumes that you have no previous knowledge of Elasticsearch or gen
4410
- Python development
4511
- The [Flask](https://flask.palletsprojects.com/) web framework for Python.
4612
- The command prompt or terminal application in your operating system.
13+
14+
15+
{applies_to}`ece: removed`

src/Elastic.Documentation.Configuration/BuildContext.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
using System.Reflection;
77
using Elastic.Documentation.Configuration.Assembler;
88
using Elastic.Documentation.Configuration.Builder;
9+
using Elastic.Documentation.Configuration.Versions;
910
using Elastic.Documentation.Diagnostics;
1011

1112
namespace Elastic.Documentation.Configuration;
1213

1314
public record BuildContext : IDocumentationContext
1415
{
1516
public static string Version { get; } = Assembly.GetExecutingAssembly().GetCustomAttributes<AssemblyInformationalVersionAttribute>()
16-
.FirstOrDefault()?.InformationalVersion ?? "0.0.0";
17+
.FirstOrDefault()?.InformationalVersion ?? "0.0.0";
18+
1719
public IFileSystem ReadFileSystem { get; }
1820
public IFileSystem WriteFileSystem { get; }
1921

@@ -23,6 +25,8 @@ public record BuildContext : IDocumentationContext
2325

2426
public ConfigurationFile Configuration { get; }
2527

28+
public VersionsConfiguration VersionsConfig { get; init; }
29+
2630
public IFileInfo ConfigurationPath { get; }
2731

2832
public GitCheckoutInformation Git { get; }
@@ -60,13 +64,16 @@ public string? UrlPathPrefix
6064
init => _urlPathPrefix = value;
6165
}
6266

63-
public BuildContext(IDiagnosticsCollector collector, IFileSystem fileSystem)
64-
: this(collector, fileSystem, fileSystem, null, null) { }
67+
public BuildContext(IDiagnosticsCollector collector, IFileSystem fileSystem, VersionsConfiguration versionsConfig)
68+
: this(collector, fileSystem, fileSystem, versionsConfig, null, null)
69+
{
70+
}
6571

6672
public BuildContext(
6773
IDiagnosticsCollector collector,
6874
IFileSystem readFileSystem,
6975
IFileSystem writeFileSystem,
76+
VersionsConfiguration versionsConfig,
7077
string? source = null,
7178
string? output = null,
7279
GitCheckoutInformation? gitCheckoutInformation = null
@@ -75,6 +82,7 @@ public BuildContext(
7582
Collector = collector;
7683
ReadFileSystem = readFileSystem;
7784
WriteFileSystem = writeFileSystem;
85+
VersionsConfig = versionsConfig;
7886

7987
var rootFolder = !string.IsNullOrWhiteSpace(source)
8088
? ReadFileSystem.DirectoryInfo.New(source)
@@ -98,5 +106,4 @@ public BuildContext(
98106
Enabled = false
99107
};
100108
}
101-
102109
}

src/Elastic.Documentation.Configuration/Elastic.Documentation.Configuration.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
<PackageReference Include="Vecc.YamlDotNet.Analyzers.StaticGenerator"/>
1717
<PackageReference Include="YamlDotNet"/>
1818
</ItemGroup>
19+
20+
<ItemGroup>
21+
<EmbeddedResource Include="versions.yml" />
22+
</ItemGroup>
1923
</Project>

src/Elastic.Documentation.Configuration/Serialization/YamlStaticContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information
44

55
using Elastic.Documentation.Configuration.Assembler;
6+
using Elastic.Documentation.Configuration.Versions;
67
using YamlDotNet.Serialization;
78

89
namespace Elastic.Documentation.Configuration.Serialization;
@@ -15,4 +16,6 @@ namespace Elastic.Documentation.Configuration.Serialization;
1516
[YamlSerializable(typeof(GoogleTagManager))]
1617
[YamlSerializable(typeof(ContentSource))]
1718
[YamlSerializable(typeof(VersionEntry))]
19+
[YamlSerializable(typeof(VersionsConfigDto))]
20+
[YamlSerializable(typeof(VersioningSystemDto))]
1821
public partial class YamlStaticContext;
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System.ComponentModel.DataAnnotations;
6+
using NetEscapades.EnumGenerators;
7+
using YamlDotNet.Serialization;
8+
9+
namespace Elastic.Documentation.Configuration.Versions;
10+
11+
[YamlSerializable]
12+
public record VersionsConfiguration
13+
{
14+
public required IReadOnlyDictionary<VersioningSystemId, VersioningSystem> VersioningSystems { get; init; }
15+
public VersioningSystem GetVersioningSystem(VersioningSystemId versioningSystem)
16+
{
17+
if (!VersioningSystems.TryGetValue(versioningSystem, out var version))
18+
throw new ArgumentException($"Unknown versioning system: {versioningSystem}");
19+
return version;
20+
}
21+
}
22+
23+
[EnumExtensions]
24+
public enum VersioningSystemId
25+
{
26+
[Display(Name = "stack")]
27+
Stack,
28+
[Display(Name = "all")]
29+
All,
30+
[Display(Name = "ece")]
31+
Ece,
32+
[Display(Name = "ech")]
33+
Ech,
34+
[Display(Name = "eck")]
35+
Eck,
36+
[Display(Name = "ess")]
37+
Ess,
38+
[Display(Name = "self")]
39+
Self,
40+
[Display(Name = "ecctl")]
41+
Ecctl,
42+
[Display(Name = "curator")]
43+
Curator,
44+
[Display(Name = "serverless")]
45+
Serverless,
46+
[Display(Name = "elasticsearch")]
47+
Elasticsearch,
48+
[Display(Name = "observability")]
49+
Observability,
50+
[Display(Name = "security")]
51+
Security,
52+
[Display(Name = "apm_agent_android")]
53+
ApmAgentAndroid,
54+
[Display(Name = "apm_agent_ios")]
55+
ApmAgentIos,
56+
[Display(Name = "apm_agent_dotnet")]
57+
ApmAgentDotnet,
58+
[Display(Name = "apm_agent_go")]
59+
ApmAgentGo,
60+
[Display(Name = "apm_agent_java")]
61+
ApmAgentJava,
62+
[Display(Name = "apm_agent_node")]
63+
ApmAgentNode,
64+
[Display(Name = "apm_agent_php")]
65+
ApmAgentPhp,
66+
[Display(Name = "apm_agent_python")]
67+
ApmAgentPython,
68+
[Display(Name = "apm_agent_ruby")]
69+
ApmAgentRuby,
70+
[Display(Name = "apm_agent_rum")]
71+
ApmAgentRum,
72+
[Display(Name = "edot_ios")]
73+
EdotIos,
74+
[Display(Name = "edot_android")]
75+
EdotAndroid,
76+
[Display(Name = "edot_dotnet")]
77+
EdotDotnet,
78+
[Display(Name = "edot_java")]
79+
EdotJava,
80+
[Display(Name = "edot_node")]
81+
EdotNode,
82+
[Display(Name = "edot_php")]
83+
EdotPhp,
84+
[Display(Name = "edot_python")]
85+
EdotPython
86+
}
87+
88+
[YamlSerializable]
89+
public record VersioningSystem
90+
{
91+
public required VersioningSystemId Id { get; init; }
92+
93+
[YamlMember(Alias = "base")]
94+
public required SemVersion Base { get; init; }
95+
96+
[YamlMember(Alias = "current")]
97+
public required SemVersion Current { get; init; }
98+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using Elastic.Documentation.Configuration.Serialization;
6+
using Microsoft.Extensions.DependencyInjection;
7+
using Microsoft.Extensions.Options;
8+
using YamlDotNet.Serialization;
9+
using YamlDotNet.Serialization.NamingConventions;
10+
11+
namespace Elastic.Documentation.Configuration.Versions;
12+
13+
public static class VersionsConfigurationExtensions
14+
{
15+
private static readonly string ResourceName = "Elastic.Documentation.Configuration.versions.yml";
16+
17+
public static IServiceCollection AddVersions(this IServiceCollection services)
18+
{
19+
var assembly = typeof(VersionsConfigurationExtensions).Assembly;
20+
using var stream = assembly.GetManifestResourceStream(ResourceName) ?? throw new FileNotFoundException(ResourceName);
21+
using var reader = new StreamReader(stream);
22+
23+
var deserializer = new StaticDeserializerBuilder(new YamlStaticContext())
24+
.WithNamingConvention(UnderscoredNamingConvention.Instance)
25+
.Build();
26+
27+
var dto = deserializer.Deserialize<VersionsConfigDto>(reader);
28+
29+
var versions = dto.VersioningSystems.ToDictionary(
30+
kvp => ToVersioningSystemId(kvp.Key),
31+
kvp => new VersioningSystem
32+
{
33+
Id = ToVersioningSystemId(kvp.Key),
34+
Base = ToSemVersion(kvp.Value.Base),
35+
Current = ToSemVersion(kvp.Value.Current)
36+
});
37+
var config = new VersionsConfiguration { VersioningSystems = versions };
38+
39+
_ = services.AddSingleton<IOptions<VersionsConfiguration>>(new OptionsWrapper<VersionsConfiguration>(config));
40+
41+
return services;
42+
}
43+
44+
private static VersioningSystemId ToVersioningSystemId(string id)
45+
{
46+
if (!VersioningSystemIdExtensions.TryParse(id, out var versioningSystemId, true, true))
47+
throw new InvalidOperationException($"Could not parse versioning system id {id}");
48+
return versioningSystemId;
49+
}
50+
51+
private static SemVersion ToSemVersion(string semVer)
52+
{
53+
var fullVersion = semVer.Split('.').Length switch
54+
{
55+
0 => semVer + "0.0.0",
56+
1 => semVer + ".0.0",
57+
2 => semVer + ".0",
58+
_ => semVer
59+
};
60+
if (!SemVersion.TryParse(fullVersion, out var version))
61+
throw new InvalidOperationException($"Could not parse version {semVer}");
62+
return version;
63+
}
64+
}
65+
66+
// Private DTOs for deserialization. These match the YAML structure directly.
67+
68+
internal sealed record VersionsConfigDto
69+
{
70+
public Dictionary<string, VersioningSystemDto> VersioningSystems { get; set; } = [];
71+
}
72+
73+
internal sealed record VersioningSystemDto
74+
{
75+
public string Base { get; set; } = string.Empty;
76+
public string Current { get; set; } = string.Empty;
77+
}

0 commit comments

Comments
 (0)