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.Domain/Volo/Docs/Localization/Domain/en.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json index 998327cd90..802e05367c 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/en.json @@ -16,6 +16,7 @@ "Projects": "Project(s)", "NoProjectWarning": "There are no projects yet!", "DocumentNotFound": "Oops, the requested document was not found!", + "ProjectNotFound": "Oops, the requested project was not found!", "NavigationDocumentNotFound": "This version does not have a navigation document!", "DocumentNotFoundInSelectedLanguage": "Document in the language you wanted is not found. Document in the default language is shown.", "FilterTopics": "Filter topics", diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json index ef4e95f3dc..8f3a3e44fb 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hans.json @@ -1,6 +1,6 @@ { "culture": "zh-Hans", - "texts": { + "texts": { "Documents": "文档", "BackToWebsite": "返回主网站", "Contributors": "贡献者", @@ -14,6 +14,7 @@ "Projects": "项目", "NoProjectWarning": "还没有项目!", "DocumentNotFound": "找不到请求的文档!", + "ProjectNotFound": "找不到请求的项目!", "NavigationDocumentNotFound": "这个版本没有导航文件!", "DocumentNotFoundInSelectedLanguage": "本文档不适用于所选语言, 将以默认语言显示文档.", "FilterTopics": "过滤主题", diff --git a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json index 6a2f4d8799..dea171863c 100644 --- a/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json +++ b/modules/docs/src/Volo.Docs.Domain/Volo/Docs/Localization/Domain/zh-Hant.json @@ -14,6 +14,7 @@ "Projects": "專案", "NoProjectWarning": "沒有專案!", "DocumentNotFound": "找不到要求的文件!", + "ProjectNotFound": "找不到請求的項目!", "NavigationDocumentNotFound": "這個版本沒有導覽文件!", "DocumentNotFoundInSelectedLanguage": "本文件不適用於所選語系,將以預設語系顯示.", "FilterTopics": "過濾主題", 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 b7db40f1fe..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 @@ -5,12 +5,12 @@ @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Clipboard @using Volo.Abp.AspNetCore.Mvc.UI.Packages.MalihuCustomScrollbar @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Popper -@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent @using Volo.Abp.AspNetCore.Mvc.UI.Packages.Prismjs @using Volo.Abp.AspNetCore.Mvc.UI.Theming @using Volo.Docs @using Volo.Docs.Localization @using Volo.Docs.Pages.Documents.Project +@using Volo.Docs.Pages.Documents.Shared.ErrorComponent @inject IThemeManager ThemeManager @inject IPageLayout PageLayout @inject IHtmlLocalizer L @@ -39,9 +39,10 @@ + } -@if (Model.DocumentFound) +@if (Model.LoadSuccess) {
@@ -152,11 +153,11 @@
-
@@ -171,11 +172,11 @@ - @@ -225,8 +226,8 @@ @if (!string.IsNullOrEmpty(Model.Document.EditLink)) { - - @(L["Edit"]) + + @(L["Edit"]) (@L["LastEditTime"]: @Model.Document.LastUpdatedTime.ToShortDateString()) } @@ -348,14 +349,31 @@ } else { - @(await Component.InvokeAsync(new - { - model = new DocumentNotFoundPageModel + if (!Model.ProjectFound) + { + @(await Component.InvokeAsync(new + { + model = new ErrorPageModel + { + RedirectUrl = Model.DocumentsUrlPrefix, + ErrorCode = "404", + ErrorMessage = L.GetString("ProjectNotFound") + } + })) + } + + if (!Model.DocumentFound) + { + @(await Component.InvokeAsync(new { - ProjectName = Model.ProjectName, - DocumentName = Model.DocumentName, - LanguageCode = Model.LanguageCode, - Version = Model.Version, - } - })) -} \ No newline at end of file + model = new ErrorPageModel + { + RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/" + + (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version), + ErrorCode = "404", + 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 04f8614f56..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 @@ -7,13 +7,11 @@ using System.Threading.Tasks; using System.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Volo.Abp; -using Volo.Abp.AspNetCore.Mvc.Localization; using Volo.Abp.AspNetCore.Mvc.UI.RazorPages; using Volo.Abp.Domain.Entities; -using Volo.Abp.Localization; using Volo.Docs.Documents; using Volo.Docs.HtmlConverting; using Volo.Docs.Models; @@ -37,6 +35,10 @@ namespace Volo.Docs.Pages.Documents.Project public bool DocumentFound { get; set; } = true; + public bool ProjectFound { get; set; } = true; + + public bool LoadSuccess => DocumentFound && ProjectFound; + public string DefaultLanguageCode { get; set; } public ProjectDto Project { get; set; } @@ -120,7 +122,8 @@ namespace Volo.Docs.Pages.Documents.Project catch (EntityNotFoundException e) { Logger.LogWarning(e.Message); - return NotFound(); + ProjectFound = false; + return Page(); } if (ShowProjectsCombobox) @@ -344,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; } @@ -542,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( diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js index 1b3d5ac7c3..71fb550539 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/index.js @@ -203,31 +203,31 @@ 'YandexBot', 'msnbot', 'Rambler', - 'Yahoo', - 'AbachoBOT', - 'accoona', + 'Yahoo', + 'AbachoBOT', + 'accoona', 'AcoiRobot', 'ASPSeek', - 'CrocCrawler', + 'CrocCrawler', 'Dumbot', - 'FAST-WebCrawler', - 'GeonaBot', + 'FAST-WebCrawler', + 'GeonaBot', 'Gigabot', - 'Lycos', - 'MSRBOT', + 'Lycos', + 'MSRBOT', 'Scooter', 'AltaVista', - 'IDBot', - 'eStyle', - 'Scrubby', - 'Slurp', - 'DuckDuckBot', - 'Baiduspider', - 'VoilaBot', - 'ExaLead', - 'Search Dog', - 'MSN Bot' , - 'BingBot' + 'IDBot', + 'eStyle', + 'Scrubby', + 'Slurp', + 'DuckDuckBot', + 'Baiduspider', + 'VoilaBot', + 'ExaLead', + 'Search Dog', + 'MSN Bot', + 'BingBot' ]; var agent = navigator.userAgent; @@ -276,9 +276,8 @@ if (queryStrings.length <= 0) { returnList.push(key + "=" + $(this).val()); - - } - else { + + } else { for (var k = 0; k < queryStrings.length; k++) { returnList.push(key + "=" + $(this).val() + "&" + queryStrings[k]); } @@ -291,12 +290,12 @@ var queryStrings = getQueryStringsFromComboboxes(0); for (var i = 0; i < queryStrings.length; i++) { - html += "" + queryStrings[i]+" " + html += "" + queryStrings[i] + " " } $("#crawler_link").html(html); }; - + initNavigationFilter("sidebar-scroll"); initAnchorTags(".docs-page .docs-body"); @@ -309,5 +308,4 @@ }); -})(jQuery); - +})(jQuery); \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundPageModel.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundPageModel.cs deleted file mode 100644 index 72b2b97584..0000000000 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundPageModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent -{ - public class DocumentNotFoundPageModel - { - public string ProjectName { get; set; } - - public string LanguageCode { get; set; } - - public string Version { get; set; } - - public string DocumentName { get; set; } - - public string DocumentsUrlPrefix { get; set; } - } -} diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundViewComponent.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundViewComponent.cs deleted file mode 100644 index 7aeed9beee..0000000000 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/DocumentNotFoundViewComponent.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using Volo.Abp.AspNetCore.Mvc; - -namespace Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent -{ - public class DocumentNotFoundViewComponent : AbpViewComponent - { - private readonly DocsUiOptions _options; - - public DocumentNotFoundViewComponent(IOptions options) - { - _options = options.Value; - } - public IViewComponentResult Invoke(DocumentNotFoundPageModel model, string defaultErrorMessageKey) - { - model.DocumentsUrlPrefix = _options.RoutePrefix; - - return View("~/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml", model); - } - } -} diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml similarity index 55% rename from modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml rename to modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml index 604ff05da7..4aef93c593 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/DocumentNotFoundComponent/Default.cshtml +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/Default.cshtml @@ -1,17 +1,19 @@ -@using Volo.Docs.Pages.Documents.Shared.DocumentNotFoundComponent -@model DocumentNotFoundPageModel +@model Volo.Docs.Pages.Documents.Shared.ErrorComponent.ErrorPageModel @{ }
-
- 404 +
+ @Model.ErrorCode

- "@Model.DocumentName" not found in @Model.ProjectName documents, with @Model.Version version and @Model.LanguageCode language. + @Model.ErrorMessage

-
- - Go Back - +
+ @if (Model.AutoRedirect) + { + + Go Back (3) + + }
@@ -20,7 +22,7 @@ h1 { font-size: 1.75em; line-height: 1.75; - color: #777; + color: #777; font-weight: normal; } @@ -37,7 +39,7 @@ transform: translate(-50%, -50%); text-align: center; } - + .notfound-404 { font-size: 300px; font-weight: 700; @@ -49,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 new file mode 100644 index 0000000000..62a64fc9d6 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorPageModel.cs @@ -0,0 +1,13 @@ +namespace Volo.Docs.Pages.Documents.Shared.ErrorComponent +{ + public class ErrorPageModel + { + public string ErrorMessage { get; set; } + + 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/ErrorViewComponent.cs b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorViewComponent.cs new file mode 100644 index 0000000000..493b6d896a --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/ErrorViewComponent.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Options; +using Volo.Abp.AspNetCore.Mvc; + +namespace Volo.Docs.Pages.Documents.Shared.ErrorComponent +{ + public class ErrorViewComponent : AbpViewComponent + { + public IViewComponentResult Invoke(ErrorPageModel model) + { + return View("~/Pages/Documents/Shared/ErrorComponent/Default.cshtml", model); + } + } +} 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 new file mode 100644 index 0000000000..edc010aa9f --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/ErrorComponent/error.js @@ -0,0 +1,20 @@ +(function ($) { + + $(function () { + var errorPageRedirect = function () { + var second = 3; + var close = setInterval(() => { + $("#ErrorRedirectSeconds").text(`(${--second})`); + if (second === 0) { + clearInterval(close); + $("#ErrorRedirect")[0].click(); + } + }, 1000); + } + + if (document.getElementById("ErrorRedirect")) { + errorPageRedirect(); + } + }); + +})(jQuery);