Browse Source

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.
pull/23868/head
Ahmet Çelik 1 year ago
parent
commit
31aa2c17bb
  1. 12
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

12
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<DocumentToHtmlConverterContext>(Document.Format ?? Project.Format);

Loading…
Cancel
Save