|
3 | 3 | // See the LICENSE file in the project root for more information |
4 | 4 |
|
5 | 5 | using System.Collections.Frozen; |
| 6 | +using System.Text.Json; |
6 | 7 | using Documentation.Assembler.Exporters; |
7 | 8 | using Documentation.Assembler.Navigation; |
8 | 9 | using Elastic.Documentation.Legacy; |
9 | 10 | using Elastic.Documentation.Links; |
| 11 | +using Elastic.Documentation.Serialization; |
10 | 12 | using Elastic.Markdown; |
11 | 13 | using Elastic.Markdown.Exporters; |
12 | 14 | using Elastic.Markdown.Links.CrossLinks; |
@@ -85,6 +87,8 @@ public async Task BuildAllAsync(FrozenDictionary<string, AssemblerDocumentationS |
85 | 87 | } |
86 | 88 | } |
87 | 89 |
|
| 90 | + await OutputRedirectsAsync(redirects, ctx); |
| 91 | + |
88 | 92 | tasks = markdownExporters.Select(async e => await e.StopAsync(ctx)); |
89 | 93 | await Task.WhenAll(tasks); |
90 | 94 | } |
@@ -143,4 +147,16 @@ private void SetFeatureFlags(AssemblerDocumentationSet set) |
143 | 147 | set.DocumentationSet.Configuration.Features.Set(configurationFeatureFlag.Key, configurationFeatureFlag.Value); |
144 | 148 | } |
145 | 149 | } |
| 150 | + |
| 151 | + private async Task OutputRedirectsAsync(Dictionary<string, string> redirects, Cancel ctx) |
| 152 | + { |
| 153 | + var uniqueRedirects = redirects |
| 154 | + .Where(x => !x.Key.TrimEnd('/').Equals(x.Value.TrimEnd('/'))) |
| 155 | + .ToFrozenDictionary(); |
| 156 | + var redirectsFile = context.WriteFileSystem.FileInfo.New(Path.Combine(context.OutputDirectory.FullName, "redirects.json")); |
| 157 | + _logger.LogInformation("Writing {Count} resolved redirects to {Path}", uniqueRedirects.Count, redirectsFile.FullName); |
| 158 | + |
| 159 | + var redirectsJson = JsonSerializer.Serialize(uniqueRedirects, SourceGenerationContext.Default.FrozenDictionaryStringString); |
| 160 | + await context.WriteFileSystem.File.WriteAllTextAsync(redirectsFile.FullName, redirectsJson, ctx); |
| 161 | + } |
146 | 162 | } |
0 commit comments