From 31aa2c17bba65d42c73274e63d8bb482a5be9273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20=C3=87elik?= Date: Fri, 3 Oct 2025 11:11:13 +0300 Subject: [PATCH] Refactor TOC generation logic in project index page Moved the TOC generation for documents to occur after navigation DTO initialization, ensuring TOC items are generated only when document content is available. This improves code clarity and maintains correct TOC population. --- .../Pages/Documents/Project/Index.cshtml.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs index 3254882f7c..319d5f1b63 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs @@ -542,12 +542,7 @@ namespace Volo.Docs.Pages.Documents.Project DocumentNameWithExtension = Document.Name; SetDocumentPageTitle(); - if (Document != null && !Document.Content.IsNullOrEmpty()) - { - TocItems = _tocGeneratorService.GenerateTocItems(Document.Content, TocLevelCount); - } - - await ConvertDocumentContentToHtmlAsync(); + await ConvertDocumentContentToHtmlAsync(); return true; } @@ -605,6 +600,11 @@ namespace Volo.Docs.Pages.Documents.Project else { DocumentNavigationsDto = new DocumentNavigationsDto(); + } + + if (Document != null && !Document.Content.IsNullOrEmpty()) + { + TocItems = _tocGeneratorService.GenerateTocItems(Document.Content, TocLevelCount); } var converter = _documentToHtmlConverterFactory.Create(Document.Format ?? Project.Format);