From 9e76bb375bc3400c1e27e20300330edbe2c58191 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Wed, 5 Aug 2020 17:11:15 +0300 Subject: [PATCH] docs module: fix latest version links to other documents --- .../Pages/Documents/Project/Index.cshtml.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) 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 b10d741fb2..4568e574a5 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 @@ -309,12 +309,7 @@ namespace Volo.Docs.Pages.Documents.Project if (Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") && (GithubVersionProviderSource) (long) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Branches) { - var prefix = Project.ExtraProperties["VersionBranchPrefix"].ToString(); - var LatestVersionBranchNameWithoutPrefix = - !string.IsNullOrWhiteSpace(Project.LatestVersionBranchName) && - Project.LatestVersionBranchName.StartsWith(prefix) && Project.LatestVersionBranchName.Length > prefix.Length - ? Project.LatestVersionBranchName.Substring(prefix.Length) - : Project.LatestVersionBranchName; + var LatestVersionBranchNameWithoutPrefix = RemoveVersionPrefix(Project.LatestVersionBranchName); var latest = versions.FirstOrDefault(v=> v.Version == LatestVersionBranchNameWithoutPrefix); @@ -327,6 +322,23 @@ namespace Volo.Docs.Pages.Documents.Project return versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Version)) ?? versions.First(); } + private string RemoveVersionPrefix(string version) + { + if (!Project.ExtraProperties.ContainsKey("VersionBranchPrefix")) + { + return version; + } + + var prefix = Project.ExtraProperties["VersionBranchPrefix"].ToString(); + + if (string.IsNullOrWhiteSpace(version) || !version.StartsWith(prefix) || version.Length <= prefix.Length) + { + return version; + } + + return version.Substring(prefix.Length); + } + private void SetLatestVersionBranchName(List versions) { if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") @@ -379,7 +391,7 @@ namespace Volo.Docs.Pages.Documents.Project return DocsAppConsts.Latest; } - return Document.Version == LatestVersionInfo.Version ? + return RemoveVersionPrefix(Document.Version) == LatestVersionInfo.Version ? DocsAppConsts.Latest : Document.Version; }