diff --git a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs index 4d451a1d4f..791abeec4f 100644 --- a/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application/Volo/Docs/Documents/DocumentAppService.cs @@ -144,7 +144,9 @@ namespace Volo.Docs.Documents input.Version = string.IsNullOrWhiteSpace(input.Version) ? project.LatestVersionBranchName : input.Version; input.Version = GetProjectVersionPrefixIfExist(project) + input.Version; - var cacheKey = CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode,input.Version); + var cacheKey = + CacheKeyGenerator.GenerateDocumentResourceCacheKey(project, input.Name, input.LanguageCode, + input.Version); async Task GetResourceAsync() { @@ -180,13 +182,15 @@ namespace Volo.Docs.Documents await _documentFullSearch.SearchAsync(input.Context, project.Id, input.LanguageCode, input.Version); return esDocs.Select(esDoc => new DocumentSearchOutput //TODO: auto map - { - Name = esDoc.Name, - FileName = esDoc.FileName, - Version = esDoc.Version, - LanguageCode = esDoc.LanguageCode, - Highlight = esDoc.Highlight - }).Where(x => x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName).ToList(); + { + Name = esDoc.Name, + FileName = esDoc.FileName, + Version = esDoc.Version, + LanguageCode = esDoc.LanguageCode, + Highlight = esDoc.Highlight + }).Where(x => + x.FileName != project.NavigationDocumentName && x.FileName != project.ParametersDocumentName) + .ToList(); } public async Task FullSearchEnabledAsync() @@ -205,34 +209,63 @@ namespace Volo.Docs.Documents foreach (var document in documents) { - var version = GetProjectVersionPrefixIfExist(project) + document.Version; - var navigationDocument = await GetDocumentWithDetailsDtoAsync( - project, - project.NavigationDocumentName, - document.LanguageCode, - version - ); - - if (!DocsJsonSerializerHelper.TryDeserialize(navigationDocument.Content, - out var navigationNode)) + try { - throw new UserFriendlyException( - $"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); + await AddDocumentToUrls(prefix, project, document, documentUrls); } - - navigationNode.Items?.ForEach(node => + catch (Exception ex) { - documentUrls.AddIfNotContains( - GetDocumentLinks(node, documentUrls, prefix, project.ShortName, document) - ); - }); + Logger.LogException(ex); + } } } return documentUrls; } - private List GetDocumentLinks(NavigationNode node, List documentUrls, string prefix, + private async Task AddDocumentToUrls(string prefix, Project project, Document document, + List documentUrls) + { + var navigationNodes = await GetNavigationNodesAsync(prefix, project, document); + AddDocumentUrls(prefix, navigationNodes, documentUrls, project, document); + } + + private void AddDocumentUrls(string prefix, + List navigationNodes, + List documentUrls, + Project project, + Document document) + { + navigationNodes?.ForEach(node => + { + documentUrls.AddIfNotContains( + GetDocumentLinks(node, documentUrls, prefix, project.ShortName, document) + ); + }); + } + + private async Task> GetNavigationNodesAsync(string prefix, Project project, + Document document) + { + var version = GetProjectVersionPrefixIfExist(project) + document.Version; + var navigationDocument = await GetDocumentWithDetailsDtoAsync( + project, + project.NavigationDocumentName, + document.LanguageCode, + version + ); + + if (!DocsJsonSerializerHelper.TryDeserialize(navigationDocument.Content, + out var navigationNode)) + { + throw new UserFriendlyException( + $"Cannot validate navigation file '{project.NavigationDocumentName}' for the project {project.Name}."); + } + + return navigationNode.Items; + } + + private List GetDocumentLinks(NavigationNode node, List documentUrls, string prefix, string shortName, Document document) { if (!IsExternalLink(node.Path)) @@ -253,7 +286,8 @@ namespace Volo.Docs.Documents private string NormalizePath(string prefix, string path, string shortName, Document document) { var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format); - var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" + pathWithoutFileExtension; + var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" + + pathWithoutFileExtension; return normalizedPath; } @@ -301,7 +335,8 @@ namespace Volo.Docs.Documents input.Version ); - if (!DocsJsonSerializerHelper.TryDeserialize(document.Content,out var documentParameters)) + if (!DocsJsonSerializerHelper.TryDeserialize(document.Content, + out var documentParameters)) { throw new UserFriendlyException( $"Cannot validate document parameters file '{project.ParametersDocumentName}' for the project {project.Name}."); @@ -363,7 +398,8 @@ namespace Volo.Docs.Documents var documentDto = ObjectMapper.Map(document); documentDto.Project = ObjectMapper.Map(project); - documentDto.Contributors = ObjectMapper.Map, List>(document.Contributors); + documentDto.Contributors = + ObjectMapper.Map, List>(document.Contributors); return documentDto; } @@ -374,7 +410,8 @@ namespace Volo.Docs.Documents Logger.LogInformation($"Not found in the cache. Requesting {documentName} from the source..."); var source = _documentStoreFactory.Create(project.DocumentStoreType); - var sourceDocument = await source.GetDocumentAsync(project, documentName, languageCode, version, oldDocument?.LastSignificantUpdateTime); + var sourceDocument = await source.GetDocumentAsync(project, documentName, languageCode, version, + oldDocument?.LastSignificantUpdateTime); await _documentRepository.DeleteAsync(project.Id, sourceDocument.Name, sourceDocument.LanguageCode, sourceDocument.Version);