Skip to content

Commit 12a57ff

Browse files
committed
Fix changelog render when title has spaces
1 parent f4b7250 commit 12a57ff

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/services/Elastic.Documentation.Services/ChangelogService.cs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,18 +1349,20 @@ Cancel ctx
13491349

13501350
// Use title from input or default to version
13511351
var title = input.Title ?? version;
1352+
// Convert title to slug format for folder names and anchors (lowercase, dashes instead of spaces)
1353+
var titleSlug = TitleToSlug(title);
13521354

13531355
// Render markdown files (use first repo found, or default)
13541356
var repoForRendering = allResolvedEntries.Count > 0 ? allResolvedEntries[0].repo : defaultRepo;
13551357

13561358
// Render index.md (features, enhancements, bug fixes, security)
1357-
await RenderIndexMarkdown(collector, outputDir, title, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
1359+
await RenderIndexMarkdown(collector, outputDir, title, titleSlug, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
13581360

13591361
// Render breaking-changes.md
1360-
await RenderBreakingChangesMarkdown(collector, outputDir, title, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
1362+
await RenderBreakingChangesMarkdown(collector, outputDir, title, titleSlug, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
13611363

13621364
// Render deprecations.md
1363-
await RenderDeprecationsMarkdown(collector, outputDir, title, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
1365+
await RenderDeprecationsMarkdown(collector, outputDir, title, titleSlug, repoForRendering, allResolvedEntries.Select(e => e.entry).ToList(), entriesByType, input.Subsections, input.HidePrivateLinks, ctx);
13641366

13651367
_logger.LogInformation("Rendered changelog markdown files to {OutputDir}", outputDir);
13661368

@@ -1393,6 +1395,7 @@ private async Task RenderIndexMarkdown(
13931395
IDiagnosticsCollector collector,
13941396
string outputDir,
13951397
string title,
1398+
string titleSlug,
13961399
string repo,
13971400
List<ChangelogData> entries,
13981401
Dictionary<string, List<ChangelogData>> entriesByType,
@@ -1422,15 +1425,15 @@ Cancel ctx
14221425
}
14231426
if (hasBreakingChanges)
14241427
{
1425-
otherLinks.Add($"[Breaking changes](/release-notes/breaking-changes.md#{repo}-{title}-breaking-changes)");
1428+
otherLinks.Add($"[Breaking changes](/release-notes/breaking-changes.md#{repo}-{titleSlug}-breaking-changes)");
14261429
}
14271430
if (hasDeprecations)
14281431
{
1429-
otherLinks.Add($"[Deprecations](/release-notes/deprecations.md#{repo}-{title}-deprecations)");
1432+
otherLinks.Add($"[Deprecations](/release-notes/deprecations.md#{repo}-{titleSlug}-deprecations)");
14301433
}
14311434

14321435
var sb = new StringBuilder();
1433-
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-release-notes-{title}]");
1436+
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-release-notes-{titleSlug}]");
14341437

14351438
if (otherLinks.Count > 0)
14361439
{
@@ -1443,15 +1446,15 @@ Cancel ctx
14431446
{
14441447
if (features.Count > 0 || enhancements.Count > 0)
14451448
{
1446-
sb.AppendLine(CultureInfo.InvariantCulture, $"### Features and enhancements [{repo}-{title}-features-enhancements]");
1449+
sb.AppendLine(CultureInfo.InvariantCulture, $"### Features and enhancements [{repo}-{titleSlug}-features-enhancements]");
14471450
var combined = features.Concat(enhancements).ToList();
14481451
RenderEntriesByArea(sb, combined, repo, subsections, hidePrivateLinks);
14491452
}
14501453

14511454
if (security.Count > 0 || bugFixes.Count > 0)
14521455
{
14531456
sb.AppendLine();
1454-
sb.AppendLine(CultureInfo.InvariantCulture, $"### Fixes [{repo}-{title}-fixes]");
1457+
sb.AppendLine(CultureInfo.InvariantCulture, $"### Fixes [{repo}-{titleSlug}-fixes]");
14551458
var combined = security.Concat(bugFixes).ToList();
14561459
RenderEntriesByArea(sb, combined, repo, subsections, hidePrivateLinks);
14571460
}
@@ -1461,7 +1464,7 @@ Cancel ctx
14611464
sb.AppendLine("_No new features, enhancements, or fixes._");
14621465
}
14631466

1464-
var indexPath = _fileSystem.Path.Combine(outputDir, title, "index.md");
1467+
var indexPath = _fileSystem.Path.Combine(outputDir, titleSlug, "index.md");
14651468
var indexDir = _fileSystem.Path.GetDirectoryName(indexPath);
14661469
if (!string.IsNullOrWhiteSpace(indexDir) && !_fileSystem.Directory.Exists(indexDir))
14671470
{
@@ -1477,6 +1480,7 @@ private async Task RenderBreakingChangesMarkdown(
14771480
IDiagnosticsCollector collector,
14781481
string outputDir,
14791482
string title,
1483+
string titleSlug,
14801484
string repo,
14811485
List<ChangelogData> entries,
14821486
Dictionary<string, List<ChangelogData>> entriesByType,
@@ -1488,7 +1492,7 @@ Cancel ctx
14881492
var breakingChanges = entriesByType.GetValueOrDefault("breaking-change", []);
14891493

14901494
var sb = new StringBuilder();
1491-
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-{title}-breaking-changes]");
1495+
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-{titleSlug}-breaking-changes]");
14921496

14931497
if (breakingChanges.Count > 0)
14941498
{
@@ -1572,7 +1576,7 @@ Cancel ctx
15721576
sb.AppendLine("_No breaking changes._");
15731577
}
15741578

1575-
var breakingPath = _fileSystem.Path.Combine(outputDir, title, "breaking-changes.md");
1579+
var breakingPath = _fileSystem.Path.Combine(outputDir, titleSlug, "breaking-changes.md");
15761580
var breakingDir = _fileSystem.Path.GetDirectoryName(breakingPath);
15771581
if (!string.IsNullOrWhiteSpace(breakingDir) && !_fileSystem.Directory.Exists(breakingDir))
15781582
{
@@ -1588,6 +1592,7 @@ private async Task RenderDeprecationsMarkdown(
15881592
IDiagnosticsCollector collector,
15891593
string outputDir,
15901594
string title,
1595+
string titleSlug,
15911596
string repo,
15921597
List<ChangelogData> entries,
15931598
Dictionary<string, List<ChangelogData>> entriesByType,
@@ -1599,7 +1604,7 @@ Cancel ctx
15991604
var deprecations = entriesByType.GetValueOrDefault("deprecation", []);
16001605

16011606
var sb = new StringBuilder();
1602-
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-{title}-deprecations]");
1607+
sb.AppendLine(CultureInfo.InvariantCulture, $"## {title} [{repo}-{titleSlug}-deprecations]");
16031608

16041609
if (deprecations.Count > 0)
16051610
{
@@ -1683,7 +1688,7 @@ Cancel ctx
16831688
sb.AppendLine("_No deprecations._");
16841689
}
16851690

1686-
var deprecationsPath = _fileSystem.Path.Combine(outputDir, title, "deprecations.md");
1691+
var deprecationsPath = _fileSystem.Path.Combine(outputDir, titleSlug, "deprecations.md");
16871692
var deprecationsDir = _fileSystem.Path.GetDirectoryName(deprecationsPath);
16881693
if (!string.IsNullOrWhiteSpace(deprecationsDir) && !_fileSystem.Directory.Exists(deprecationsDir))
16891694
{
@@ -1816,6 +1821,15 @@ private static string Beautify(string text)
18161821
return result;
18171822
}
18181823

1824+
private static string TitleToSlug(string title)
1825+
{
1826+
if (string.IsNullOrWhiteSpace(title))
1827+
return string.Empty;
1828+
1829+
// Convert to lowercase and replace spaces with dashes
1830+
return title.ToLowerInvariant().Replace(' ', '-');
1831+
}
1832+
18191833
private static string Indent(string text)
18201834
{
18211835
// Indent each line with two spaces

0 commit comments

Comments
 (0)