From fde0e5a01dea3391ba2870c7e9dab2c26c844743 Mon Sep 17 00:00:00 2001 From: EngincanV Date: Wed, 31 Mar 2021 20:51:30 +0300 Subject: [PATCH] Refactoring --- .../Docs/Documents/IDocumentAppService.cs | 2 +- .../Volo/Docs/Documents/DocumentAppService.cs | 45 ++++++++++--------- .../Docs/Documents/DocsDocumentController.cs | 4 +- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs index 355c2319f8..653d823ff6 100644 --- a/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs +++ b/modules/docs/src/Volo.Docs.Application.Contracts/Volo/Docs/Documents/IDocumentAppService.cs @@ -20,6 +20,6 @@ namespace Volo.Docs.Documents Task FullSearchEnabledAsync(); - Task> GetLinksAsync(); + Task> GetUrlsAsync(string prefix); } } \ No newline at end of file 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 2c9521209c..73cc7e7a06 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 @@ -194,13 +194,18 @@ namespace Volo.Docs.Documents return await Task.FromResult(_docsElasticSearchOptions.Enable); } - public async Task> GetLinksAsync() + public async Task> GetUrlsAsync(string prefix) { - var documentLinks = new List(); + var documentUrls = new List(); var projects = await _projectRepository.GetListAsync(); foreach (var project in projects) { + if (project.ShortName == "ABP Commercial" || project.Name == "ABP Commercial") + { + continue; + } + var documents = await _documentRepository.GetListByProjectId(project.Id); foreach (var document in documents) @@ -214,53 +219,51 @@ namespace Volo.Docs.Documents navigationNode.Items?.ForEach(node => { - documentLinks.AddIfNotContains( - GetDocumentLinks(node, documentLinks, document.LanguageCode, - project.ShortName, document.Version, document.Format) + documentUrls.AddIfNotContains( + GetDocumentLinks(node, documentUrls, prefix, project.ShortName, document) ); }); } } - return documentLinks; + return documentUrls; } - private List GetDocumentLinks(NavigationNode node, List documentLinks, string languageName, - string shortName, string version, string format) + private List GetDocumentLinks(NavigationNode node, List documentUrls, string prefix, + string shortName, Document document) { if (!IsExternalLink(node.Path)) { - documentLinks.AddIfNotContains(NormalizePath(node.Path, languageName, shortName, version, format)); + documentUrls.AddIfNotContains( + NormalizePath(prefix, node.Path, shortName, document) + ); } node.Items?.ForEach(childNode => { - GetDocumentLinks(childNode, documentLinks, languageName, shortName, version, format); + GetDocumentLinks(childNode, documentUrls, prefix, shortName, document); }); - return documentLinks; + return documentUrls; } - private string NormalizePath(string path, string languageCode, string projectName, string version, - string projectFormat) + private string NormalizePath(string prefix, string path, string shortName, Document document) { - var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, projectFormat); - - //TODO: get prefix from DocsUiOptions? - var prefix = "/"; + var pathWithoutFileExtension = RemoveFileExtensionFromPath(path, document.Format); + var normalizedPath = prefix + document.LanguageCode + "/" + shortName + "/" + document.Version + "/" + pathWithoutFileExtension; - return prefix + languageCode + "/" + projectName + "/" + version + "/" + pathWithoutFileExtension; + return normalizedPath; } - private string RemoveFileExtensionFromPath(string path, string projectFormat) + private string RemoveFileExtensionFromPath(string path, string format) { if (path == null) { return null; } - return path.EndsWith("." + projectFormat) - ? path.Left(path.Length - projectFormat.Length - 1) + return path.EndsWith("." + format) + ? path.Left(path.Length - format.Length - 1) : path; } diff --git a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs index bec1be922e..354925f83e 100644 --- a/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs +++ b/modules/docs/src/Volo.Docs.HttpApi/Volo/Docs/Documents/DocsDocumentController.cs @@ -63,9 +63,9 @@ namespace Volo.Docs.Documents [HttpGet] [Route("links")] - public Task> GetLinksAsync() + public Task> GetUrlsAsync(string prefix) { - return DocumentAppService.GetLinksAsync(); + return DocumentAppService.GetUrlsAsync(prefix); } [HttpGet]