DocsUrlOptions refactor

pull/1331/head
Yunus Emre Kalkan 6 years ago
parent 7e07f11453
commit 0fc9238218

@ -20,7 +20,7 @@ namespace VoloDocs.Web.Pages
//TODO: Create HomeController & Index instead of Page. Otherwise, we have an empty Index.cshtml file.
if (!_urlOptions.RoutePrefix.IsNullOrWhiteSpace())
{
return Redirect("." + _urlOptions.GetFormattedRoutePrefix());
return Redirect("." + _urlOptions.RoutePrefix);
}
return Page();

@ -142,7 +142,7 @@ namespace Volo.Docs.Areas.Documents.TagHelpers
return "javascript:;";
}
var prefix = _urlOptions.GetFormattedRoutePrefix();
var prefix = _urlOptions.RoutePrefix;
return prefix + LanguageCode + "/" + ProjectName + "/" + Version + "/" + pathWithoutFileExtension;
}

@ -4,19 +4,25 @@ namespace Volo.Docs
{
public class DocsUrlOptions
{
private string _routePrefix = "documents";
/// <summary>
/// Default value: "documents";
/// </summary>
public string RoutePrefix { get; set; } = "documents";
public string RoutePrefix
{
get => GetFormattedRoutePrefix();
set => _routePrefix = value;
}
public string GetFormattedRoutePrefix()
private string GetFormattedRoutePrefix()
{
if (string.IsNullOrWhiteSpace(RoutePrefix))
{
return "/";
}
if (string.IsNullOrWhiteSpace(_routePrefix))
{
return "/";
}
return RoutePrefix.EnsureEndsWith('/').EnsureStartsWith('/');
return _routePrefix.EnsureEndsWith('/').EnsureStartsWith('/');
}
}
}

@ -43,9 +43,9 @@ namespace Volo.Docs
{
var urlOptions = context.Services
.GetRequiredServiceLazy<IOptions<DocsUrlOptions>>()
.Value;
.Value.Value;
var routePrefix = urlOptions.Value.GetFormattedRoutePrefix();
var routePrefix = urlOptions.RoutePrefix;
options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{projectName}");
options.Conventions.AddPageRoute("/Documents/Project/Index", routePrefix + "{languageCode}/{projectName}");

@ -73,7 +73,7 @@ namespace Volo.Docs.Markdown
return string.Format(
MdLinkFormat,
displayText,
_urlOptions.GetFormattedRoutePrefix(),
_urlOptions.RoutePrefix,
languageCode,
projectShortName,
version,
@ -101,7 +101,7 @@ namespace Volo.Docs.Markdown
return string.Format(
MdLinkFormat,
displayText,
_urlOptions.GetFormattedRoutePrefix(),
_urlOptions.RoutePrefix,
languageCode,
projectShortName,
version,

@ -27,7 +27,7 @@ namespace Volo.Docs.Pages.Documents
public async Task<IActionResult> OnGetAsync()
{
DocumentsUrlPrefix = _urlOptions.GetFormattedRoutePrefix();
DocumentsUrlPrefix = _urlOptions.RoutePrefix;
var listResult = await _projectAppService.GetListAsync();

@ -73,7 +73,7 @@ namespace Volo.Docs.Pages.Documents.Project
public async Task<IActionResult> OnGetAsync()
{
DocumentsUrlPrefix = _options.GetFormattedRoutePrefix();
DocumentsUrlPrefix = _options.RoutePrefix;
if (IsDocumentCultureDifferentThanCurrent())
{

Loading…
Cancel
Save