diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentSource.cs b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentSource.cs index cc0f03a60a..f97eddf0e2 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentSource.cs +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/FileSystem/Documents/FileSystemDocumentSource.cs @@ -87,6 +87,11 @@ namespace Volo.Docs.FileSystem.Documents { throw new SecurityException("Can not get a resource file out of the project folder!"); } + + if (!File.Exists(path)) + { + throw new DocumentNotFoundException(path); + } } } } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml index 74f7c21464..7f521de34b 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml @@ -371,7 +371,8 @@ else RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/" + (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version), ErrorCode = "404", - ErrorMessage = L.GetString("DocumentNotFound") + ErrorMessage = L.GetString("DocumentNotFound"), + AutoRedirect = !Model.DocumentName.IsNullOrWhiteSpace() } })) } 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 f5758447e4..b1d1c021f1 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 @@ -34,7 +34,7 @@ namespace Volo.Docs.Pages.Documents.Project public string LanguageCode { get; set; } public bool DocumentFound { get; set; } = true; - + public bool ProjectFound { get; set; } = true; public bool LoadSuccess => DocumentFound && ProjectFound; @@ -347,43 +347,13 @@ namespace Volo.Docs.Pages.Documents.Project try { - if (DocumentName.IsNullOrWhiteSpace()) - { - Document = await _documentAppService.GetDefaultAsync( - new GetDefaultDocumentInput - { - ProjectId = Project.Id, - LanguageCode = LanguageCode, - Version = Version - } - ); - } - else - { - Document = await _documentAppService.GetAsync( - new GetDocumentInput - { - ProjectId = Project.Id, - Name = DocumentNameWithExtension, - LanguageCode = LanguageCode, - Version = Version - } - ); - } + Document = await GetSpecificDocumentOrDefaultAsync(LanguageCode); } catch (DocumentNotFoundException) { if (LanguageCode != DefaultLanguageCode) { - Document = await _documentAppService.GetAsync( - new GetDocumentInput - { - ProjectId = Project.Id, - Name = DocumentNameWithExtension, - LanguageCode = DefaultLanguageCode, - Version = Version - } - ); + Document = await GetSpecificDocumentOrDefaultAsync(DefaultLanguageCode); DocumentLanguageIsDifferent = true; } @@ -545,6 +515,33 @@ namespace Volo.Docs.Pages.Documents.Project } + private async Task GetSpecificDocumentOrDefaultAsync(string languageCode) + { + if (DocumentName.IsNullOrWhiteSpace()) + { + return await _documentAppService.GetDefaultAsync( + new GetDefaultDocumentInput + { + ProjectId = Project.Id, + LanguageCode = languageCode, + Version = Version + } + ); + } + else + { + return await _documentAppService.GetAsync( + new GetDocumentInput + { + ProjectId = Project.Id, + Name = DocumentNameWithExtension, + LanguageCode = languageCode, + Version = Version + } + ); + } + } + public async Task SetDocumentPreferencesAsync() { var projectParameters = await _documentAppService.GetParametersAsync( @@ -604,7 +601,7 @@ namespace Volo.Docs.Pages.Documents.Project { return null; } - + var firstParagraph = new Regex(@"

(.*?)

", RegexOptions.IgnoreCase); var match = firstParagraph.Match(Document.Content); if (!match.Success) diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml index ff10a25f2a..4aef93c593 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml @@ -3,14 +3,17 @@ }
- @Model.ErrorCode + @Model.ErrorCode

@Model.ErrorMessage

-
- - Go Back (3) - +
+ @if (Model.AutoRedirect) + { + + Go Back (3) + + }
@@ -19,7 +22,7 @@ h1 { font-size: 1.75em; line-height: 1.75; - color: #777; + color: #777; font-weight: normal; } @@ -36,7 +39,7 @@ transform: translate(-50%, -50%); text-align: center; } - + .notfound-404 { font-size: 300px; font-weight: 700; @@ -48,5 +51,5 @@ margin-bottom: -150px; z-index: -1; position: relative; - } - \ No newline at end of file + } + diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorPageModel.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorPageModel.cs index cfb65409c7..62a64fc9d6 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorPageModel.cs +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorPageModel.cs @@ -7,5 +7,7 @@ public string ErrorCode { get; set; } public string RedirectUrl { get; set; } + + public bool AutoRedirect { get; set; } = true; } } diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/error.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/error.js index d1d08829ac..edc010aa9f 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/error.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/error.js @@ -12,7 +12,7 @@ }, 1000); } - if (document.getElementById("DocumentErrorContainer")) { + if (document.getElementById("ErrorRedirect")) { errorPageRedirect(); } });