-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9362bdd
commit a0de880
Showing
4 changed files
with
132 additions
and
63 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentNavigationController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Asp.Versioning; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Volo.Abp; | ||
using Volo.Abp.AspNetCore.Mvc; | ||
using Volo.Docs.Areas.Models.DocumentNavigation; | ||
using Volo.Docs.Documents; | ||
using Volo.Docs.Utils; | ||
|
||
namespace Volo.Docs.Areas.Documents; | ||
|
||
[RemoteService(Name = DocsRemoteServiceConsts.RemoteServiceName)] | ||
[Area(DocsRemoteServiceConsts.ModuleName)] | ||
[ControllerName("DocumentNavigation")] | ||
[Route("/docs/document-navigation")] | ||
public class DocumentNavigationController : AbpController | ||
{ | ||
private readonly IDocumentAppService _documentAppService; | ||
private readonly IDocsLinkGenerator _docsLinkGenerator; | ||
|
||
public DocumentNavigationController(IDocumentAppService documentAppService, IDocsLinkGenerator docsLinkGenerator) | ||
{ | ||
_documentAppService = documentAppService; | ||
_docsLinkGenerator = docsLinkGenerator; | ||
} | ||
|
||
[HttpGet] | ||
[Route("")] | ||
public virtual async Task<NavigationNode> GetNavigationAsync(GetNavigationNodeWithLinkModel input) | ||
{ | ||
var navigationNode = await _documentAppService.GetNavigationAsync(new GetNavigationDocumentInput | ||
{ | ||
LanguageCode = input.LanguageCode, | ||
Version = input.Version, | ||
ProjectId = input.ProjectId | ||
}); | ||
|
||
NormalPath(navigationNode, input); | ||
|
||
return navigationNode; | ||
} | ||
|
||
protected virtual void NormalPath(NavigationNode node, GetNavigationNodeWithLinkModel input) | ||
{ | ||
if (node.HasChildItems) | ||
{ | ||
foreach (var item in node.Items) | ||
{ | ||
NormalPath(item, input); | ||
} | ||
} | ||
|
||
if (UrlHelper.IsExternalLink(node.Path)) | ||
{ | ||
return; | ||
} | ||
|
||
node.Path = RemoveFileExtensionFromPath(node.Path, input.ProjectFormat); | ||
if (node.Path.IsNullOrWhiteSpace()) | ||
{ | ||
node.Path = "javascript:;"; | ||
return; | ||
} | ||
|
||
node.Path = _docsLinkGenerator.GenerateLink(input.ProjectName, input.LanguageCode, input.RouteVersion, node.Path); | ||
} | ||
|
||
private string RemoveFileExtensionFromPath(string path, string projectFormat) | ||
{ | ||
if (path == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return path.EndsWith("." + projectFormat) | ||
? path.Left(path.Length - projectFormat.Length - 1) | ||
: path; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../docs/src/Volo.Docs.Web/Areas/Models/DocumentNavigation/GetNavigationNodeWithLinkModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using Volo.Abp.Validation; | ||
using Volo.Docs.Language; | ||
using Volo.Docs.Projects; | ||
|
||
namespace Volo.Docs.Areas.Models.DocumentNavigation; | ||
|
||
public class GetNavigationNodeWithLinkModel | ||
{ | ||
public Guid ProjectId { get; set; } | ||
|
||
[DynamicStringLength(typeof(ProjectConsts), nameof(ProjectConsts.MaxVersionNameLength))] | ||
public string Version { get; set; } | ||
|
||
[Required] | ||
[DynamicStringLength(typeof(LanguageConsts), nameof(LanguageConsts.MaxLanguageCodeLength))] | ||
public string LanguageCode { get; set; } | ||
|
||
[Required] | ||
public string ProjectName { get; set; } | ||
|
||
[Required] | ||
public string ProjectFormat { get; set; } | ||
|
||
[Required] | ||
public string RouteVersion { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters