From 7309ccd6f23ac5b3d2875f8f0d3d8f1f3df50d9b Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 31 May 2019 13:31:07 +0300 Subject: [PATCH] docs redirect improvements --- .../docs/app/VoloDocs.Web/Pages/Index.cshtml | 52 +------------------ .../app/VoloDocs.Web/Pages/Index.cshtml.cs | 24 ++------- .../Pages/Documents/Index.cshtml | 4 +- .../Pages/Documents/Index.cshtml.cs | 19 ++++--- .../Pages/Documents/Project/Index.cshtml.cs | 9 ++-- 5 files changed, 23 insertions(+), 85 deletions(-) diff --git a/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml b/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml index 3cc5408311..0d75012326 100644 --- a/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml +++ b/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml @@ -1,55 +1,5 @@ @page - -@using System.Linq -@using Microsoft.AspNetCore.Mvc.Localization -@using Volo.Docs -@using Volo.Docs.Localization -@using Volo.Docs.Pages.Documents - @model VoloDocs.Web.Pages.IndexModel -@inject IHtmlLocalizer L - -@section styles { - - - +@{ } -
- -

- @L["WelcomeVoloDocs"] -

- - @if (!Model.Projects.Any()) - { -
- -
- } - else if (Model.Projects.Count > 1) - { -

@L["Projects"]

-

-

-

- } - -
diff --git a/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs b/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs index befbbb1cdf..3c3d0ca38a 100644 --- a/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs +++ b/modules/docs/app/VoloDocs.Web/Pages/Index.cshtml.cs @@ -9,31 +9,15 @@ namespace VoloDocs.Web.Pages { public class IndexModel : PageModel { - public IReadOnlyList Projects { get; set; } - private readonly IProjectAppService _projectAppService; - - public IndexModel(IProjectAppService projectAppService) + public IndexModel() { - _projectAppService = projectAppService; + } - public async Task OnGetAsync() + public IActionResult OnGet() { - Projects = (await _projectAppService.GetListAsync()).Items; - - //if (Projects.Count == 1) - //{ - // return RedirectToPage("./Documents/Project/Index", new - // { - // projectName = Projects[0].ShortName, - // version = DocsAppConsts.Latest, - // languageCode = "", - // documentName = Projects[0].DefaultDocumentName - // }); - //} - - return Page(); + return Redirect("./documents"); } } } \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml index 1c5976e760..7b13a66aba 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml @@ -29,9 +29,7 @@ {
  • - + @project.Name

    diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml.cs index 2852c233b5..dee88226bb 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Index.cshtml.cs @@ -1,35 +1,38 @@ +using System; using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; +using Microsoft.Extensions.Configuration; +using Volo.Abp.Configuration; using Volo.Docs.Projects; namespace Volo.Docs.Pages.Documents { public class IndexModel : PageModel { + public string DocumentsUrlPrefix { get; set; } + public IReadOnlyList Projects { get; set; } private readonly IProjectAppService _projectAppService; + private readonly IConfigurationRoot _configuration; - public IndexModel(IProjectAppService projectAppService) + public IndexModel(IProjectAppService projectAppService, IConfigurationAccessor configurationAccessor) { + _configuration = configurationAccessor.Configuration; _projectAppService = projectAppService; } public async Task OnGetAsync() { + DocumentsUrlPrefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : ""; + var listResult = await _projectAppService.GetListAsync(); if (listResult.Items.Count == 1) { - return RedirectToPage("./Project/Index", new - { - projectName = listResult.Items[0].ShortName, - version = DocsAppConsts.Latest, - languageCode = "", - documentName = listResult.Items[0].DefaultDocumentName - }); + return Redirect("./" + DocumentsUrlPrefix + listResult.Items[0].ShortName); } Projects = listResult.Items; 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 d7de812579..6732dd45fa 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 @@ -49,6 +49,8 @@ namespace Volo.Docs.Pages.Documents.Project public VersionInfoViewModel LatestVersionInfo { get; private set; } + public string DocumentsUrlPrefix { get; set; } + public bool DocumentLanguageIsDifferent { get; set; } private readonly IDocumentAppService _documentAppService; @@ -70,6 +72,8 @@ namespace Volo.Docs.Pages.Documents.Project public async Task OnGetAsync() { + DocumentsUrlPrefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : ""; + await SetProjectAsync(); await SetProjectsAsync(); await SetVersionAsync(); @@ -316,7 +320,7 @@ namespace Volo.Docs.Pages.Documents.Project LanguageSelectListItems.Add( new SelectListItem( language.DisplayName, - "/documents/" + language.Code + "/" + Project.ShortName + "/" + Version + "/" + DocumentName, + "/" + DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + Version + "/" + DocumentName, language.Code == LanguageCode ) ); @@ -346,8 +350,7 @@ namespace Volo.Docs.Pages.Documents.Project private void AddLanguageCodePrefixToLinks() { - var prefix = Convert.ToBoolean(_configuration["IncludeDocumentPrefixInUrl"]) ? "documents/" : ""; - Document.Content = Document.Content.Replace("href=\"/documents", "href=\"/" + prefix + LanguageCode); + Document.Content = Document.Content.Replace("href=\"/documents", "href=\"/" + DocumentsUrlPrefix + LanguageCode); } } } \ No newline at end of file