From 32e5dff12600a8edcb49a96b9253472e6b1138cf Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 19 Dec 2024 23:55:14 +0800 Subject: [PATCH 1/4] Lazy expandable feature for documentation --- docs/en/docs-nav.json | 2 + .../Volo/Docs/Documents/NavigationNode.cs | 3 + .../Documents/TagHelpers/TreeTagHelper.cs | 16 +- .../Pages/Documents/Project/Index.cshtml | 15 ++ .../Pages/Documents/Project/index.js | 144 ++++++++++++++++++ 5 files changed, 176 insertions(+), 4 deletions(-) diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index 6967e1f9ee5..d2a928561d2 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -71,6 +71,8 @@ }, { "text": "Book Store Application", + "isLazyExpandable": true, + "path": "tutorials/book-store", "items": [ { "text": "Overview", diff --git a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs index 231a8cddba9..f19b9f41df9 100644 --- a/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs +++ b/modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Documents/NavigationNode.cs @@ -16,6 +16,9 @@ public class NavigationNode [JsonPropertyName("items")] public List Items { get; set; } + [JsonPropertyName("isLazyExpandable")] + public bool IsLazyExpandable { get; set; } + [JsonPropertyName("isIndex")] public bool IsIndex { get; set; } diff --git a/modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs b/modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs index 6d2cb8c9ba3..e6c75d01618 100644 --- a/modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs +++ b/modules/docs/src/Volo.Docs.Web/Areas/Documents/TagHelpers/TreeTagHelper.cs @@ -72,11 +72,14 @@ private string RenderNodeAsHtml(NavigationNode node) var isAnyNodeOpenedInThisLevel = IsAnyNodeOpenedInThisLevel(node); - node.Items?.ForEach(innerNode => + if (!node.IsLazyExpandable || isAnyNodeOpenedInThisLevel) { - content += GetParentNode(innerNode, isAnyNodeOpenedInThisLevel); - }); - + node.Items?.ForEach(innerNode => + { + content += GetParentNode(innerNode, isAnyNodeOpenedInThisLevel); + }); + } + var result = node.IsEmpty ? content : GetLeafNode(node, content); return result; @@ -121,6 +124,11 @@ private string GetLeafNode(NavigationNode node, string content) listItemCss += " selected-tree"; } + if (node.IsLazyExpandable) + { + listItemCss += " lazy-expand"; + } + string listInnerItem; if (node.Path.IsNullOrEmpty() && node.IsLeaf) { 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 976154c6302..8d36e55bd23 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 @@ -53,6 +53,21 @@ @if (Model.LoadSuccess) { + 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 41896bb2fdf..4d8e036a718 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 @@ -1,5 +1,116 @@ +var doc = doc || {}; + (function ($) { $(function () { + + var _documentAppService = volo.docs.documents.docsDocument; + + doc.lazyExpandableNavigation = { + isAllLoaded: false, + findNode : function(text, node){ + if(node.text === text && node.isLazyExpandable){ + return node; + } + if(node.items){ + for (let i = 0; i < node.items.length; i++) { + var result = doc.lazyExpandableNavigation.findNode(text, node.items[i]); + if(result){ + return result; + } + } + } + return null; + }, + renderNodeAsHtml : function($lazyLiElement, node){ + if(node.isEmpty){ + return; + } + + var $ul = $(``); + var $li = $(`
  • `); + + $li.append(` ${node.text}`) + + if(node.isLazyExpandable){ + $li.addClass("lazy-expand"); + }else if(node.hasChildItems){ + node.items.forEach(function(item){ + doc.lazyExpandableNavigation.renderNodeAsHtml($li, item); + }); + } + + $ul.append($li); + $lazyLiElement.append($ul) + + function normalPath(path){ + var pathWithoutFileExtension = removeFileExtensionFromPath(path); + + if (!pathWithoutFileExtension) + { + return "javascript:;"; + } + + if (path.toLowerCase().startsWith("http://") || path.toLowerCase().startsWith("https://")) + { + return path; + } + + path = abp.appPath + doc.uiOptions.routePrefix; + + if(doc.uiOptions.multiLanguageMode === `True`){ + path += doc.project.languageCode; + } + + if(doc.uiOptions.singleProjectMode === `False`){ + path += "/" + doc.project.name + } + + path += "/" + doc.project.routeVersion; + path += "/" + pathWithoutFileExtension; + return path.replace("//","/"); + } + + function removeFileExtensionFromPath(path){ + if (!path) + { + return null; + } + + var lastDotIndex = path.lastIndexOf("."); + if (lastDotIndex < 0) + { + return path; + } + + return path.substring(0, lastDotIndex); + } + }, + loadAll : function(lazyLiElements){ + if(doc.lazyExpandableNavigation.isAllLoaded){ + return; + } + for(var i = 0; i < lazyLiElements.length; i++){ + var $li = $(lazyLiElements[i]); + if($li.has("ul").length === 0){ + var node = doc.lazyExpandableNavigation.findNode($li.find("a").text(), doc.project.navigation); + node.items.forEach(item => { + doc.lazyExpandableNavigation.renderNodeAsHtml($li, item); + }) + } + + var childLazyLiElements = $li.find("li.lazy-expand"); + if(childLazyLiElements.length > 0){ + doc.lazyExpandableNavigation.loadAll(childLazyLiElements); + } + + $("li .lazy-expand").off('click'); + initLazyExpandNavigation(); + } + + doc.lazyExpandableNavigation.isAllLoaded = true; + } + } + var initNavigationFilter = function (navigationContainerId) { var $navigation = $('#' + navigationContainerId); @@ -23,6 +134,8 @@ return; } + doc.lazyExpandableNavigation.loadAll($navigation.find("li.lazy-expand")); + var filteredItems = $navigation .find('li > a') .filter(function () { @@ -98,6 +211,16 @@ }); }; + var initDocProject = function(){ + _documentAppService.getNavigation({ + projectId: doc.project.id, + version: doc.project.version, + languageCode: doc.project.languageCode + }).done((data) => { + doc.project.navigation = data; + }) + } + var initSocialShareLinks = function () { var pageHeader = $('.docs-body').find('h1, h2').first().text(); @@ -272,6 +395,25 @@ } }; + var initLazyExpandNavigation = function(){ + $("li .lazy-expand").on('click', function(){ + var $this = $(this); + if($this.has("ul").length > 0){ + return; + } + + var node = doc.lazyExpandableNavigation.findNode($this.find("a").text(), doc.project.navigation); + node.items.forEach(item => { + doc.lazyExpandableNavigation.renderNodeAsHtml($this, item); + }) + + $("li .lazy-expand").off('click'); + initLazyExpandNavigation(); + }); + } + + initDocProject(); + initNavigationFilter('sidebar-scroll'); initAnchorTags('.docs-page .docs-body'); @@ -279,6 +421,8 @@ initSocialShareLinks(); initSections(); + + initLazyExpandNavigation(); Element.prototype.querySelector = function (selector) { var result = $(this).find(decodeURI(selector)); From 9362bdd5c63ea1bb702edeaa71ed254228ba7632 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Fri, 20 Dec 2024 11:40:53 +0800 Subject: [PATCH 2/4] Update docs-nav.json to add isLazyExpandable --- docs/en/docs-nav.json | 173 +++++++++++++++++- .../Pages/Documents/Project/index.js | 19 +- .../Pages/Documents/Shared/Scripts/vs.js | 42 +++-- 3 files changed, 208 insertions(+), 26 deletions(-) diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index d2a928561d2..5f6ca79b556 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -53,6 +53,8 @@ }, { "text": "TODO Application", + "isLazyExpandable": true, + "path": "tutorials/todo", "items": [ { "text": "Overview", @@ -153,6 +155,8 @@ }, { "text": "Modular Monolith Application", + "isLazyExpandable": true, + "path": "tutorials/modular-crm/index.md", "items": [ { "text": "Overview", @@ -1823,7 +1827,170 @@ }, { "text": "Microservice Solution", - "path": "solution-templates/microservice" + "isLazyExpandable": true, + "path": "solution-templates/microservice", + "items":[ + { + "text": "Overview", + "path": "solution-templates/microservice" + }, + { + "text": "Solution Structure", + "path": "solution-templates/microservice/solution-structure.md" + }, + { + "text": "Main Components", + "items": [ + { + "text": "Overview", + "path": "solution-templates/microservice/main-components" + }, + { + "text": "Microservices", + "path": "solution-templates/microservice/microservices.md" + }, + { + "text": "API Gateways", + "path": "solution-templates/microservice/api-gateways.md" + }, + { + "text": "Web Applications", + "path": "solution-templates/microservice/web-applications.md" + }, + { + "text": "Mobile Applications", + "path": "solution-templates/microservice/mobile-applications.md" + } + ] + }, + { + "text": "Built-In Features", + "items": [ + { + "text": "Overview", + "path": "solution-templates/microservice/built-in-features" + }, + { + "text": "Authentication", + "path": "solution-templates/microservice/authentication.md" + }, + { + "text": "Database configurations", + "path": "solution-templates/microservice/database-configurations.md" + }, + { + "text": "Logging (with Serilog and Elasticsearch)", + "path": "solution-templates/microservice/logging.md" + }, + { + "text": "Monitoring (with Prometheus and Grafana)", + "path": "solution-templates/microservice/monitoring.md" + }, + { + "text": "Swagger integration", + "path": "solution-templates/microservice/swagger.md" + }, + { + "text": "Permission management", + "path": "solution-templates/microservice/permission-management.md" + }, + { + "text": "Feature management", + "path": "solution-templates/microservice/feature-management.md" + }, + { + "text": "Localization system", + "path": "solution-templates/microservice/localization-system.md" + }, + { + "text": "Background Jobs", + "path": "solution-templates/microservice/background-jobs.md" + }, + { + "text": "Background Workers", + "path": "solution-templates/microservice/background-workers.md" + }, + { + "text": "Distributed Locking", + "path": "solution-templates/microservice/distributed-locking.md" + }, + { + "text": "Distributed Cache", + "path": "solution-templates/microservice/distributed-cache.md" + }, + { + "text": "Multi-Tenancy", + "path": "solution-templates/microservice/multi-tenancy.md" + }, + { + "text": "BLOB Storing", + "path": "solution-templates/microservice/blob-storing.md" + }, + { + "text": "CORS configuration", + "path": "solution-templates/microservice/cors-configuration.md" + } + ] + }, + { + "text": "Communication", + "items":[ + { + "text": "Overview", + "path": "solution-templates/microservice/communication" + }, + { + "text": "HTTP API Calls", + "path": "solution-templates/microservice/communication/http-api-calls.md" + }, + { + "text": "gRPC Calls", + "path": "solution-templates/microservice/communication/grpc-calls.md" + }, + { + "text": "Distributed Events", + "path": "solution-templates/microservice/communication/distributed-events.md" + } + ] + }, + { + "text": "Helm Charts and Kubernetes", + "path": "solution-templates/microservice/helm-charts-and-kubernetes.md" + }, + { + "text": "Guides", + "items": [ + { + "text": "Overview", + "path": "solution-templates/microservice/guides" + }, + { + "text": "Adding new microservices", + "path": "solution-templates/microservice/guides/adding-new-microservices.md" + }, + { + "text": "Adding new applications", + "path": "solution-templates/microservice/guides/adding-new-applications.md" + }, + { + "text": "Adding new API gateways", + "path": "solution-templates/microservice/guides/adding-new-api-gateways.md" + }, + { + "text": "Mono-repo vs multiple repository approaches", + "path": "solution-templates/microservice/guides/mono-repo-vs-multiple-repository-approaches.md" + }, + { + "text": "Authoring unit and integration tests", + "path": "solution-templates/microservice/guides/authoring-unit-and-integration-tests.md" + }, + { + "text": "How to use with ABP Suite", + "path": "solution-templates/microservice/guides/how-to-use-with-abp-suite.md" + } + ] + } + ] }, { "text": "Application Module", @@ -1911,6 +2078,8 @@ }, { "text": "IdentityServer", + "isLazyExpandable": true, + "path": "modules/identity-server", "items": [ { "text": "Overview", @@ -1933,6 +2102,8 @@ }, { "text": "OpenIddict", + "isLazyExpandable": true, + "path": "modules/openiddict", "items": [ { "text": "Overview", 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 4d8e036a718..22993a0c4f3 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 @@ -21,27 +21,30 @@ var doc = doc || {}; } return null; }, - renderNodeAsHtml : function($lazyLiElement, node){ + renderNodeAsHtml : function($lazyLiElement, node, isRootLazyNode){ if(node.isEmpty){ return; } - - var $ul = $(``); + + var textCss = node.path ? "": "tree-toggle"; + var uiCss = isRootLazyNode ? "" : "style='display: none;'"; + var $ul = $(``); var $li = $(`
  • `); - $li.append(` ${node.text}`) + $li.append(` ${node.text}`) if(node.isLazyExpandable){ $li.addClass("lazy-expand"); }else if(node.hasChildItems){ node.items.forEach(function(item){ - doc.lazyExpandableNavigation.renderNodeAsHtml($li, item); + doc.lazyExpandableNavigation.renderNodeAsHtml($li, item, false); }); } $ul.append($li); $lazyLiElement.append($ul) - + + window.Toc.helpers.initNavEvent(); function normalPath(path){ var pathWithoutFileExtension = removeFileExtensionFromPath(path); @@ -94,7 +97,7 @@ var doc = doc || {}; if($li.has("ul").length === 0){ var node = doc.lazyExpandableNavigation.findNode($li.find("a").text(), doc.project.navigation); node.items.forEach(item => { - doc.lazyExpandableNavigation.renderNodeAsHtml($li, item); + doc.lazyExpandableNavigation.renderNodeAsHtml($li, item, true); }) } @@ -404,7 +407,7 @@ var doc = doc || {}; var node = doc.lazyExpandableNavigation.findNode($this.find("a").text(), doc.project.navigation); node.items.forEach(item => { - doc.lazyExpandableNavigation.renderNodeAsHtml($this, item); + doc.lazyExpandableNavigation.renderNodeAsHtml($this, item, true); }) $("li .lazy-expand").off('click'); diff --git a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js index 74767bf56b5..5208ac99c07 100644 --- a/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js +++ b/modules/docs/src/Volo.Docs.Web/Pages/Documents/Shared/Scripts/vs.js @@ -1,23 +1,7 @@ (function ($) { $(function () { - $('li:not(.last-link) a.tree-toggle').click(function () { - $(this).parent().children('ul.tree').toggle(100); - $(this).closest('li').toggleClass('selected-tree'); - }); - - $('li:not(.last-link) span.plus-icon i.fa-chevron-right').click( - function () { - var $element = $(this).parent(); - var $filter = $('.docs-version #filter'); - if ($filter && $filter.val() != ''){ - return; - } - - $element.parent().children('ul.tree').toggle(100); - $element.closest('li').toggleClass('selected-tree'); - } - ); + window.Toc.helpers.initNavEvent(); var scrollTopBtn = $('.scroll-top-btn'); var enoughHeight = $('.docs-sidebar-wrapper > .docs-top').height(); @@ -159,6 +143,30 @@ $li.append($a); return $li; }; + + window.Toc.helpers.initNavEvent = function () { + $('li:not(.last-link) a.tree-toggle').off('click'); + $('li:not(.last-link) span.plus-icon i.fa-chevron-right').off('click'); + + $('li:not(.last-link) a.tree-toggle').click(function () { + $(this).parent().children('ul.tree').toggle(100); + $(this).closest('li').toggleClass('selected-tree'); + }); + + $('li:not(.last-link) span.plus-icon i.fa-chevron-right').click( + function () { + var $element = $(this).parent(); + var $filter = $('.docs-version #filter'); + + if ($filter && $filter.val() != ''){ + return; + } + + $element.parent().children('ul.tree').toggle(100); + $element.closest('li').toggleClass('selected-tree'); + } + ); + } function docsCriteria() { var docsContentWidth = $('.docs-content').width() - 74; From a0de880b8df11fc745d83171edf99fa817f59d0f Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Mon, 23 Dec 2024 20:07:17 +0800 Subject: [PATCH 3/4] Add DocumentNavigationController --- .../Documents/DocumentNavigationController.cs | 80 +++++++++++++++++++ .../GetNavigationNodeWithLinkModel.cs | 28 +++++++ .../Pages/Documents/Project/Index.cshtml | 10 +-- .../Pages/Documents/Project/index.js | 77 +++++------------- 4 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentNavigationController.cs create mode 100644 modules/docs/src/Volo.Docs.Web/Areas/Models/DocumentNavigation/GetNavigationNodeWithLinkModel.cs diff --git a/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentNavigationController.cs b/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentNavigationController.cs new file mode 100644 index 00000000000..cac52e8d5f7 --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/Areas/Documents/DocumentNavigationController.cs @@ -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 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; + } +} \ No newline at end of file diff --git a/modules/docs/src/Volo.Docs.Web/Areas/Models/DocumentNavigation/GetNavigationNodeWithLinkModel.cs b/modules/docs/src/Volo.Docs.Web/Areas/Models/DocumentNavigation/GetNavigationNodeWithLinkModel.cs new file mode 100644 index 00000000000..085cc2de0ec --- /dev/null +++ b/modules/docs/src/Volo.Docs.Web/Areas/Models/DocumentNavigation/GetNavigationNodeWithLinkModel.cs @@ -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; } +} \ No newline at end of file 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 8d36e55bd23..fb1f232cb36 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 @@ -57,15 +57,11 @@ var doc = doc || {}; doc.project = { id: '@Model.Project.Id', - name: '@Model.Project.Name', + name: '@Model.Project.ShortName', languageCode: '@Model.LanguageCode', version: '@Model.Version', - routeVersion: '@(Model.LatestVersionInfo == null || Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)', - } - doc.uiOptions = { - routePrefix: '@DocsUiOptions.Value.RoutePrefix', - multiLanguageMode : `@DocsUiOptions.Value.MultiLanguageMode`, - singleProjectMode : `@DocsUiOptions.Value.SingleProjectMode.Enable`, + format: '@Model.Project.Format', + routeVersion: '@(Model.LatestVersionInfo == null || Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)' } 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 22993a0c4f3..730fe0116a9 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 @@ -3,17 +3,15 @@ var doc = doc || {}; (function ($) { $(function () { - var _documentAppService = volo.docs.documents.docsDocument; - doc.lazyExpandableNavigation = { isAllLoaded: false, - findNode : function(text, node){ - if(node.text === text && node.isLazyExpandable){ + findNode : function(text, href, node){ + if(node.text === text && node.path === href && node.isLazyExpandable){ return node; } if(node.items){ for (let i = 0; i < node.items.length; i++) { - var result = doc.lazyExpandableNavigation.findNode(text, node.items[i]); + var result = doc.lazyExpandableNavigation.findNode(text, href, node.items[i]); if(result){ return result; } @@ -26,12 +24,12 @@ var doc = doc || {}; return; } - var textCss = node.path ? "": "tree-toggle"; + var textCss = node.path === "javascript:;" ? "": "tree-toggle"; var uiCss = isRootLazyNode ? "" : "style='display: none;'"; var $ul = $(``); var $li = $(`
  • `); - $li.append(` ${node.text}`) + $li.append(` ${node.text}`) if(node.isLazyExpandable){ $li.addClass("lazy-expand"); @@ -45,48 +43,6 @@ var doc = doc || {}; $lazyLiElement.append($ul) window.Toc.helpers.initNavEvent(); - function normalPath(path){ - var pathWithoutFileExtension = removeFileExtensionFromPath(path); - - if (!pathWithoutFileExtension) - { - return "javascript:;"; - } - - if (path.toLowerCase().startsWith("http://") || path.toLowerCase().startsWith("https://")) - { - return path; - } - - path = abp.appPath + doc.uiOptions.routePrefix; - - if(doc.uiOptions.multiLanguageMode === `True`){ - path += doc.project.languageCode; - } - - if(doc.uiOptions.singleProjectMode === `False`){ - path += "/" + doc.project.name - } - - path += "/" + doc.project.routeVersion; - path += "/" + pathWithoutFileExtension; - return path.replace("//","/"); - } - - function removeFileExtensionFromPath(path){ - if (!path) - { - return null; - } - - var lastDotIndex = path.lastIndexOf("."); - if (lastDotIndex < 0) - { - return path; - } - - return path.substring(0, lastDotIndex); - } }, loadAll : function(lazyLiElements){ if(doc.lazyExpandableNavigation.isAllLoaded){ @@ -95,7 +51,8 @@ var doc = doc || {}; for(var i = 0; i < lazyLiElements.length; i++){ var $li = $(lazyLiElements[i]); if($li.has("ul").length === 0){ - var node = doc.lazyExpandableNavigation.findNode($li.find("a").text(), doc.project.navigation); + var $a = $li.find("a"); + var node = doc.lazyExpandableNavigation.findNode($a.text(), $a.attr("href"), doc.project.navigation); node.items.forEach(item => { doc.lazyExpandableNavigation.renderNodeAsHtml($li, item, true); }) @@ -215,11 +172,18 @@ var doc = doc || {}; }; var initDocProject = function(){ - _documentAppService.getNavigation({ - projectId: doc.project.id, - version: doc.project.version, - languageCode: doc.project.languageCode - }).done((data) => { + abp.ajax({ + type :"GET", + url: '/docs/document-navigation', + data: { + projectId: doc.project.id, + version: doc.project.version, + routeVersion: doc.project.routeVersion, + languageCode: doc.project.languageCode, + projectName: doc.project.name, + projectFormat: doc.project.format + } + }).done(data => { doc.project.navigation = data; }) } @@ -405,7 +369,8 @@ var doc = doc || {}; return; } - var node = doc.lazyExpandableNavigation.findNode($this.find("a").text(), doc.project.navigation); + var $a = $this.find("a"); + var node = doc.lazyExpandableNavigation.findNode($a.text(), $a.attr("href") , doc.project.navigation); node.items.forEach(item => { doc.lazyExpandableNavigation.renderNodeAsHtml($this, item, true); }) From 7c85b2aa0703c86f95cf691fa25b4d75440ed8cc Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 24 Dec 2024 10:40:47 +0800 Subject: [PATCH 4/4] Update docs-env --- docs/en/docs-nav.json | 28 +++++++++---------- .../Pages/Documents/Project/index.js | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/en/docs-nav.json b/docs/en/docs-nav.json index 5f6ca79b556..dd21bed20e3 100644 --- a/docs/en/docs-nav.json +++ b/docs/en/docs-nav.json @@ -1868,7 +1868,7 @@ "items": [ { "text": "Overview", - "path": "solution-templates/microservice/built-in-features" + "path": "solution-templates/microservice/built-in-features.md" }, { "text": "Authentication", @@ -1937,19 +1937,19 @@ "items":[ { "text": "Overview", - "path": "solution-templates/microservice/communication" + "path": "solution-templates/microservice/communication.md" }, { "text": "HTTP API Calls", - "path": "solution-templates/microservice/communication/http-api-calls.md" + "path": "solution-templates/microservice/http-api-calls.md" }, { "text": "gRPC Calls", - "path": "solution-templates/microservice/communication/grpc-calls.md" + "path": "solution-templates/microservice/grpc-calls.md" }, { "text": "Distributed Events", - "path": "solution-templates/microservice/communication/distributed-events.md" + "path": "solution-templates/microservice/distributed-events.md" } ] }, @@ -1962,31 +1962,31 @@ "items": [ { "text": "Overview", - "path": "solution-templates/microservice/guides" + "path": "solution-templates/microservice/guides.md" }, { "text": "Adding new microservices", - "path": "solution-templates/microservice/guides/adding-new-microservices.md" + "path": "solution-templates/microservice/adding-new-microservices.md" }, { "text": "Adding new applications", - "path": "solution-templates/microservice/guides/adding-new-applications.md" + "path": "solution-templates/microservice/adding-new-applications.md" }, { "text": "Adding new API gateways", - "path": "solution-templates/microservice/guides/adding-new-api-gateways.md" + "path": "solution-templates/microservice/adding-new-api-gateways.md" }, { "text": "Mono-repo vs multiple repository approaches", - "path": "solution-templates/microservice/guides/mono-repo-vs-multiple-repository-approaches.md" + "path": "solution-templates/microservice/mono-repo-vs-multiple-repository-approaches.md" }, { "text": "Authoring unit and integration tests", - "path": "solution-templates/microservice/guides/authoring-unit-and-integration-tests.md" + "path": "solution-templates/microservice/authoring-unit-and-integration-tests.md" }, { "text": "How to use with ABP Suite", - "path": "solution-templates/microservice/guides/how-to-use-with-abp-suite.md" + "path": "solution-templates/microservice/how-to-use-with-abp-suite.md" } ] } @@ -2079,7 +2079,7 @@ { "text": "IdentityServer", "isLazyExpandable": true, - "path": "modules/identity-server", + "path": "modules/identity-server.md", "items": [ { "text": "Overview", @@ -2103,7 +2103,7 @@ { "text": "OpenIddict", "isLazyExpandable": true, - "path": "modules/openiddict", + "path": "modules/openiddict.md", "items": [ { "text": "Overview", 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 730fe0116a9..0cfbdff32f5 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 @@ -60,10 +60,10 @@ var doc = doc || {}; var childLazyLiElements = $li.find("li.lazy-expand"); if(childLazyLiElements.length > 0){ + doc.lazyExpandableNavigation.isAllLoaded = false; doc.lazyExpandableNavigation.loadAll(childLazyLiElements); } - $("li .lazy-expand").off('click'); initLazyExpandNavigation(); } @@ -363,6 +363,7 @@ var doc = doc || {}; }; var initLazyExpandNavigation = function(){ + $("li .lazy-expand").off('click'); $("li .lazy-expand").on('click', function(){ var $this = $(this); if($this.has("ul").length > 0){ @@ -375,7 +376,6 @@ var doc = doc || {}; doc.lazyExpandableNavigation.renderNodeAsHtml($this, item, true); }) - $("li .lazy-expand").off('click'); initLazyExpandNavigation(); }); }