Browse Source

docs: add a new options class to obtain default language

pull/15157/head
Engincan VESKE 3 years ago
parent
commit
557c50265a
  1. 12
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/DocsDomainModule.cs
  2. 8
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/DocsGithubLanguageOptions.cs
  3. 47
      modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/Documents/GithubDocumentSource.cs

12
modules/docs/src/Volo.Docs.Domain/Volo/Docs/DocsDomainModule.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -13,6 +14,7 @@ using Volo.Abp.VirtualFileSystem;
using Volo.Docs.Documents; using Volo.Docs.Documents;
using Volo.Docs.Documents.FullSearch.Elastic; using Volo.Docs.Documents.FullSearch.Elastic;
using Volo.Docs.FileSystem.Documents; using Volo.Docs.FileSystem.Documents;
using Volo.Docs.GitHub;
using Volo.Docs.GitHub.Documents; using Volo.Docs.GitHub.Documents;
using Volo.Docs.Localization; using Volo.Docs.Localization;
using Volo.Docs.Projects; using Volo.Docs.Projects;
@ -59,6 +61,16 @@ namespace Volo.Docs
options.Sources[GithubDocumentSource.Type] = typeof(GithubDocumentSource); options.Sources[GithubDocumentSource.Type] = typeof(GithubDocumentSource);
options.Sources[FileSystemDocumentSource.Type] = typeof(FileSystemDocumentSource); options.Sources[FileSystemDocumentSource.Type] = typeof(FileSystemDocumentSource);
}); });
Configure<DocsGithubLanguageOptions>(options =>
{
options.DefaultLanguage = new LanguageConfigElement
{
Code = "en",
DisplayName = "English",
IsDefault = true
};
});
context.Services.AddHttpClient(GithubRepositoryManager.HttpClientName, client => context.Services.AddHttpClient(GithubRepositoryManager.HttpClientName, client =>
{ {

8
modules/docs/src/Volo.Docs.Domain/Volo/Docs/GitHub/DocsGithubLanguageOptions.cs

@ -0,0 +1,8 @@
using Volo.Docs.Documents;
namespace Volo.Docs.GitHub;
public class DocsGithubLanguageOptions
{
public LanguageConfigElement DefaultLanguage { get; set; }
}

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

@ -4,6 +4,7 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Domain.Services; using Volo.Abp.Domain.Services;
using Volo.Docs.Documents; using Volo.Docs.Documents;
using Volo.Docs.GitHub.Projects; using Volo.Docs.GitHub.Projects;
@ -25,15 +26,18 @@ namespace Volo.Docs.GitHub.Documents
private readonly IGithubRepositoryManager _githubRepositoryManager; private readonly IGithubRepositoryManager _githubRepositoryManager;
private readonly IGithubPatchAnalyzer _githubPatchAnalyzer; private readonly IGithubPatchAnalyzer _githubPatchAnalyzer;
private readonly IDocumentRepository _documentRepository; private readonly IDocumentRepository _documentRepository;
private readonly DocsGithubLanguageOptions _docsGithubLanguageOptions;
public GithubDocumentSource( public GithubDocumentSource(
IGithubRepositoryManager githubRepositoryManager, IGithubRepositoryManager githubRepositoryManager,
IGithubPatchAnalyzer githubPatchAnalyzer, IGithubPatchAnalyzer githubPatchAnalyzer,
IDocumentRepository documentRepository) IDocumentRepository documentRepository,
IOptions<DocsGithubLanguageOptions> docsGithubLanguageOptions)
{ {
_githubRepositoryManager = githubRepositoryManager; _githubRepositoryManager = githubRepositoryManager;
_githubPatchAnalyzer = githubPatchAnalyzer; _githubPatchAnalyzer = githubPatchAnalyzer;
_documentRepository = documentRepository; _documentRepository = documentRepository;
_docsGithubLanguageOptions = docsGithubLanguageOptions.Value;
} }
public virtual async Task<Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime? lastKnownSignificantUpdateTime = null) public virtual async Task<Document> GetDocumentAsync(Project project, string documentName, string languageCode, string version, DateTime? lastKnownSignificantUpdateTime = null)
@ -57,7 +61,7 @@ namespace Volo.Docs.GitHub.Documents
var documentCreationTime = GetFirstCommitDate(commits); var documentCreationTime = GetFirstCommitDate(commits);
var lastUpdateTime = GetLastCommitDate(commits); var lastUpdateTime = GetLastCommitDate(commits);
var lastSignificantUpdateTime = await GetLastKnownSignificantUpdateTime(project, documentName, languageCode, version, lastKnownSignificantUpdateTime, isNavigationDocument, isParameterDocument, commits, documentCreationTime); var lastSignificantUpdateTime = await GetLastKnownSignificantUpdateTime(project, documentName, languageCode, version, lastKnownSignificantUpdateTime, isNavigationDocument, isParameterDocument, commits);
var document = new Document var document = new Document
( (
@ -103,18 +107,24 @@ namespace Volo.Docs.GitHub.Documents
DateTime? lastKnownSignificantUpdateTime, DateTime? lastKnownSignificantUpdateTime,
bool isNavigationDocument, bool isNavigationDocument,
bool isParameterDocument, bool isParameterDocument,
IReadOnlyList<GitHubCommit> commits, IReadOnlyList<GitHubCommit> commits)
DateTime documentCreationTime)
{ {
return !isNavigationDocument && !isParameterDocument && version == project.LatestVersionBranchName try
? await GetLastSignificantUpdateTime( {
commits, return !isNavigationDocument && !isParameterDocument && version == project.LatestVersionBranchName
project, ? await GetLastSignificantUpdateTime(
project.GetGitHubInnerUrl(languageCode, documentName), commits,
lastKnownSignificantUpdateTime, project,
documentCreationTime project.GetGitHubInnerUrl(languageCode, documentName),
) ?? lastKnownSignificantUpdateTime lastKnownSignificantUpdateTime
: null; ) ?? lastKnownSignificantUpdateTime
: null;
}
catch
{
Logger.LogWarning("Could not retrieved the last update time from Github.");
return null;
}
} }
private static List<DocumentAuthor> GetAuthors(IReadOnlyList<GitHubCommit> commits) private static List<DocumentAuthor> GetAuthors(IReadOnlyList<GitHubCommit> commits)
@ -209,8 +219,7 @@ namespace Volo.Docs.GitHub.Documents
IReadOnlyList<GitHubCommit> commits, IReadOnlyList<GitHubCommit> commits,
Project project, Project project,
string fileName, string fileName,
DateTime? lastKnownSignificantUpdateTime, DateTime? lastKnownSignificantUpdateTime)
DateTime documentCreationTime)
{ {
if (commits == null || !commits.Any()) if (commits == null || !commits.Any())
{ {
@ -335,15 +344,11 @@ namespace Volo.Docs.GitHub.Documents
} }
catch catch
{ {
Logger.LogWarning("Could not retrieved language list from Github."); Logger.LogWarning("Could not retrieved language list from Github. Using the default language from DocsGithubLanguageOptions.");
//TODO: save language list to documents table and then retrieve here!!!
return new LanguageConfig return new LanguageConfig
{ {
Languages = new List<LanguageConfigElement> Languages = new List<LanguageConfigElement> { _docsGithubLanguageOptions.DefaultLanguage }
{
new LanguageConfigElement { Code = "en", DisplayName = "English", IsDefault = true }
}
}; };
} }
} }

Loading…
Cancel
Save