Browse Source

Docs module: added alternative way (using branches) to get versions

resolves https://github.com/abpframework/abp/issues/4845
pull/4860/head
Yunus Emre Kalkan 6 years ago
parent
commit
8d87d539d7
  1. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs
  2. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs
  3. 3
      modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs
  4. 6
      modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs
  5. 13
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs
  6. 15
      modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs
  7. 8
      modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs
  8. 3
      modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj
  9. 59
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs
  10. 15
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs
  11. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs
  12. 28
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs
  13. 28
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs
  14. 7
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs
  15. 34
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs
  16. 10
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs
  17. 9
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs
  18. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs
  19. 4
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs
  20. 6
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml
  21. 37
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs
  22. 33
      modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs
  23. 1
      modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj
  24. 30
      modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/CreateProjectDto.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -26,4 +27,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/ProjectDto.cs

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Dtos;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -29,4 +30,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

3
modules/docs/src/Volo.Docs.Admin.Application.Contracts/Volo/Docs/Admin/Projects/UpdateProjectDto.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Admin.Projects
{
@ -22,4 +23,4 @@ namespace Volo.Docs.Admin.Projects
public Dictionary<string, object> ExtraProperties { get; set; }
}
}
}

6
modules/docs/src/Volo.Docs.Admin.Web/DocsAdminWebAutoMapperProfile.cs

@ -15,7 +15,11 @@ namespace Volo.Docs.Admin
CreateMap<EditModel.EditGithubProjectViewModel, UpdateProjectDto>().Ignore(x => x.ExtraProperties);
CreateMap<ProjectDto, EditModel.EditGithubProjectViewModel > ()
.Ignore(x => x.GitHubAccessToken).Ignore(x => x.GitHubRootUrl).Ignore(x => x.GitHubUserAgent);
.Ignore(x => x.GitHubAccessToken)
.Ignore(x => x.GitHubRootUrl)
.Ignore(x => x.GitHubUserAgent)
.Ignore(x => x.GithubVersionProviderSource)
.Ignore(x => x.VersionBranchPrefix);
CreateMap<PullModel.PullDocumentViewModel, PullAllDocumentInput>();
CreateMap<PullModel.PullDocumentViewModel, PullDocumentInput>();

13
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Create.cshtml.cs

@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken},
{nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource},
{nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix}
};
return dto;
@ -118,6 +120,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
[DisplayOrder(10003)]
public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases;
[DisplayOrder(10004)]
[StringLength(64)]
public string VersionBranchPrefix { get; set; }
}
}
}
}

15
modules/docs/src/Volo.Docs.Admin.Web/Pages/Docs/Admin/Projects/Edit.cshtml.cs

@ -62,7 +62,9 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
{
{nameof(GithubProject.GitHubRootUrl), GithubProject.GitHubRootUrl},
{nameof(GithubProject.GitHubUserAgent), GithubProject.GitHubUserAgent},
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken}
{nameof(GithubProject.GitHubAccessToken), GithubProject.GitHubAccessToken},
{nameof(GithubProject.GithubVersionProviderSource), GithubProject.GithubVersionProviderSource},
{nameof(GithubProject.VersionBranchPrefix), GithubProject.VersionBranchPrefix}
};
return dto;
@ -75,6 +77,8 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
GithubProject.GitHubAccessToken = (string) dto.ExtraProperties[nameof(GithubProject.GitHubAccessToken)];
GithubProject.GitHubRootUrl = (string) dto.ExtraProperties[nameof(GithubProject.GitHubRootUrl)];
GithubProject.GitHubUserAgent = (string) dto.ExtraProperties[nameof(GithubProject.GitHubUserAgent)];
GithubProject.GithubVersionProviderSource = (GithubVersionProviderSource) dto.ExtraProperties[nameof(GithubProject.GithubVersionProviderSource)];
GithubProject.VersionBranchPrefix = (string) dto.ExtraProperties[nameof(GithubProject.VersionBranchPrefix)];
}
public abstract class EditProjectViewModelBase
@ -125,6 +129,13 @@ namespace Volo.Docs.Admin.Pages.Docs.Admin.Projects
[DisplayOrder(10002)]
[StringLength(64)]
public string GitHubUserAgent { get; set; }
[DisplayOrder(10003)]
public GithubVersionProviderSource GithubVersionProviderSource { get; set; } = GithubVersionProviderSource.Releases;
[DisplayOrder(10004)]
[StringLength(64)]
public string VersionBranchPrefix { get; set; }
}
}
}
}

8
modules/docs/src/Volo.Docs.Domain.Shared/Volo/Docs/Projects/GithubVersionProviderSource.cs

@ -0,0 +1,8 @@
namespace Volo.Docs.Projects
{
public enum GithubVersionProviderSource
{
Releases,
Branches
}
}

3
modules/docs/src/Volo.Docs.Domain/Volo.Docs.Domain.csproj

@ -21,8 +21,9 @@
<PackageReference Include="Octokit" Version="0.48.0" />
<PackageReference Include="NEST" Version="7.7.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.5" />
<PackageReference Include="NuGet.Versioning" Version="5.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Docs.Domain.Shared\Volo.Docs.Domain.Shared.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Ddd.Domain\Volo.Abp.Ddd.Domain.csproj" />

59
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs

@ -9,6 +9,7 @@ using Volo.Docs.GitHub.Projects;
using Volo.Docs.Projects;
using Octokit;
using Volo.Abp;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Extensions;
using Project = Volo.Docs.Projects.Project;
@ -22,11 +23,13 @@ namespace Volo.Docs.GitHub.Documents
private readonly IGithubRepositoryManager _githubRepositoryManager;
private readonly IGithubPatchAnalyzer _githubPatchAnalyzer;
private readonly IVersionHelper _versionHelper;
public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer)
public GithubDocumentSource(IGithubRepositoryManager githubRepositoryManager, IGithubPatchAnalyzer githubPatchAnalyzer, IVersionHelper versionHelper)
{
_githubRepositoryManager = githubRepositoryManager;
_githubPatchAnalyzer = githubPatchAnalyzer;
_versionHelper = versionHelper;
}
public virtual async Task<Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime? lastKnownSignificantUpdateTime = null)
@ -172,7 +175,7 @@ namespace Volo.Docs.GitHub.Documents
* Getting file commits usually throws "Resource temporarily unavailable" or "Network is unreachable"
* This is a trival information and running this inside try-catch is safer.
*/
try
{
return await GetFileCommitsAsync(project, version, project.GetGitHubInnerUrl(languageCode, documentName));
@ -221,15 +224,19 @@ namespace Volo.Docs.GitHub.Documents
public async Task<List<VersionInfo>> GetVersionsAsync(Project project)
{
var url = project.GetGitHubUrl();
var ownerName = GetOwnerNameFromUrl(url);
var repositoryName = GetRepositoryNameFromUrl(url);
var githubVersionProviderSource = GetGithubVersionProviderSource(project);
List<VersionInfo> versions;
try
{
versions = (await GetReleasesAsync(project))
.OrderByDescending(r => r.PublishedAt)
versions = (await _githubRepositoryManager.GetVersionsAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull(), githubVersionProviderSource))
.Select(r => new VersionInfo
{
Name = r.TagName,
DisplayName = r.TagName
Name = r.Name,
DisplayName = r.Name
}).ToList();
}
catch (Exception ex)
@ -239,14 +246,42 @@ namespace Volo.Docs.GitHub.Documents
versions = new List<VersionInfo>();
}
if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName))
if (githubVersionProviderSource == GithubVersionProviderSource.Branches && project.ExtraProperties.ContainsKey("VersionBranchPrefix"))
{
versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName });
var prefix = (string) project.ExtraProperties["VersionBranchPrefix"];
if (!string.IsNullOrEmpty(prefix))
{
versions = versions.Where(v => v.Name.StartsWith(prefix)).ToList();
versions.ForEach(v=> v.Name.Substring(prefix.Length));
versions.ForEach(v=> v.DisplayName.Substring(prefix.Length));
}
versions = _versionHelper.OrderByDescending(versions);
}
if(githubVersionProviderSource == GithubVersionProviderSource.Releases)
{
if (!versions.Any() && !string.IsNullOrEmpty(project.LatestVersionBranchName))
{
versions.Add(new VersionInfo { DisplayName = "1.0.0", Name = project.LatestVersionBranchName });
}
else
{
versions = _versionHelper.OrderByDescending(versions);
}
}
return versions;
}
private GithubVersionProviderSource GetGithubVersionProviderSource(Project project)
{
return project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
? (GithubVersionProviderSource) project.ExtraProperties["GithubVersionProviderSource"]
: GithubVersionProviderSource.Releases;
}
public async Task<DocumentResource> GetResource(Project project, string resourceName, string languageCode, string version)
{
var rawRootUrl = CalculateRawRootUrlWithLanguageCode(project.GetGitHubUrl(version), languageCode);
@ -277,14 +312,6 @@ namespace Volo.Docs.GitHub.Documents
return languageConfig;
}
private async Task<IReadOnlyList<Release>> GetReleasesAsync(Project project)
{
var url = project.GetGitHubUrl();
var ownerName = GetOwnerNameFromUrl(url);
var repositoryName = GetRepositoryNameFromUrl(url);
return await _githubRepositoryManager.GetReleasesAsync(ownerName, repositoryName, project.GetGitHubAccessTokenOrNull());
}
private async Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(Project project, string version, string filename)
{
var url = project.GetGitHubUrl();

15
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubRepositoryManager.cs

@ -6,6 +6,8 @@ using System.Net.Http.Headers;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
using ProductHeaderValue = Octokit.ProductHeaderValue;
namespace Volo.Docs.GitHub.Documents
@ -15,10 +17,12 @@ namespace Volo.Docs.GitHub.Documents
public const string HttpClientName = "GithubRepositoryManagerHttpClientName";
private readonly IHttpClientFactory _clientFactory;
private readonly IGithubVersionProviderFactory _githubVersionProviderFactory;
public GithubRepositoryManager(IHttpClientFactory clientFactory)
public GithubRepositoryManager(IHttpClientFactory clientFactory, IGithubVersionProviderFactory githubVersionProviderFactory)
{
_clientFactory = clientFactory;
_githubVersionProviderFactory = githubVersionProviderFactory;
}
public async Task<string> GetFileRawStringContentAsync(string rawUrl, string token, string userAgent)
@ -32,11 +36,12 @@ namespace Volo.Docs.GitHub.Documents
using var httpClient = CreateHttpClient(token, userAgent);
return await httpClient.GetByteArrayAsync(new Uri(rawUrl));
}
public async Task<IReadOnlyList<Release>> GetReleasesAsync(string name, string repositoryName, string token)
public async Task<IReadOnlyList<GithubVersion>> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource)
{
var client = GetGitHubClient(name, token);
return await client.Repository.Release.GetAll(name, repositoryName);
var _provider = _githubVersionProviderFactory.Create(githubVersionProviderSource);
return await _provider.GetVersions(name, repositoryName, token);
}
public async Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token)

4
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/IGithubRepositoryManager.cs

@ -4,6 +4,8 @@ using System.Text;
using System.Threading.Tasks;
using Octokit;
using Volo.Abp.DependencyInjection;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents
{
@ -13,7 +15,7 @@ namespace Volo.Docs.GitHub.Documents
Task<byte[]> GetFileRawByteArrayContentAsync(string rawUrl, string token, string userAgent);
Task<IReadOnlyList<Release>> GetReleasesAsync(string name, string repositoryName, string token);
Task<IReadOnlyList<GithubVersion>> GetVersionsAsync(string name, string repositoryName, string token, GithubVersionProviderSource githubVersionProviderSource);
Task<IReadOnlyList<GitHubCommit>> GetFileCommitsAsync(string name, string repositoryName, string version, string filename, string token);

28
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubBranchProvider.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubBranchProvider : IGithubVersionProvider, ITransientDependency
{
public async Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token)
{
var client = GetGitHubClient(name, token);
var branches = await client.Repository.Branch.GetAll(name, repositoryName);
return branches.Select(b => new GithubVersion {Name = b.Name}).ToList();
}
private static GitHubClient GetGitHubClient(string name, string token)
{
return token.IsNullOrWhiteSpace()
? new GitHubClient(new ProductHeaderValue(name))
: new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token)));
}
}
}

28
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubReleaseProvider.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Octokit.Internal;
using Volo.Abp.DependencyInjection;
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubReleaseProvider : IGithubVersionProvider, ITransientDependency
{
public async Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token)
{
var client = GetGitHubClient(name, token);
var releases = await client.Repository.Release.GetAll(name, repositoryName);
return releases.Select(r => new GithubVersion {Name = r.TagName}).ToList();
}
private static GitHubClient GetGitHubClient(string name, string token)
{
return token.IsNullOrWhiteSpace()
? new GitHubClient(new ProductHeaderValue(name))
: new GitHubClient(new ProductHeaderValue(name), new InMemoryCredentialStore(new Credentials(token)));
}
}
}

7
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersion.cs

@ -0,0 +1,7 @@
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubVersion
{
public string Name { get; set; }
}
}

34
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/GithubVersionProviderFactory.cs

@ -0,0 +1,34 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents.Version
{
public class GithubVersionProviderFactory : IGithubVersionProviderFactory, ITransientDependency
{
public IServiceProvider ServiceProvider { get; }
public GithubVersionProviderFactory(IServiceProvider serviceProvider)
{
ServiceProvider = serviceProvider;
}
public IGithubVersionProvider Create(GithubVersionProviderSource source)
{
Type serviceType;
switch (source)
{
case GithubVersionProviderSource.Branches:
serviceType = typeof(GithubBranchProvider);
break;
case GithubVersionProviderSource.Releases:
default:
serviceType = typeof(GithubReleaseProvider);
break;
}
return (IGithubVersionProvider)ServiceProvider.GetRequiredService(serviceType);
}
}
}

10
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProvider.cs

@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IGithubVersionProvider
{
Task<List<GithubVersion>> GetVersions(string name, string repositoryName, string token);
}
}

9
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IGithubVersionProviderFactory.cs

@ -0,0 +1,9 @@
using Volo.Docs.Projects;
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IGithubVersionProviderFactory
{
IGithubVersionProvider Create(GithubVersionProviderSource source);
}
}

4
modules/docs/src/Volo.Docs.Web/Version/IVersionHelper.cs → modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/IVersionHelper.cs

@ -1,13 +1,13 @@
using System.Collections.Generic;
using Volo.Docs.Projects;
namespace Volo.Docs.Version
namespace Volo.Docs.GitHub.Documents.Version
{
public interface IVersionHelper
{
List<string> OrderByDescending(List<string> versions);
List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions);
List<VersionInfo> OrderByDescending(List<VersionInfo> versions);
bool IsPreRelease(string version);
}

4
modules/docs/src/Volo.Docs.Web/Version/SemanticVersionHelper.cs → modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/Version/SemanticVersionHelper.cs

@ -5,7 +5,7 @@ using NuGet.Versioning;
using Volo.Abp.DependencyInjection;
using Volo.Docs.Projects;
namespace Volo.Docs.Version
namespace Volo.Docs.GitHub.Documents.Version
{
public class SemanticVersionHelper : IVersionHelper, ITransientDependency
{
@ -14,7 +14,7 @@ namespace Volo.Docs.Version
return versions.OrderByDescending(v=> SemanticVersion.Parse(NormalizeVersion(v)), new VersionComparer()).ToList();
}
public List<VersionInfoDto> OrderByDescending(List<VersionInfoDto> versions)
public List<VersionInfo> OrderByDescending(List<VersionInfo> versions)
{
return versions.OrderByDescending(v => SemanticVersion.Parse(NormalizeVersion(v.Name)), new VersionComparer()).ToList();
}

6
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml

@ -53,7 +53,7 @@
<nav class="navbar navbar-logo">
@if (!Model.Project.Name.IsNullOrWhiteSpace())
{
<a class="navbar-brand w-100" href="@Model.CreateVersionLink(Model.LatestStableVersionInfo, Model.GetSpecificVersionOrLatest())">
<a class="navbar-brand w-100" href="@Model.CreateVersionLink(Model.LatestVersionInfo, Model.GetSpecificVersionOrLatest())">
<span id="ProjectName">@Model.Project.Name</span><br>
<strong class="display-block">
@L["Documents"]
@ -173,7 +173,7 @@
else
{
<ul root-node="@Model.Navigation"
version="@(Model.LatestStableVersionInfo == null || Model.LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
version="@(Model.LatestVersionInfo == null || Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version)"
project-name="@Model.ProjectName"
project-format="@Model.Project.Format"
selected-document-name="@Model.DocumentNameWithExtension"
@ -374,7 +374,7 @@ else
model = new ErrorPageModel
{
RedirectUrl = Model.DocumentsUrlPrefix + Model.LanguageCode + "/" + Model.ProjectName + "/"
+ (Model.LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
+ (Model.LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Model.Version),
ErrorCode = "404",
ErrorMessage = L.GetString("DocumentNotFound"),
AutoRedirect = !Model.DocumentName.IsNullOrWhiteSpace()

37
modules/docs/src/Volo.Docs.Web/Pages/Documents/Project/Index.cshtml.cs

@ -16,9 +16,7 @@ using Volo.Docs.Documents;
using Volo.Docs.HtmlConverting;
using Volo.Docs.Models;
using Volo.Docs.Projects;
using Volo.Docs.Utils;
using NuGet.Versioning;
using Volo.Docs.Version;
using Volo.Docs.GitHub.Documents.Version;
namespace Volo.Docs.Pages.Documents.Project
{
@ -60,7 +58,7 @@ namespace Volo.Docs.Pages.Documents.Project
public NavigationNode Navigation { get; private set; }
public VersionInfoViewModel LatestStableVersionInfo { get; private set; }
public VersionInfoViewModel LatestVersionInfo { get; private set; }
public string DocumentsUrlPrefix { get; set; }
@ -207,7 +205,7 @@ namespace Volo.Docs.Pages.Documents.Project
private IActionResult ReloadPageWithCulture()
{
var returnUrl = DocumentsUrlPrefix + LanguageCode + "/" + ProjectName + "/"
+ (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" +
+ (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" +
DocumentName;
return Redirect("/Abp/Languages/Switch?culture=" + LanguageCode + "&uiCulture=" + LanguageCode + "&returnUrl=" + returnUrl);
@ -218,7 +216,7 @@ namespace Volo.Docs.Pages.Documents.Project
return RedirectToPage(new
{
projectName = ProjectName,
version = (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
version = (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
languageCode = DefaultLanguageCode,
documentName = DocumentName
});
@ -229,7 +227,7 @@ namespace Volo.Docs.Pages.Documents.Project
return RedirectToPage(new
{
projectName = ProjectName,
version = (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
version = (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version),
documentName = "",
languageCode = DefaultLanguageCode
});
@ -256,22 +254,22 @@ namespace Volo.Docs.Pages.Documents.Project
}
var output = await _projectAppService.GetVersionsAsync(Project.ShortName);
var versions = _versionHelper.OrderByDescending(output.Items.ToList())
var versions = output.Items.ToList()
.Select(v => new VersionInfoViewModel(v.DisplayName, v.Name))
.ToList();
if (versions.Any())
{
LatestStableVersionInfo = versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Version)) ?? versions.First();
LatestVersionInfo = versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Version)) ?? versions.First();
SetLatestVersionBranchName(versions);
LatestStableVersionInfo.DisplayText = $"{LatestStableVersionInfo.DisplayText} ({DocsAppConsts.Latest})";
LatestVersionInfo.DisplayText = $"{LatestVersionInfo.DisplayText} ({DocsAppConsts.Latest})";
if (string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
LatestStableVersionInfo.IsSelected = true;
Version = LatestStableVersionInfo.Version;
LatestVersionInfo.IsSelected = true;
Version = LatestVersionInfo.Version;
}
else
{
@ -283,8 +281,8 @@ namespace Volo.Docs.Pages.Documents.Project
}
else
{
LatestStableVersionInfo.IsSelected = true;
Version = LatestStableVersionInfo.Version;
LatestVersionInfo.IsSelected = true;
Version = LatestVersionInfo.Version;
}
}
}
@ -292,7 +290,7 @@ namespace Volo.Docs.Pages.Documents.Project
{
SetLatestVersionBranchName(versions);
LatestStableVersionInfo = new VersionInfoViewModel(
LatestVersionInfo = new VersionInfoViewModel(
$"{DocsAppConsts.Latest}",
DocsAppConsts.Latest,
true);
@ -301,14 +299,15 @@ namespace Volo.Docs.Pages.Documents.Project
VersionSelectItems = versions.Select(v => new SelectListItem
{
Text = v.DisplayText,
Value = CreateVersionLink(LatestStableVersionInfo, v.Version, DocumentName),
Value = CreateVersionLink(LatestVersionInfo, v.Version, DocumentName),
Selected = v.IsSelected
}).ToList();
}
private void SetLatestVersionBranchName(List<VersionInfoViewModel> versions)
{
if (versions.Any() && !string.IsNullOrEmpty(Project.LatestVersionBranchName))
if (!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource")
|| (GithubVersionProviderSource) Project.ExtraProperties["GithubVersionProviderSource"] == GithubVersionProviderSource.Releases)
{
versions.First(v=> !_versionHelper.IsPreRelease(v.Version)).Version = Project.LatestVersionBranchName;
}
@ -357,7 +356,7 @@ namespace Volo.Docs.Pages.Documents.Project
return DocsAppConsts.Latest;
}
return Document.Version == LatestStableVersionInfo.Version ?
return Document.Version == LatestVersionInfo.Version ?
DocsAppConsts.Latest :
Document.Version;
}
@ -396,7 +395,7 @@ namespace Volo.Docs.Pages.Documents.Project
LanguageSelectListItems.Add(
new SelectListItem(
language.DisplayName,
DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + (LatestStableVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" + DocumentName,
DocumentsUrlPrefix + language.Code + "/" + Project.ShortName + "/" + (LatestVersionInfo.IsSelected ? DocsAppConsts.Latest : Version) + "/" + DocumentName,
language.Code == LanguageCode
)
);

33
modules/docs/src/Volo.Docs.Web/Pages/Documents/Search.cshtml.cs

@ -7,27 +7,23 @@ using System.Web;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Volo.Docs.Documents;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.HtmlConverting;
using Volo.Docs.Models;
using Volo.Docs.Projects;
using Volo.Docs.Utils;
using Volo.Docs.Version;
namespace Volo.Docs.Pages.Documents
{
public class SearchModel : PageModel
{
[BindProperty(SupportsGet = true)]
public string ProjectName { get; set; }
[BindProperty(SupportsGet = true)] public string ProjectName { get; set; }
[BindProperty(SupportsGet = true)]
public string Version { get; set; }
[BindProperty(SupportsGet = true)] public string Version { get; set; }
[BindProperty(SupportsGet = true)]
public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)] public string LanguageCode { get; set; }
[BindProperty(SupportsGet = true)]
public string KeyWord { get; set; }
[BindProperty(SupportsGet = true)] public string KeyWord { get; set; }
public ProjectDto Project { get; set; }
@ -64,11 +60,19 @@ namespace Volo.Docs.Pages.Documents
var versions = output.Items.ToList();
if (versions.Any() && string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
if (versions.Any() &&
string.Equals(Version, DocsAppConsts.Latest, StringComparison.OrdinalIgnoreCase))
{
Version = string.IsNullOrEmpty(Project.LatestVersionBranchName) ?
(versions.FirstOrDefault(v=> !_versionHelper.IsPreRelease(v.Name)) ?? versions.First()).Name :
Project.LatestVersionBranchName;
if ((!Project.ExtraProperties.ContainsKey("GithubVersionProviderSource") ||
(GithubVersionProviderSource) Project.ExtraProperties["GithubVersionProviderSource"] ==GithubVersionProviderSource.Releases) &&
!string.IsNullOrEmpty(Project.LatestVersionBranchName))
{
Version = Project.LatestVersionBranchName;
}
else
{
Version = (versions.FirstOrDefault(v => !_versionHelper.IsPreRelease(v.Name)) ?? versions.First()).Name;
}
}
SearchOutputs = await _documentAppService.SearchAsync(new DocumentSearchInput
@ -86,7 +90,8 @@ namespace Volo.Docs.Pages.Documents
for (var i = 0; i < searchOutput.Highlight.Count; i++)
{
searchOutput.Highlight[i] = _encoder
.Encode(searchOutput.Highlight[i].Replace("<highlight>", highlightTag1).Replace("</highlight>", highlightTag2))
.Encode(searchOutput.Highlight[i].Replace("<highlight>", highlightTag1)
.Replace("</highlight>", highlightTag2))
.Replace(highlightTag1, "<highlight>").Replace(highlightTag2, "</highlight>");
}
}

1
modules/docs/src/Volo.Docs.Web/Volo.Docs.Web.csproj

@ -25,7 +25,6 @@
<PackageReference Include="Markdig.Signed" Version="0.20.0" />
<PackageReference Include="Scriban" Version="2.1.3" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.5" />
<PackageReference Include="NuGet.Versioning" Version="5.6.0" />
</ItemGroup>

30
modules/docs/test/Volo.Docs.TestBase/Volo/Docs/DocsTestBase.cs

@ -7,10 +7,12 @@ using Volo.Abp;
using Volo.Abp.Modularity;
using Volo.Docs.GitHub.Documents;
using Volo.Abp.Testing;
using Volo.Docs.GitHub.Documents.Version;
using Volo.Docs.Projects;
namespace Volo.Docs
{
public abstract class DocsTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
public abstract class DocsTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
@ -30,27 +32,13 @@ namespace Volo.Docs
repositoryManager.GetFileRawByteArrayContentAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(new byte[] { 0x01, 0x02, 0x03 });
repositoryManager.GetReleasesAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>())
.Returns(new List<Release>
repositoryManager.GetVersionsAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), GithubVersionProviderSource.Releases)
.Returns(new List<GithubVersion>
{
new Release("https://api.github.com/repos/abpframework/abp/releases/16293679",
"https://github.com/abpframework/abp/releases/tag/0.15.0",
"https://api.github.com/repos/abpframework/abp/releases/16293679/assets",
"https://uploads.github.com/repos/abpframework/abp/releases/16293679/assets{?name,label}",
16293679,
"",
"0.15.0",
"master",
"0.15.0",
"0.15.0 already release",
false,
false,
DateTimeOffset.Parse("2019-03-22T18:43:58Z"),
DateTimeOffset.Parse("2019-03-22T19:44:25Z"),
null,
"https://api.github.com/repos/abpframework/abp/tarball/0.15.0",
"https://api.github.com/repos/abpframework/abp/zipball/0.15.0",
null)
new GithubVersion()
{
Name = "0.15.0"
}
});
repositoryManager.GetFileCommitsAsync(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(),
Arg.Any<string>(), Arg.Any<string>())

Loading…
Cancel
Save